From 7979fd73b88ed3a506b596ed99836890a20440e0 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 14 Jun 2024 21:39:51 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/AssetManipulationList.php | 6 +-- src/Dev/TestAssetStore.php | 26 +++++------ src/File.php | 34 +++++++------- src/FileFinder.php | 2 +- src/FilenameParsing/AbstractFileIDHelper.php | 6 +-- src/FilenameParsing/HashFileIDHelper.php | 4 +- src/FilenameParsing/NaturalFileIDHelper.php | 2 +- src/FilenameParsing/ParsedFileID.php | 16 +++---- src/Filesystem.php | 8 ++-- src/Flysystem/AssetAdapter.php | 2 +- src/Flysystem/FlysystemAssetStore.php | 46 +++++++++---------- src/Flysystem/LocalFilesystemAdapter.php | 2 +- src/Flysystem/ProtectedAssetAdapter.php | 4 +- src/Flysystem/PublicAssetAdapter.php | 4 +- src/Image.php | 2 +- src/ImageManipulation.php | 2 +- src/InterventionBackend.php | 24 +++++----- src/Shortcodes/ImageShortcodeProvider.php | 4 +- src/Storage/Sha1FileHashingService.php | 4 +- src/Upload.php | 2 +- src/Util.php | 4 +- .../FlysystemAssetStoreExtension.php | 6 +-- 22 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/AssetManipulationList.php b/src/AssetManipulationList.php index 54c1da22..74466d62 100644 --- a/src/AssetManipulationList.php +++ b/src/AssetManipulationList.php @@ -66,11 +66,11 @@ protected function getAssetKey($asset) public function addAsset($asset, $state) { switch ($state) { - case self::STATE_PUBLIC: + case AssetManipulationList::STATE_PUBLIC: return $this->addPublicAsset($asset); - case self::STATE_PROTECTED: + case AssetManipulationList::STATE_PROTECTED: return $this->addProtectedAsset($asset); - case self::STATE_DELETED: + case AssetManipulationList::STATE_DELETED: return $this->addDeletedAsset($asset); default: throw new \InvalidArgumentException("Invalid state {$state}"); diff --git a/src/Dev/TestAssetStore.php b/src/Dev/TestAssetStore.php index e985f16e..d31e7557 100644 --- a/src/Dev/TestAssetStore.php +++ b/src/Dev/TestAssetStore.php @@ -97,11 +97,11 @@ public static function activate($basedir) Director::config()->set('alternate_base_url', '/'); DBFile::config()->set('force_resample', false); File::config()->set('force_resample', false); - self::reset(); - self::$basedir = $basedir; + TestAssetStore::reset(); + TestAssetStore::$basedir = $basedir; // Ensure basedir exists - SSFilesystem::makeFolder(self::base_path()); + SSFilesystem::makeFolder(TestAssetStore::base_path()); } /** @@ -111,10 +111,10 @@ public static function activate($basedir) */ public static function base_path() { - if (!self::$basedir) { + if (!TestAssetStore::$basedir) { return null; } - return ASSETS_PATH . '/' . self::$basedir; + return ASSETS_PATH . '/' . TestAssetStore::$basedir; } /** @@ -123,14 +123,14 @@ public static function base_path() public static function reset() { // Remove all files in this store - if (self::$basedir) { - $path = self::base_path(); + if (TestAssetStore::$basedir) { + $path = TestAssetStore::base_path(); if (file_exists($path ?? '')) { SSFilesystem::removeFolder($path); } } - self::$seekable_override = null; - self::$basedir = null; + TestAssetStore::$seekable_override = null; + TestAssetStore::$basedir = null; } /** @@ -144,7 +144,7 @@ public static function reset() public static function getLocalPath(AssetContainer $asset, $forceProtected = false, $relative = false) { if ($asset instanceof Folder) { - return self::base_path() . '/' . $asset->getFilename(); + return TestAssetStore::base_path() . '/' . $asset->getFilename(); } if ($asset instanceof File) { $asset = $asset->File; @@ -223,10 +223,10 @@ public function isGranted($fileID) protected function isSeekableStream($stream) { - if (isset(self::$seekable_override)) { + if (isset(TestAssetStore::$seekable_override)) { // Unset the override so we don't get stuck in an infinite loop - self::$seekable_override = null; - return self::$seekable_override; + TestAssetStore::$seekable_override = null; + return TestAssetStore::$seekable_override; } return parent::isSeekableStream($stream); } diff --git a/src/File.php b/src/File.php index 7f085d46..7a00eb2a 100644 --- a/src/File.php +++ b/src/File.php @@ -424,7 +424,7 @@ public function canEdit($member = null) return $result; } - if (Permission::checkMember($member, self::EDIT_ALL)) { + if (Permission::checkMember($member, File::EDIT_ALL)) { return true; } @@ -455,7 +455,7 @@ public function canCreate($member = null, $context = []) return $result; } - if (Permission::checkMember($member, self::EDIT_ALL)) { + if (Permission::checkMember($member, File::EDIT_ALL)) { return true; } @@ -491,7 +491,7 @@ public function canDelete($member = null) } // Default permission check - if (Permission::checkMember($member, self::EDIT_ALL)) { + if (Permission::checkMember($member, File::EDIT_ALL)) { return true; } @@ -529,21 +529,21 @@ private function hasRestrictedPermissions(File $file): bool InheritedPermissions::ONLY_THESE_USERS, InheritedPermissions::ONLY_THESE_MEMBERS, ])) { - self::$has_restricted_permissions_cache[$id] = true; + File::$has_restricted_permissions_cache[$id] = true; return true; } if ($canViewType == InheritedPermissions::INHERIT && $parentID != 0) { - if (isset(self::$has_restricted_permissions_cache[$parentID])) { - return self::$has_restricted_permissions_cache[$parentID]; + if (isset(File::$has_restricted_permissions_cache[$parentID])) { + return File::$has_restricted_permissions_cache[$parentID]; } $parent = $file->Parent(); if ($parent->exists()) { $value = $this->hasRestrictedPermissions($parent); - self::$has_restricted_permissions_cache[$parentID] = $value; + File::$has_restricted_permissions_cache[$parentID] = $value; return $value; } } - self::$has_restricted_permissions_cache[$id] = false; + File::$has_restricted_permissions_cache[$id] = false; return false; } @@ -666,7 +666,7 @@ public static function get_category_extensions($categories) */ public function appCategory() { - return self::get_app_category($this->getExtension()); + return File::get_app_category($this->getExtension()); } /** @@ -754,7 +754,7 @@ public function onAfterRevertToLive() { // Force query of draft object and update (as source record is bound to live stage) if (class_exists(Versioned::class) && - $draftRecord = Versioned::get_by_stage(self::class, Versioned::DRAFT)->byID($this->ID) + $draftRecord = Versioned::get_by_stage(File::class, Versioned::DRAFT)->byID($this->ID) ) { $draftRecord->updateDependantObjects(); } @@ -998,7 +998,7 @@ public function setFilename($filename) */ public function getExtension() { - return self::get_file_extension($this->Name); + return File::get_file_extension($this->Name); } /** @@ -1053,7 +1053,7 @@ public static function get_icon_for_extension($extension) */ public function getFileType() { - return self::get_file_type($this->getFilename()); + return File::get_file_type($this->getFilename()); } /** @@ -1064,10 +1064,10 @@ public function getFileType() */ public static function get_file_type($filename) { - $file_types = self::config()->get('file_types'); + $file_types = static::config()->get('file_types'); // Get extension - $extension = strtolower(self::get_file_extension($filename) ?? ''); + $extension = strtolower(File::get_file_extension($filename) ?? ''); if (isset($file_types[$extension])) { return _t( @@ -1154,7 +1154,7 @@ public function validate() */ public static function get_class_for_file_extension($ext) { - $map = array_change_key_case(self::config()->get('class_for_file_extension') ?? [], CASE_LOWER); + $map = array_change_key_case(static::config()->get('class_for_file_extension') ?? [], CASE_LOWER); return (array_key_exists(strtolower($ext ?? ''), $map ?? [])) ? $map[strtolower($ext)] : $map['*']; } @@ -1175,7 +1175,7 @@ public static function set_class_for_file_extension($exts, $class) sprintf('Class "%s" (for extension "%s") is not a valid subclass of File', $class, $ext) ); } - self::config()->merge('class_for_file_extension', [$ext => $class]); + static::config()->merge('class_for_file_extension', [$ext => $class]); } } @@ -1415,7 +1415,7 @@ public function getPermissionChecker() public function providePermissions() { return [ - self::EDIT_ALL => [ + File::EDIT_ALL => [ 'name' => _t(__CLASS__.'.EDIT_ALL_DESCRIPTION', 'Edit any file'), 'category' => _t('SilverStripe\\Security\\Permission.CONTENT_CATEGORY', 'Content permissions'), 'sort' => -100, diff --git a/src/FileFinder.php b/src/FileFinder.php index 17b7309b..901ff8e3 100644 --- a/src/FileFinder.php +++ b/src/FileFinder.php @@ -208,7 +208,7 @@ protected function acceptDir($basename, $pathname, $depth) } } - if ($this->getOption('ignore_vcs') && in_array($basename, self::$vcs_dirs)) { + if ($this->getOption('ignore_vcs') && in_array($basename, FileFinder::$vcs_dirs)) { return false; } diff --git a/src/FilenameParsing/AbstractFileIDHelper.php b/src/FilenameParsing/AbstractFileIDHelper.php index f36aea92..09b93a28 100644 --- a/src/FilenameParsing/AbstractFileIDHelper.php +++ b/src/FilenameParsing/AbstractFileIDHelper.php @@ -41,7 +41,7 @@ public function buildFileID($filename, $hash = null, $variant = null, $cleanfile } if ($variant) { - $filename = $this->swapExtension($filename, $variant, self::EXTENSION_VARIANT); + $filename = $this->swapExtension($filename, $variant, AbstractFileIDHelper::EXTENSION_VARIANT); } $name = basename($filename ?? ''); @@ -79,7 +79,7 @@ public function buildFileID($filename, $hash = null, $variant = null, $cleanfile * or the variant extension. * * @param string $filename Original filename without variant - * @param int $extIndex One of self::EXTENSION_ORIGINAL or self::EXTENSION_VARIANT + * @param int $extIndex One of AbstractFileIDHelper::EXTENSION_ORIGINAL or AbstractFileIDHelper::EXTENSION_VARIANT */ protected function swapExtension(string $filename, string $variant, int $extIndex): string { @@ -102,7 +102,7 @@ protected function swapExtension(string $filename, string $variant, int $extInde // Loop our variant list until we find our special file extension swap variant // Reverse the list first so the variant extension we find is the last extension rewrite variant in a chain - $extSwapVariant = preg_quote(self::EXTENSION_REWRITE_VARIANT, '/'); + $extSwapVariant = preg_quote(AbstractFileIDHelper::EXTENSION_REWRITE_VARIANT, '/'); foreach (array_reverse($subVariants) as $subVariant) { if (preg_match("/^$extSwapVariant(?.+)$/", $subVariant, $matches)) { // This array always contain 2 values: The original extension at index 0 and the variant extension at index 1 diff --git a/src/FilenameParsing/HashFileIDHelper.php b/src/FilenameParsing/HashFileIDHelper.php index f69e8829..5f065006 100644 --- a/src/FilenameParsing/HashFileIDHelper.php +++ b/src/FilenameParsing/HashFileIDHelper.php @@ -33,7 +33,7 @@ public function parseFileID($fileID) $variant = $matches['variant'] ?: ''; if ($variant) { - $filename = $this->swapExtension($filename, $variant, self::EXTENSION_ORIGINAL); + $filename = $this->swapExtension($filename, $variant, HashFileIDHelper::EXTENSION_ORIGINAL); } return new ParsedFileID( @@ -82,6 +82,6 @@ protected function getFileIDBase($shortFilename, $fullFilename, $hash, $variant) */ private function truncate($hash) { - return substr($hash ?? '', 0, self::HASH_TRUNCATE_LENGTH); + return substr($hash ?? '', 0, HashFileIDHelper::HASH_TRUNCATE_LENGTH); } } diff --git a/src/FilenameParsing/NaturalFileIDHelper.php b/src/FilenameParsing/NaturalFileIDHelper.php index aef4298a..b5ab7c8d 100644 --- a/src/FilenameParsing/NaturalFileIDHelper.php +++ b/src/FilenameParsing/NaturalFileIDHelper.php @@ -24,7 +24,7 @@ public function parseFileID($fileID) $variant = $matches['variant'] ?: ''; if ($variant) { - $filename = $this->swapExtension($filename, $variant, self::EXTENSION_ORIGINAL); + $filename = $this->swapExtension($filename, $variant, NaturalFileIDHelper::EXTENSION_ORIGINAL); } return new ParsedFileID( diff --git a/src/FilenameParsing/ParsedFileID.php b/src/FilenameParsing/ParsedFileID.php index 6977c033..359b0851 100644 --- a/src/FilenameParsing/ParsedFileID.php +++ b/src/FilenameParsing/ParsedFileID.php @@ -86,37 +86,37 @@ public function getTuple() /** * @param string $fileID - * @return self + * @return ParsedFileID */ public function setFileID($fileID) { - return new self($this->filename, $this->hash, $this->variant, $fileID); + return new ParsedFileID($this->filename, $this->hash, $this->variant, $fileID); } /** * @param string $filename - * @return self + * @return ParsedFileID */ public function setFilename($filename) { - return new self($filename, $this->hash, $this->variant, $this->fileID); + return new ParsedFileID($filename, $this->hash, $this->variant, $this->fileID); } /** * @param string $variant - * @return self + * @return ParsedFileID */ public function setVariant($variant) { - return new self($this->filename, $this->hash, $variant, $this->fileID); + return new ParsedFileID($this->filename, $this->hash, $variant, $this->fileID); } /** * @param string $hash - * @return self + * @return ParsedFileID */ public function setHash($hash) { - return new self($this->filename, $hash, $this->variant, $this->fileID); + return new ParsedFileID($this->filename, $hash, $this->variant, $this->fileID); } } diff --git a/src/Filesystem.php b/src/Filesystem.php index b1a8d693..d610ede6 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -42,7 +42,7 @@ class Filesystem public static function makeFolder($folder) { if (!file_exists($base = dirname($folder ?? ''))) { - self::makeFolder($base); + Filesystem::makeFolder($base); } if (!file_exists($folder ?? '')) { mkdir($folder ?? '', static::config()->folder_create_mask ?? 0); @@ -93,7 +93,7 @@ public static function remove_folder_if_empty($folder, $recursive = true) while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { // if an empty folder is detected, remove that one first and move on - if ($recursive && is_dir($entry ?? '') && self::remove_folder_if_empty($entry)) { + if ($recursive && is_dir($entry ?? '') && Filesystem::remove_folder_if_empty($entry)) { continue; } // if a file was encountered, or a subdirectory was not empty, return false. @@ -124,7 +124,7 @@ public static function folderModTime($folder, $extensionList = null) if ($item[0] != '.') { // Recurse into folders if (is_dir("$folder/$item")) { - $modTime = max($modTime, self::folderModTime("$folder/$item", $extensionList)); + $modTime = max($modTime, Filesystem::folderModTime("$folder/$item", $extensionList)); // Check files } else { @@ -139,7 +139,7 @@ public static function folderModTime($folder, $extensionList = null) } } - //if(!$recursiveCall) self::$cache_folderModTime[$cacheID] = $modTime; + //if(!$recursiveCall) Filesystem::$cache_folderModTime[$cacheID] = $modTime; return $modTime; } diff --git a/src/Flysystem/AssetAdapter.php b/src/Flysystem/AssetAdapter.php index 41c6b8a2..a843c4f5 100644 --- a/src/Flysystem/AssetAdapter.php +++ b/src/Flysystem/AssetAdapter.php @@ -57,7 +57,7 @@ class AssetAdapter extends LocalFilesystemAdapter ] ]; - public function __construct($root = null, $writeFlags = LOCK_EX, $linkHandling = self::DISALLOW_LINKS) + public function __construct($root = null, $writeFlags = LOCK_EX, $linkHandling = AssetAdapter::DISALLOW_LINKS) { // Get root path, and ensure that this exists and is safe $root = $this->findRoot($root); diff --git a/src/Flysystem/FlysystemAssetStore.php b/src/Flysystem/FlysystemAssetStore.php index cb5fbc13..ee67b7f2 100644 --- a/src/Flysystem/FlysystemAssetStore.php +++ b/src/Flysystem/FlysystemAssetStore.php @@ -252,13 +252,13 @@ protected function applyToFileOnFilesystem(callable $callable, ParsedFileID $par $publicSet = [ $this->getPublicFilesystem(), $this->getPublicResolutionStrategy(), - self::VISIBILITY_PUBLIC + FlysystemAssetStore::VISIBILITY_PUBLIC ]; $protectedSet = [ $this->getProtectedFilesystem(), $this->getProtectedResolutionStrategy(), - self::VISIBILITY_PROTECTED + FlysystemAssetStore::VISIBILITY_PROTECTED ]; $hasher = Injector::inst()->get(FileHashingService::class); @@ -335,13 +335,13 @@ protected function applyToFileIDOnFilesystem(callable $callable, $fileID, $stric $publicSet = [ $this->getPublicFilesystem(), $this->getPublicResolutionStrategy(), - self::VISIBILITY_PUBLIC + FlysystemAssetStore::VISIBILITY_PUBLIC ]; $protectedSet = [ $this->getProtectedFilesystem(), $this->getProtectedResolutionStrategy(), - self::VISIBILITY_PROTECTED + FlysystemAssetStore::VISIBILITY_PROTECTED ]; /** @var Filesystem $fs */ @@ -389,14 +389,14 @@ public function getCapabilities() { return [ 'visibility' => [ - self::VISIBILITY_PUBLIC, - self::VISIBILITY_PROTECTED + FlysystemAssetStore::VISIBILITY_PUBLIC, + FlysystemAssetStore::VISIBILITY_PROTECTED ], 'conflict' => [ - self::CONFLICT_EXCEPTION, - self::CONFLICT_OVERWRITE, - self::CONFLICT_RENAME, - self::CONFLICT_USE_EXISTING + FlysystemAssetStore::CONFLICT_EXCEPTION, + FlysystemAssetStore::CONFLICT_OVERWRITE, + FlysystemAssetStore::CONFLICT_RENAME, + FlysystemAssetStore::CONFLICT_USE_EXISTING ] ]; } @@ -853,9 +853,9 @@ public function grant($filename, $hash) $fileID = $this->getFileID($filename, $hash); $session = Controller::curr()->getRequest()->getSession(); - $granted = $session->get(self::GRANTS_SESSION) ?: []; + $granted = $session->get(FlysystemAssetStore::GRANTS_SESSION) ?: []; $granted[$fileID] = true; - $session->set(self::GRANTS_SESSION, $granted); + $session->set(FlysystemAssetStore::GRANTS_SESSION, $granted); } public function revoke($filename, $hash) @@ -866,12 +866,12 @@ public function revoke($filename, $hash) } $session = Controller::curr()->getRequest()->getSession(); - $granted = $session->get(self::GRANTS_SESSION) ?: []; + $granted = $session->get(FlysystemAssetStore::GRANTS_SESSION) ?: []; unset($granted[$fileID]); if ($granted) { - $session->set(self::GRANTS_SESSION, $granted); + $session->set(FlysystemAssetStore::GRANTS_SESSION, $granted); } else { - $session->clear(self::GRANTS_SESSION); + $session->clear(FlysystemAssetStore::GRANTS_SESSION); } } @@ -905,7 +905,7 @@ protected function isGranted($fileID) // Make sure our File ID got understood if ($parsedFileID && $originalID = $parsedFileID->getFileID()) { $session = Controller::curr()->getRequest()->getSession(); - $granted = $session->get(self::GRANTS_SESSION) ?: []; + $granted = $session->get(FlysystemAssetStore::GRANTS_SESSION) ?: []; if (!empty($granted[$originalID])) { return true; } @@ -1024,14 +1024,14 @@ function ( list($parsedFileID, $fs, $strategy, $visibility) = $fsObjs; $targetFileID = $parsedFileID->getFileID(); } else { - if (isset($config['visibility']) && $config['visibility'] === self::VISIBILITY_PUBLIC) { + if (isset($config['visibility']) && $config['visibility'] === FlysystemAssetStore::VISIBILITY_PUBLIC) { $fs = $this->getPublicFilesystem(); $strategy = $this->getPublicResolutionStrategy(); - $visibility = self::VISIBILITY_PUBLIC; + $visibility = FlysystemAssetStore::VISIBILITY_PUBLIC; } else { $fs = $this->getProtectedFilesystem(); $strategy = $this->getProtectedResolutionStrategy(); - $visibility = self::VISIBILITY_PROTECTED; + $visibility = FlysystemAssetStore::VISIBILITY_PROTECTED; } $targetFileID = $strategy->buildFileID($parsedFileID); } @@ -1280,7 +1280,7 @@ private function generateResponseFor(string $asset): array if ($public->has($asset)) { return [ $this->createResponseFor($public, $asset), - ['visibility' => self::VISIBILITY_PUBLIC] + ['visibility' => FlysystemAssetStore::VISIBILITY_PUBLIC] ]; } @@ -1290,7 +1290,7 @@ private function generateResponseFor(string $asset): array if ($this->canView($parsedFileID->getFilename(), $parsedFileID->getHash())) { return [ $this->createResponseFor($protected, $asset), - ['visibility' => self::VISIBILITY_PROTECTED, 'parsedFileID' => $parsedFileID] + ['visibility' => FlysystemAssetStore::VISIBILITY_PROTECTED, 'parsedFileID' => $parsedFileID] ]; } // Let's not deny if the file is in the protected store, but is not granted. @@ -1308,7 +1308,7 @@ private function generateResponseFor(string $asset): array return [ $this->createRedirectResponse($redirectFileID, $code), - ['visibility' => self::VISIBILITY_PUBLIC, 'parsedFileID' => $parsedFileID] + ['visibility' => FlysystemAssetStore::VISIBILITY_PUBLIC, 'parsedFileID' => $parsedFileID] ]; } @@ -1316,7 +1316,7 @@ private function generateResponseFor(string $asset): array if ($protected->has($asset)) { return [ $this->createDeniedResponse(), - ['visibility' => self::VISIBILITY_PROTECTED] + ['visibility' => FlysystemAssetStore::VISIBILITY_PROTECTED] ]; } diff --git a/src/Flysystem/LocalFilesystemAdapter.php b/src/Flysystem/LocalFilesystemAdapter.php index 098b64ba..6132914d 100644 --- a/src/Flysystem/LocalFilesystemAdapter.php +++ b/src/Flysystem/LocalFilesystemAdapter.php @@ -15,7 +15,7 @@ public function __construct( string $location, VisibilityConverter $visibility = null, int $writeFlags = LOCK_EX, - int $linkHandling = self::DISALLOW_LINKS, + int $linkHandling = LocalFilesystemAdapter::DISALLOW_LINKS, MimeTypeDetector $mimeTypeDetector = null ) { $this->pathPrefixer = new PathPrefixer($location); diff --git a/src/Flysystem/ProtectedAssetAdapter.php b/src/Flysystem/ProtectedAssetAdapter.php index e9bbb882..b0bd2a4c 100644 --- a/src/Flysystem/ProtectedAssetAdapter.php +++ b/src/Flysystem/ProtectedAssetAdapter.php @@ -22,10 +22,10 @@ class ProtectedAssetAdapter extends AssetAdapter implements ProtectedAdapter private static $server_configuration = [ 'apache' => [ - '.htaccess' => self::class . '_HTAccess' + '.htaccess' => ProtectedAssetAdapter::class . '_HTAccess' ], 'microsoft-iis' => [ - 'web.config' => self::class . '_WebConfig' + 'web.config' => ProtectedAssetAdapter::class . '_WebConfig' ] ]; diff --git a/src/Flysystem/PublicAssetAdapter.php b/src/Flysystem/PublicAssetAdapter.php index 21448570..16b76f0e 100644 --- a/src/Flysystem/PublicAssetAdapter.php +++ b/src/Flysystem/PublicAssetAdapter.php @@ -24,10 +24,10 @@ class PublicAssetAdapter extends AssetAdapter implements PublicAdapter */ private static $server_configuration = [ 'apache' => [ - '.htaccess' => self::class . '_HTAccess' + '.htaccess' => PublicAssetAdapter::class . '_HTAccess' ], 'microsoft-iis' => [ - 'web.config' => self::class . '_WebConfig' + 'web.config' => PublicAssetAdapter::class . '_WebConfig' ] ]; diff --git a/src/Image.php b/src/Image.php index 91a30c1f..c36d7b7a 100644 --- a/src/Image.php +++ b/src/Image.php @@ -75,6 +75,6 @@ public function PreviewLink($action = null) */ public static function getLazyLoadingEnabled(): bool { - return self::config()->get('lazy_loading_enabled'); + return static::config()->get('lazy_loading_enabled'); } } diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index b6c0cd82..00bf32c6 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -541,7 +541,7 @@ public function CropHeight($height) * then scale down the image to those dimensions if it exceeds them. * Similar to Fill but without up-sampling. Use in templates with $FillMax. * - * @uses ImageManipulation::Fill() + * @uses self::Fill() * @param int $width The relative (used to determine aspect ratio) and maximum width of the output image * @param int $height The relative (used to determine aspect ratio) and maximum height of the output image * @return AssetContainer diff --git a/src/InterventionBackend.php b/src/InterventionBackend.php index 1d3dea76..a6644560 100644 --- a/src/InterventionBackend.php +++ b/src/InterventionBackend.php @@ -52,9 +52,9 @@ class InterventionBackend implements Image_Backend, Flushable * or list of integers (increasing scale) */ private static $error_cache_ttl = [ - self::FAILED_INVALID => 0, // Invalid file type should probably never be retried - self::FAILED_MISSING => '5,10,20,40,80', // Missing files may be eventually available - self::FAILED_UNKNOWN => 300, // Unknown (edge case). Maybe system error? Needs a flush? + InterventionBackend::FAILED_INVALID => 0, // Invalid file type should probably never be retried + InterventionBackend::FAILED_MISSING => '5,10,20,40,80', // Missing files may be eventually available + InterventionBackend::FAILED_UNKNOWN => 300, // Unknown (edge case). Maybe system error? Needs a flush? ]; /** @@ -238,7 +238,7 @@ public function getImageResource() // Validate stream is readable // Note: Mark failed regardless of whether a failed stream is exceptional or not - $error = self::FAILED_MISSING; + $error = InterventionBackend::FAILED_MISSING; try { $stream = $assetContainer->getStream(); if ($this->isStreamReadable($stream)) { @@ -253,7 +253,7 @@ public function getImageResource() } // Handle resource - $error = self::FAILED_UNKNOWN; + $error = InterventionBackend::FAILED_UNKNOWN; try { // write the file to a local path so we can extract exif data if it exists. // Currently exif data can only be read from file paths and not streams @@ -288,7 +288,7 @@ public function getImageResource() } catch (NotReadableException $ex) { // Handle unsupported image encoding on load (will be marked as failed) // Unsupported exceptions are handled without being raised as exceptions - $error = self::FAILED_INVALID; + $error = InterventionBackend::FAILED_INVALID; } finally { if ($error) { $this->markFailed($hash, $variant, $error); @@ -312,7 +312,7 @@ public function loadFrom($path) } // Handle resource - $error = self::FAILED_UNKNOWN; + $error = InterventionBackend::FAILED_UNKNOWN; try { $this->setImageResource($this->getImageManager()->make($path)); $this->markSuccess($hash, null); @@ -320,7 +320,7 @@ public function loadFrom($path) } catch (NotReadableException $ex) { // Handle unsupported image encoding on load (will be marked as failed) // Unsupported exceptions are handled without being raised as exceptions - $error = self::FAILED_INVALID; + $error = InterventionBackend::FAILED_INVALID; } finally { if ($error) { $this->markFailed($hash, null, $error); @@ -488,7 +488,7 @@ protected function getResourceDimensions(InterventionImage $resource) */ protected function getErrorCacheKey($hash, $variant = null) { - return self::CACHE_MARK . sha1($hash . '-' . $variant); + return InterventionBackend::CACHE_MARK . sha1($hash . '-' . $variant); } /** @@ -500,7 +500,7 @@ protected function getErrorCacheKey($hash, $variant = null) */ protected function getDimensionCacheKey($hash, $variant = null) { - return self::CACHE_DIMENSIONS . sha1($hash . '-' . $variant); + return InterventionBackend::CACHE_DIMENSIONS . sha1($hash . '-' . $variant); } /** @@ -763,13 +763,13 @@ protected function markSuccess($hash, $variant = null) * @param string|null $variant Variant being loaded * @param string $reason Reason this file is failed */ - protected function markFailed($hash, $variant = null, $reason = self::FAILED_UNKNOWN) + protected function markFailed($hash, $variant = null, $reason = InterventionBackend::FAILED_UNKNOWN) { $key = $this->getErrorCacheKey($hash, $variant); // Get TTL for error $errorTTLs = $this->config()->get('error_cache_ttl'); - $ttl = isset($errorTTLs[$reason]) ? $errorTTLs[$reason] : $errorTTLs[self::FAILED_UNKNOWN]; + $ttl = isset($errorTTLs[$reason]) ? $errorTTLs[$reason] : $errorTTLs[InterventionBackend::FAILED_UNKNOWN]; // Detect increasing waits if (is_string($ttl) && strstr($ttl ?? '', ',')) { diff --git a/src/Shortcodes/ImageShortcodeProvider.php b/src/Shortcodes/ImageShortcodeProvider.php index 2e5c7b9c..11ce70b3 100644 --- a/src/Shortcodes/ImageShortcodeProvider.php +++ b/src/Shortcodes/ImageShortcodeProvider.php @@ -92,7 +92,7 @@ public static function handle_shortcode($args, $content, $parser, $shortcode, $e } // Determine whether loading="lazy" is set - $args = self::updateLoadingValue($args, $width, $height); + $args = ImageShortcodeProvider::updateLoadingValue($args, $width, $height); // Build the HTML tag $attrs = array_merge( @@ -115,7 +115,7 @@ public static function handle_shortcode($args, $content, $parser, $shortcode, $e return in_array($k, $whitelist) && (strlen(trim($v ?? '')) || $k === 'alt'); }, ARRAY_FILTER_USE_BOTH); - $markup = self::createImageTag($attrs); + $markup = ImageShortcodeProvider::createImageTag($attrs); // cache it for future reference if ($fileFound) { diff --git a/src/Storage/Sha1FileHashingService.php b/src/Storage/Sha1FileHashingService.php index 7ed9b5a0..f0b7fc04 100644 --- a/src/Storage/Sha1FileHashingService.php +++ b/src/Storage/Sha1FileHashingService.php @@ -136,7 +136,7 @@ public function compare($hashOne, $hashTwo) public function isCached() { if ($this->cachable === null) { - $this->cachable = self::config()->get('default_cachable'); + $this->cachable = static::config()->get('default_cachable'); } return $this->cachable; @@ -205,7 +205,7 @@ public function invalidate($fileID, $fs) public static function flush() { - /** @var self $self */ + /** @var Sha1FileHashingService $self */ $self = Injector::inst()->get(FileHashingService::class); $self->getCache()->clear(); } diff --git a/src/Upload.php b/src/Upload.php index 2970108f..78719d2c 100644 --- a/src/Upload.php +++ b/src/Upload.php @@ -104,7 +104,7 @@ public function __construct() { parent::__construct(); $this->validator = Upload_Validator::create(); - $this->replaceFile = self::config()->replaceFile; + $this->replaceFile = static::config()->replaceFile; } public function index() diff --git a/src/Util.php b/src/Util.php index 53c7eb1e..b43b6430 100644 --- a/src/Util.php +++ b/src/Util.php @@ -6,7 +6,7 @@ class Util { public static function rewindStream($resource): void { - self::checkIsResource($resource); + Util::checkIsResource($resource); if (ftell($resource) !== 0 && static::isSeekableStream($resource)) { rewind($resource); } @@ -14,7 +14,7 @@ public static function rewindStream($resource): void public static function isSeekableStream($resource): bool { - self::checkIsResource($resource); + Util::checkIsResource($resource); return stream_get_meta_data($resource)['seekable']; } diff --git a/tests/php/Flysystem/FlysystemAssetStoreExtension.php b/tests/php/Flysystem/FlysystemAssetStoreExtension.php index a38d11ea..5f9d8f13 100644 --- a/tests/php/Flysystem/FlysystemAssetStoreExtension.php +++ b/tests/php/Flysystem/FlysystemAssetStoreExtension.php @@ -17,9 +17,9 @@ class FlysystemAssetStoreExtension extends Extension */ public function updateResponse($response, $asset, $context) { - self::$lastHookCall = [$response, $asset, $context]; - self::$callCount++; + FlysystemAssetStoreExtension::$lastHookCall = [$response, $asset, $context]; + FlysystemAssetStoreExtension::$callCount++; - $response->addHeader('FlysystemAssetStoreExtensionCallCount', self::$callCount); + $response->addHeader('FlysystemAssetStoreExtensionCallCount', FlysystemAssetStoreExtension::$callCount); } }