From 09831c7eedf8eeb5a8b232d464b1b8bf7e8591d9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 18:14:23 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Control/ContentNegotiator.php | 2 +- src/Control/Controller.php | 8 +- src/Control/Cookie.php | 18 +-- src/Control/Director.php | 60 +++++----- src/Control/Email/Email.php | 6 +- src/Control/HTTP.php | 6 +- src/Control/HTTPRequest.php | 2 +- src/Control/HTTPResponse.php | 8 +- .../Middleware/HTTPCacheControlMiddleware.php | 38 +++--- src/Control/RequestHandler.php | 4 +- src/Control/Session.php | 2 +- src/Control/Util/IPUtils.php | 2 +- src/Core/BaseKernel.php | 6 +- src/Core/ClassInfo.php | 46 +++---- src/Core/Config/Config.php | 2 +- src/Core/Config/ConfigLoader.php | 8 +- src/Core/Convert.php | 20 ++-- src/Core/Environment.php | 2 +- src/Core/Extensible.php | 2 +- src/Core/Injector/Injector.php | 14 +-- src/Core/Injector/InjectorLoader.php | 10 +- src/Core/Manifest/ClassLoader.php | 2 +- src/Core/Manifest/ManifestFileFinder.php | 14 +-- src/Core/Manifest/ModuleLoader.php | 6 +- src/Core/Manifest/ModuleManifest.php | 2 +- src/Core/Manifest/VersionProvider.php | 2 +- src/Core/Path.php | 4 +- src/Dev/Backtrace.php | 14 +-- src/Dev/BulkLoader.php | 14 +-- src/Dev/CLI.php | 10 +- src/Dev/CliDebugView.php | 24 ++-- src/Dev/CsvBulkLoader.php | 4 +- src/Dev/Debug.php | 4 +- src/Dev/DebugView.php | 4 +- src/Dev/Deprecation.php | 62 +++++----- src/Dev/Install/DatabaseAdapterRegistry.php | 14 +-- src/Dev/SapphireTest.php | 12 +- src/Dev/TestKernel.php | 4 +- .../Validation/RelationValidationService.php | 6 +- src/Forms/ConfirmedPasswordField.php | 2 +- src/Forms/Form.php | 22 ++-- src/Forms/FormFactory.php | 2 +- src/Forms/FormField.php | 6 +- src/Forms/GridField/GridField.php | 6 +- src/Forms/GridField/GridFieldDetailForm.php | 2 +- src/Forms/GridField/GridFieldFilterHeader.php | 2 +- src/Forms/GridField/GridState_Data.php | 6 +- src/Forms/HTMLEditor/HTMLEditorConfig.php | 24 ++-- src/Forms/HTMLEditor/TinyMCEConfig.php | 10 +- src/Forms/HTMLReadonlyField.php | 2 +- src/Forms/HeaderField.php | 2 +- src/Forms/LiteralField.php | 2 +- src/Forms/SingleSelectField.php | 2 +- src/Forms/TextField.php | 2 +- src/Forms/Tip.php | 14 +-- src/Forms/TreeDropdownField.php | 12 +- src/ORM/ArrayLib.php | 4 +- src/ORM/Connect/DBQueryBuilder.php | 2 +- src/ORM/Connect/Database.php | 10 +- src/ORM/Connect/MySQLQueryBuilder.php | 2 +- src/ORM/Connect/MySQLSchemaManager.php | 14 +-- src/ORM/Connect/MySQLiConnector.php | 2 +- src/ORM/Connect/NullDatabase.php | 4 +- src/ORM/DB.php | 74 ++++++------ src/ORM/DataObject.php | 112 +++++++++--------- src/ORM/DataObjectSchema.php | 16 +-- src/ORM/DataQuery.php | 2 +- src/ORM/EagerLoadedList.php | 6 +- src/ORM/FieldType/DBDate.php | 16 +-- src/ORM/FieldType/DBDatetime.php | 18 +-- src/ORM/FieldType/DBEnum.php | 12 +- src/ORM/FieldType/DBField.php | 2 +- src/ORM/FieldType/DBForeignKey.php | 2 +- src/ORM/FieldType/DBString.php | 2 +- src/ORM/FieldType/DBTime.php | 2 +- src/ORM/Filters/SearchFilter.php | 8 +- src/ORM/Hierarchy/Hierarchy.php | 18 +-- src/ORM/Hierarchy/MarkedSet.php | 2 +- src/ORM/ListDecorator.php | 2 +- src/ORM/Queries/SQLConditionalExpression.php | 4 +- src/ORM/Queries/SQLSelect.php | 2 +- src/ORM/Search/FulltextSearchable.php | 4 +- src/ORM/Search/SearchContext.php | 2 +- src/ORM/ValidationResult.php | 14 +-- src/Security/BasicAuth.php | 10 +- src/Security/Confirmation/Storage.php | 4 +- src/Security/InheritedPermissions.php | 56 ++++----- src/Security/LogoutForm.php | 2 +- src/Security/Member.php | 14 +-- .../MemberAuthenticator/MemberLoginForm.php | 4 +- src/Security/PasswordEncryptor.php | 4 +- src/Security/PasswordEncryptor_Blowfish.php | 8 +- src/Security/Permission.php | 30 ++--- src/Security/RememberLoginHash.php | 4 +- src/Security/Security.php | 34 +++--- src/Security/SecurityToken.php | 20 ++-- src/Security/SudoMode/SudoModeService.php | 4 +- src/View/Embed/EmbedContainer.php | 2 +- src/View/Parsers/HtmlDiff.php | 42 +++---- src/View/Parsers/SQLFormatter.php | 2 +- src/View/Parsers/ShortcodeParser.php | 52 ++++---- src/View/Requirements.php | 84 ++++++------- src/View/SSViewer.php | 22 ++-- src/View/SSViewer_DataPresenter.php | 16 +-- src/View/SSViewer_Scope.php | 6 +- .../Shortcodes/EmbedShortcodeProvider.php | 14 +-- src/View/ThemeManifest.php | 2 +- src/View/ThemeResourceLoader.php | 6 +- src/View/ViewableData.php | 8 +- src/i18n/TextCollection/i18nTextCollector.php | 14 +-- src/i18n/i18n.php | 12 +- tests/behat/src/CmsUiContext.php | 2 +- .../FlushMiddlewareTest/TestFlushable.php | 2 +- tests/php/Control/RSS/RSSFeedTest.php | 6 +- .../ControllerExtension.php | 4 +- .../DevAdminControllerTest/Controller1.php | 4 +- .../ControllerWithPermissions.php | 2 +- .../php/Dev/SapphireTestTest/DataProvider.php | 32 ++--- .../Logging/DetailedErrorFormatterTest.php | 2 +- tests/php/ORM/DataListEagerLoadingTest.php | 8 +- .../MockDynamicAssignmentDataObject.php | 4 +- tests/php/ORM/DataObjectTest/TreeNode.php | 8 +- tests/php/ORM/Filters/EndsWithFilterTest.php | 3 +- .../php/ORM/Filters/ExactMatchFilterTest.php | 3 +- .../ORM/Filters/PartialMatchFilterTest.php | 3 +- .../php/ORM/Filters/StartsWithFilterTest.php | 3 +- tests/php/ORM/MarkedSetTest.php | 4 +- tests/php/ORM/MySQLiConnectorTest.php | 2 +- tests/php/ORM/RelatedDataServiceTest.php | 4 +- .../ORM/SQLSelectTest/CteRecursiveObject.php | 4 +- .../TestCacheFlusher.php | 2 +- .../TestPermissionNode.php | 2 +- .../InheritedPermissionsTest/UnstagedNode.php | 2 +- tests/php/View/RequirementsTest.php | 32 ++--- tests/php/View/SSViewerTest/LevelTestData.php | 2 +- tests/php/i18n/i18nTest/TestObject.php | 4 +- thirdparty/php-peg/Compiler.php | 34 +++--- 137 files changed, 801 insertions(+), 797 deletions(-) diff --git a/src/Control/ContentNegotiator.php b/src/Control/ContentNegotiator.php index 21ec89f3e6b..aeb3b9f54a8 100644 --- a/src/Control/ContentNegotiator.php +++ b/src/Control/ContentNegotiator.php @@ -116,7 +116,7 @@ public static function setEnabled($enabled) */ public static function process(HTTPResponse $response) { - if (!self::enabled_for($response)) { + if (!ContentNegotiator::enabled_for($response)) { return; } diff --git a/src/Control/Controller.php b/src/Control/Controller.php index 80d7047c06c..5b94f0ad694 100644 --- a/src/Control/Controller.php +++ b/src/Control/Controller.php @@ -573,7 +573,7 @@ public function pushCurrent() { // Ensure this controller has a valid session $this->getRequest()->getSession(); - array_unshift(self::$controller_stack, $this); + array_unshift(Controller::$controller_stack, $this); } /** @@ -581,8 +581,8 @@ public function pushCurrent() */ public function popCurrent() { - if ($this === self::$controller_stack[0]) { - array_shift(self::$controller_stack); + if ($this === Controller::$controller_stack[0]) { + array_shift(Controller::$controller_stack); } else { $class = static::class; user_error( @@ -693,7 +693,7 @@ public static function normaliseTrailingSlash(string $url): string } // Normlise trailing slash - $shouldHaveTrailingSlash = self::config()->uninherited('add_trailing_slash'); + $shouldHaveTrailingSlash = Controller::config()->uninherited('add_trailing_slash'); if ($shouldHaveTrailingSlash && !str_ends_with($url, '/') && !preg_match('/^(.*)\.([^\/]*)$/', Director::makeRelative($url)) diff --git a/src/Control/Cookie.php b/src/Control/Cookie.php index 2995e844f9e..2bcafa606de 100644 --- a/src/Control/Cookie.php +++ b/src/Control/Cookie.php @@ -31,7 +31,7 @@ class Cookie * Must be "Strict", "Lax", or "None" * @config */ - private static string $default_samesite = self::SAMESITE_LAX; + private static string $default_samesite = Cookie::SAMESITE_LAX; /** * Fetch the current instance of the cookie backend. @@ -67,7 +67,7 @@ public static function set( $secure = false, $httpOnly = true ) { - return self::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly); + return Cookie::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly); } /** @@ -80,7 +80,7 @@ public static function set( */ public static function get($name, $includeUnsent = true) { - return self::get_inst()->get($name, $includeUnsent); + return Cookie::get_inst()->get($name, $includeUnsent); } /** @@ -92,7 +92,7 @@ public static function get($name, $includeUnsent = true) */ public static function get_all($includeUnsent = true) { - return self::get_inst()->getAll($includeUnsent); + return Cookie::get_inst()->getAll($includeUnsent); } /** @@ -104,7 +104,7 @@ public static function get_all($includeUnsent = true) */ public static function force_expiry($name, $path = null, $domain = null, $secure = false, $httpOnly = true) { - return self::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly); + return Cookie::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly); } /** @@ -116,14 +116,14 @@ public static function force_expiry($name, $path = null, $domain = null, $secure public static function validateSameSite(string $sameSite): void { $validValues = [ - self::SAMESITE_STRICT, - self::SAMESITE_LAX, - self::SAMESITE_NONE, + Cookie::SAMESITE_STRICT, + Cookie::SAMESITE_LAX, + Cookie::SAMESITE_NONE, ]; if (!in_array($sameSite, $validValues)) { throw new LogicException('Cookie samesite must be "Strict", "Lax", or "None"'); } - if ($sameSite === self::SAMESITE_NONE && !Director::is_https(self::getRequest())) { + if ($sameSite === Cookie::SAMESITE_NONE && !Director::is_https(Cookie::getRequest())) { Injector::inst()->get(LoggerInterface::class)->warning('Cookie samesite cannot be "None" for non-https requests.'); } } diff --git a/src/Control/Director.php b/src/Control/Director.php index f91fc93b478..ce7654edb3d 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -238,7 +238,7 @@ public static function mockRequest( // Ensure URL is properly made relative. // Example: url passed is "/ss31/my-page" (prefixed with BASE_URL), this should be changed to "my-page" - $url = self::makeRelative($url); + $url = Director::makeRelative($url); if (strpos($url ?? '', '?') !== false) { list($url, $getVarsEncoded) = explode('?', $url ?? '', 2); parse_str($getVarsEncoded ?? '', $newVars['_GET']); @@ -371,7 +371,7 @@ public function handleRequest(HTTPRequest $request) */ public static function get_current_page() { - return self::$current_page ? self::$current_page : Controller::curr(); + return Director::$current_page ? Director::$current_page : Controller::curr(); } /** @@ -381,7 +381,7 @@ public static function get_current_page() */ public static function set_current_page($page) { - self::$current_page = $page; + Director::$current_page = $page; } /** @@ -394,7 +394,7 @@ public static function set_current_page($page) * - REQUEST - Resolve this path to the current url (i.e. behaves as though no `` tag is provided in a html document) * - ROOT - Treat this as though it was an absolute path, and append it to the protocol and hostname. */ - public static function absoluteURL(string $url, string $relativeParent = self::BASE): string|bool + public static function absoluteURL(string $url, string $relativeParent = Director::BASE): string|bool { // Check if there is already a protocol given if (preg_match('/^http(s?):\/\//', $url ?? '')) { @@ -404,14 +404,14 @@ public static function absoluteURL(string $url, string $relativeParent = self::B // Absolute urls without protocol are added // E.g. //google.com -> http://google.com if (strpos($url ?? '', '//') === 0) { - return Controller::normaliseTrailingSlash(self::protocol() . substr($url ?? '', 2)); + return Controller::normaliseTrailingSlash(Director::protocol() . substr($url ?? '', 2)); } // Determine method for mapping the parent to this relative url - if ($relativeParent === self::ROOT || self::is_root_relative_url($url)) { + if ($relativeParent === Director::ROOT || Director::is_root_relative_url($url)) { // Root relative urls always should be evaluated relative to the root - $parent = self::protocolAndHost(); - } elseif ($relativeParent === self::REQUEST) { + $parent = Director::protocolAndHost(); + } elseif ($relativeParent === Director::REQUEST) { // Request relative urls rely on the REQUEST_URI param (old default behaviour) if (!isset($_SERVER['REQUEST_URI'])) { return false; @@ -419,7 +419,7 @@ public static function absoluteURL(string $url, string $relativeParent = self::B $parent = dirname($_SERVER['REQUEST_URI'] . 'x'); } else { // Default to respecting site base_url - $parent = self::absoluteBaseURL(); + $parent = Director::absoluteBaseURL(); } // Map empty urls to relative slash and join to base @@ -489,7 +489,7 @@ protected static function validateUserAndPass($url) public static function host(HTTPRequest $request = null) { // Check if overridden by alternate_base_url - if ($baseURL = self::config()->get('alternate_base_url')) { + if ($baseURL = Director::config()->get('alternate_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $host = static::parseHost($baseURL); if ($host) { @@ -508,7 +508,7 @@ public static function host(HTTPRequest $request = null) } // Check base url - if ($baseURL = self::config()->uninherited('default_base_url')) { + if ($baseURL = Director::config()->uninherited('default_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $host = static::parseHost($baseURL); if ($host) { @@ -566,7 +566,7 @@ public static function protocolAndHost(HTTPRequest $request = null) */ public static function protocol(HTTPRequest $request = null) { - return (self::is_https($request)) ? 'https://' : 'http://'; + return (Director::is_https($request)) ? 'https://' : 'http://'; } /** @@ -578,7 +578,7 @@ public static function protocol(HTTPRequest $request = null) public static function is_https(HTTPRequest $request = null) { // Check override from alternate_base_url - if ($baseURL = self::config()->uninherited('alternate_base_url')) { + if ($baseURL = Director::config()->uninherited('alternate_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME); if ($protocol) { @@ -593,7 +593,7 @@ public static function is_https(HTTPRequest $request = null) } // Check default_base_url - if ($baseURL = self::config()->uninherited('default_base_url')) { + if ($baseURL = Director::config()->uninherited('default_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME); if ($protocol) { @@ -612,7 +612,7 @@ public static function is_https(HTTPRequest $request = null) public static function baseURL() { // Check override base_url - $alternate = self::config()->get('alternate_base_url'); + $alternate = Director::config()->get('alternate_base_url'); if ($alternate) { $alternate = Injector::inst()->convertServiceProperty($alternate); return rtrim(parse_url($alternate ?? '', PHP_URL_PATH) ?? '', '/') . '/'; @@ -659,8 +659,8 @@ public static function publicDir() */ public static function publicFolder() { - $folder = self::baseFolder(); - $publicDir = self::publicDir(); + $folder = Director::baseFolder(); + $publicDir = Director::publicDir(); if ($publicDir) { return Path::join($folder, $publicDir); } @@ -694,7 +694,7 @@ public static function makeRelative($url) } // Remove base folder or url - foreach ([self::publicFolder(), self::baseFolder(), self::baseURL()] as $base) { + foreach ([Director::publicFolder(), Director::baseFolder(), Director::baseURL()] as $base) { // Ensure single / doesn't break comparison (unless it would make base empty) $base = rtrim($base ?? '', '\\/') ?: $base; if (stripos($url ?? '', $base ?? '') === 0) { @@ -827,7 +827,7 @@ public static function is_site_url($url) } // Relative urls always are site urls - return self::is_relative_url($url); + return Director::is_relative_url($url); } /** @@ -840,20 +840,20 @@ public static function is_site_url($url) public static function getAbsFile($file) { // If already absolute - if (self::is_absolute($file)) { + if (Director::is_absolute($file)) { return $file; } // If path is relative to public folder search there first - if (self::publicDir()) { - $path = Path::join(self::publicFolder(), $file); + if (Director::publicDir()) { + $path = Path::join(Director::publicFolder(), $file); if (file_exists($path ?? '')) { return $path; } } // Default to base folder - return Path::join(self::baseFolder(), $file); + return Path::join(Director::baseFolder(), $file); } /** @@ -877,9 +877,9 @@ public static function fileExists($file) */ public static function absoluteBaseURL() { - $baseURL = self::absoluteURL( - self::baseURL(), - self::ROOT + $baseURL = Director::absoluteURL( + Director::baseURL(), + Director::ROOT ); return Controller::normaliseTrailingSlash($baseURL); } @@ -986,7 +986,7 @@ public static function forceWWW(HTTPRequest $request = null) */ public static function is_ajax(HTTPRequest $request = null) { - $request = self::currentRequest($request); + $request = Director::currentRequest($request); if ($request) { return $request->isAjax(); } @@ -1054,7 +1054,7 @@ public static function get_session_environment_type(HTTPRequest $request = null) */ public static function isLive() { - return self::get_environment_type() === 'live'; + return Director::get_environment_type() === 'live'; } /** @@ -1065,7 +1065,7 @@ public static function isLive() */ public static function isDev() { - return self::get_environment_type() === 'dev'; + return Director::get_environment_type() === 'dev'; } /** @@ -1076,7 +1076,7 @@ public static function isDev() */ public static function isTest() { - return self::get_environment_type() === 'test'; + return Director::get_environment_type() === 'test'; } /** diff --git a/src/Control/Email/Email.php b/src/Control/Email/Email.php index 21420d61f09..52b05dc944f 100644 --- a/src/Control/Email/Email.php +++ b/src/Control/Email/Email.php @@ -104,10 +104,10 @@ private static function mergeConfiguredAddresses(string $configKey, string $envK { $addresses = []; $config = (array) static::config()->get($configKey); - $addresses = self::convertConfigToAddreses($config); + $addresses = Email::convertConfigToAddreses($config); $env = Environment::getEnv($envKey); if ($env) { - $addresses = array_merge($addresses, self::convertConfigToAddreses($env)); + $addresses = array_merge($addresses, Email::convertConfigToAddreses($env)); } return $addresses; } @@ -403,7 +403,7 @@ public function getHTMLTemplate(): string } return ThemeResourceLoader::inst()->findTemplate( - SSViewer::get_templates_by_class(static::class, '', self::class), + SSViewer::get_templates_by_class(static::class, '', Email::class), SSViewer::get_themes() ); } diff --git a/src/Control/HTTP.php b/src/Control/HTTP.php index d13bd7728be..d8a3b7248c9 100644 --- a/src/Control/HTTP.php +++ b/src/Control/HTTP.php @@ -226,7 +226,7 @@ public static function setGetVar($varname, $varvalue, $currentURL = null, $separ */ public static function RAW_setGetVar($varname, $varvalue, $currentURL = null) { - $url = self::setGetVar($varname, $varvalue, $currentURL); + $url = HTTP::setGetVar($varname, $varvalue, $currentURL); return Convert::xml2raw($url); } @@ -268,7 +268,7 @@ public static function findByTagAndAttribute($content, $attributes) */ public static function getLinksIn($content) { - return self::findByTagAndAttribute($content, ["a" => "href"]); + return HTTP::findByTagAndAttribute($content, ["a" => "href"]); } /** @@ -278,7 +278,7 @@ public static function getLinksIn($content) */ public static function getImagesIn($content) { - return self::findByTagAndAttribute($content, ["img" => "src"]); + return HTTP::findByTagAndAttribute($content, ["img" => "src"]); } /** diff --git a/src/Control/HTTPRequest.php b/src/Control/HTTPRequest.php index 8cc1ab9152a..ee014d0fdb0 100644 --- a/src/Control/HTTPRequest.php +++ b/src/Control/HTTPRequest.php @@ -850,7 +850,7 @@ public function httpMethod() */ public function setHttpMethod($method) { - if (!self::isValidHttpMethod($method)) { + if (!HTTPRequest::isValidHttpMethod($method)) { throw new \InvalidArgumentException('HTTPRequest::setHttpMethod: Invalid HTTP method'); } diff --git a/src/Control/HTTPResponse.php b/src/Control/HTTPResponse.php index b7e47cbbe67..3cb4a498bbc 100644 --- a/src/Control/HTTPResponse.php +++ b/src/Control/HTTPResponse.php @@ -174,7 +174,7 @@ public function setProtocolVersion($protocolVersion) */ public function setStatusCode($code, $description = null) { - if (isset(self::$status_codes[$code])) { + if (isset(HTTPResponse::$status_codes[$code])) { $this->statusCode = $code; } else { throw new InvalidArgumentException("Unrecognised HTTP status code '$code'"); @@ -183,7 +183,7 @@ public function setStatusCode($code, $description = null) if ($description) { $this->statusDescription = $description; } else { - $this->statusDescription = self::$status_codes[$code]; + $this->statusDescription = HTTPResponse::$status_codes[$code]; } return $this; } @@ -320,7 +320,7 @@ private function sanitiseHeader(string $value): string public function redirect(string $dest, int $code = 302): static { - if (!in_array($code, self::$redirect_codes)) { + if (!in_array($code, HTTPResponse::$redirect_codes)) { trigger_error("Invalid HTTP redirect code {$code}", E_USER_WARNING); $code = 302; } @@ -439,7 +439,7 @@ public function isFinished() */ public function isRedirect() { - return in_array($this->getStatusCode(), self::$redirect_codes); + return in_array($this->getStatusCode(), HTTPResponse::$redirect_codes); } /** diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 94fb0e2c3b3..c3da4f756c9 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -68,20 +68,20 @@ public function process(HTTPRequest $request, callable $delegate) * @var array */ protected $stateDirectives = [ - self::STATE_DISABLED => [ + HTTPCacheControlMiddleware::STATE_DISABLED => [ 'no-cache' => true, 'no-store' => true, 'must-revalidate' => true, ], - self::STATE_PRIVATE => [ + HTTPCacheControlMiddleware::STATE_PRIVATE => [ 'private' => true, 'must-revalidate' => true, ], - self::STATE_PUBLIC => [ + HTTPCacheControlMiddleware::STATE_PUBLIC => [ 'public' => true, 'must-revalidate' => true, ], - self::STATE_ENABLED => [ + HTTPCacheControlMiddleware::STATE_ENABLED => [ 'no-cache' => true, 'must-revalidate' => true, ] @@ -93,7 +93,7 @@ public function process(HTTPRequest $request, callable $delegate) * @config * @var string */ - private static $defaultState = self::STATE_ENABLED; + private static $defaultState = HTTPCacheControlMiddleware::STATE_ENABLED; /** * Current state @@ -307,7 +307,7 @@ public function getState() */ protected function applyChangeLevel($level, $force) { - $forcingLevel = $level + ($force ? self::LEVEL_FORCED : 0); + $forcingLevel = $level + ($force ? HTTPCacheControlMiddleware::LEVEL_FORCED : 0); if ($forcingLevel < $this->getForcingLevel()) { return false; } @@ -465,7 +465,7 @@ public function getDirectives() public function setNoStore($noStore = true) { // Affect all non-disabled states - $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC]; + $applyTo = [HTTPCacheControlMiddleware::STATE_ENABLED, HTTPCacheControlMiddleware::STATE_PRIVATE, HTTPCacheControlMiddleware::STATE_PUBLIC]; if ($noStore) { $this->setStateDirective($applyTo, 'no-store'); $this->removeStateDirective($applyTo, 'max-age'); @@ -486,7 +486,7 @@ public function setNoStore($noStore = true) public function setNoCache($noCache = true) { // Affect all non-disabled states - $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC]; + $applyTo = [HTTPCacheControlMiddleware::STATE_ENABLED, HTTPCacheControlMiddleware::STATE_PRIVATE, HTTPCacheControlMiddleware::STATE_PUBLIC]; if ($noCache) { $this->setStateDirective($applyTo, 'no-cache'); $this->removeStateDirective($applyTo, 'max-age'); @@ -509,7 +509,7 @@ public function setNoCache($noCache = true) public function setMaxAge($age) { // Affect all non-disabled states - $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC]; + $applyTo = [HTTPCacheControlMiddleware::STATE_ENABLED, HTTPCacheControlMiddleware::STATE_PRIVATE, HTTPCacheControlMiddleware::STATE_PUBLIC]; $this->setStateDirective($applyTo, 'max-age', $age); if ($age) { $this->removeStateDirective($applyTo, 'no-cache'); @@ -529,7 +529,7 @@ public function setMaxAge($age) public function setSharedMaxAge($age) { // Affect all non-disabled states - $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC]; + $applyTo = [HTTPCacheControlMiddleware::STATE_ENABLED, HTTPCacheControlMiddleware::STATE_PRIVATE, HTTPCacheControlMiddleware::STATE_PUBLIC]; $this->setStateDirective($applyTo, 's-maxage', $age); if ($age) { $this->removeStateDirective($applyTo, 'no-cache'); @@ -547,7 +547,7 @@ public function setSharedMaxAge($age) */ public function setMustRevalidate($mustRevalidate = true) { - $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC]; + $applyTo = [HTTPCacheControlMiddleware::STATE_ENABLED, HTTPCacheControlMiddleware::STATE_PRIVATE, HTTPCacheControlMiddleware::STATE_PUBLIC]; $this->setStateDirective($applyTo, 'must-revalidate', $mustRevalidate); return $this; } @@ -569,8 +569,8 @@ public function setMustRevalidate($mustRevalidate = true) public function enableCache($force = false, $maxAge = null) { // Only execute this if its forcing level is high enough - if ($this->applyChangeLevel(self::LEVEL_ENABLED, $force)) { - $this->setState(self::STATE_ENABLED); + if ($this->applyChangeLevel(HTTPCacheControlMiddleware::LEVEL_ENABLED, $force)) { + $this->setState(HTTPCacheControlMiddleware::STATE_ENABLED); } if (!is_null($maxAge)) { @@ -600,8 +600,8 @@ public function enableCache($force = false, $maxAge = null) public function disableCache($force = false) { // Only execute this if its forcing level is high enough - if ($this->applyChangeLevel(self::LEVEL_DISABLED, $force)) { - $this->setState(self::STATE_DISABLED); + if ($this->applyChangeLevel(HTTPCacheControlMiddleware::LEVEL_DISABLED, $force)) { + $this->setState(HTTPCacheControlMiddleware::STATE_DISABLED); } return $this; } @@ -620,8 +620,8 @@ public function disableCache($force = false) public function privateCache($force = false) { // Only execute this if its forcing level is high enough - if ($this->applyChangeLevel(self::LEVEL_PRIVATE, $force)) { - $this->setState(self::STATE_PRIVATE); + if ($this->applyChangeLevel(HTTPCacheControlMiddleware::LEVEL_PRIVATE, $force)) { + $this->setState(HTTPCacheControlMiddleware::STATE_PRIVATE); } return $this; } @@ -641,8 +641,8 @@ public function privateCache($force = false) public function publicCache($force = false, $maxAge = null) { // Only execute this if its forcing level is high enough - if ($this->applyChangeLevel(self::LEVEL_PUBLIC, $force)) { - $this->setState(self::STATE_PUBLIC); + if ($this->applyChangeLevel(HTTPCacheControlMiddleware::LEVEL_PUBLIC, $force)) { + $this->setState(HTTPCacheControlMiddleware::STATE_PUBLIC); } if (!is_null($maxAge)) { diff --git a/src/Control/RequestHandler.php b/src/Control/RequestHandler.php index 872c6a05bae..fa2d02af0b2 100644 --- a/src/Control/RequestHandler.php +++ b/src/Control/RequestHandler.php @@ -130,7 +130,7 @@ public function __construct() /** * Handles URL requests. * - * - ViewableData::handleRequest() iterates through each rule in {@link self::$url_handlers}. + * - ViewableData::handleRequest() iterates through each rule in {@link RequestHandler::$url_handlers}. * - If the rule matches, the named method will be called. * - If there is still more URL to be processed, then handleRequest() * is called on the object that that method returns. @@ -445,7 +445,7 @@ protected function definingClassForAction($actionOrigCasing) /** * Check that the given action is allowed to be called from a URL. - * It will interrogate {@link self::$allowed_actions} to determine this. + * It will interrogate {@link RequestHandler::$allowed_actions} to determine this. * * @param string $action * @return bool diff --git a/src/Control/Session.php b/src/Control/Session.php index 8bdf6e0e99a..881a480a4cc 100644 --- a/src/Control/Session.php +++ b/src/Control/Session.php @@ -235,7 +235,7 @@ public function init(HTTPRequest $request) } // Funny business detected! - if (self::config()->get('strict_user_agent_check') && isset($this->data['HTTP_USER_AGENT'])) { + if (Session::config()->get('strict_user_agent_check') && isset($this->data['HTTP_USER_AGENT'])) { if ($this->data['HTTP_USER_AGENT'] !== $this->userAgent($request)) { $this->clearAll(); $this->restart($request); diff --git a/src/Control/Util/IPUtils.php b/src/Control/Util/IPUtils.php index 0d8d4e57c82..be3cdc52257 100644 --- a/src/Control/Util/IPUtils.php +++ b/src/Control/Util/IPUtils.php @@ -44,7 +44,7 @@ public static function checkIP($requestIP, $ips) $method = substr_count($requestIP ?? '', ':') > 1 ? 'checkIP6' : 'checkIP4'; foreach ($ips as $ip) { - if (self::$method($requestIP, trim($ip ?? ''))) { + if (IPUtils::$method($requestIP, trim($ip ?? ''))) { return true; } } diff --git a/src/Core/BaseKernel.php b/src/Core/BaseKernel.php index 4e6c56a1c90..957aa01cf13 100644 --- a/src/Core/BaseKernel.php +++ b/src/Core/BaseKernel.php @@ -139,7 +139,7 @@ public function __construct($basePath) */ protected function bootPHP() { - if ($this->getEnvironment() === self::LIVE) { + if ($this->getEnvironment() === BaseKernel::LIVE) { // limited to fatal errors and warnings in live mode error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT | E_NOTICE)); } else { @@ -262,7 +262,7 @@ public function getEnvironment() return $env; } - return self::LIVE; + return BaseKernel::LIVE; } abstract public function boot($flush = false); @@ -427,7 +427,7 @@ public function setModuleLoader(ModuleLoader $moduleLoader) public function setEnvironment($environment) { - if (!in_array($environment, [self::DEV, self::TEST, self::LIVE, null])) { + if (!in_array($environment, [BaseKernel::DEV, BaseKernel::TEST, BaseKernel::LIVE, null])) { throw new InvalidArgumentException( "Director::set_environment_type passed '$environment'. It should be passed dev, test, or live" ); diff --git a/src/Core/ClassInfo.php b/src/Core/ClassInfo.php index 7c8094d0f0e..527af52386a 100644 --- a/src/Core/ClassInfo.php +++ b/src/Core/ClassInfo.php @@ -88,16 +88,16 @@ public static function exists($class) public static function hasTable($tableName) { // Cache the list of all table names to reduce on DB traffic - if (empty(self::$_cache_all_tables) && DB::is_active()) { - self::$_cache_all_tables = DB::get_schema()->tableList(); + if (empty(ClassInfo::$_cache_all_tables) && DB::is_active()) { + ClassInfo::$_cache_all_tables = DB::get_schema()->tableList(); } - return !empty(self::$_cache_all_tables[strtolower($tableName)]); + return !empty(ClassInfo::$_cache_all_tables[strtolower($tableName)]); } public static function reset_db_cache() { - self::$_cache_all_tables = null; - self::$_cache_ancestry = []; + ClassInfo::$_cache_all_tables = null; + ClassInfo::$_cache_ancestry = []; } /** @@ -114,7 +114,7 @@ public static function getValidSubClasses($class = SiteTree::class, $includeUnba return []; } - $class = self::class_name($class); + $class = ClassInfo::class_name($class); if ($includeUnbacked) { $table = DataObject::getSchema()->tableName($class); $classes = DB::get_schema()->enumValuesForField($table, 'ClassName'); @@ -138,10 +138,10 @@ public static function dataClassesFor($nameOrObject) } // Get all classes - $class = self::class_name($nameOrObject); + $class = ClassInfo::class_name($nameOrObject); $classes = array_merge( - self::ancestry($class), - self::subclassesFor($class) + ClassInfo::ancestry($class), + ClassInfo::subclassesFor($class) ); // Filter by table @@ -178,7 +178,7 @@ public static function subclassesFor($nameOrObject, $includeBaseClass = true) } // Get class names - $className = self::class_name($nameOrObject); + $className = ClassInfo::class_name($nameOrObject); $lowerClassName = strtolower($className ?? ''); // Merge with descendants @@ -192,7 +192,7 @@ public static function subclassesFor($nameOrObject, $includeBaseClass = true) /** * Convert a class name in any case and return it as it was defined in PHP * - * eg: self::class_name('dataobJEct'); //returns 'DataObject' + * eg: ClassInfo::class_name('dataobJEct'); //returns 'DataObject' * * @param string|object $nameOrObject The classname or object you want to normalise * @throws \ReflectionException @@ -234,23 +234,23 @@ public static function ancestry($nameOrObject, $tablesOnly = false) return []; } - $class = self::class_name($nameOrObject); + $class = ClassInfo::class_name($nameOrObject); $lowerClass = strtolower($class ?? ''); $cacheKey = $lowerClass . '_' . (string)$tablesOnly; $parent = $class; - if (!isset(self::$_cache_ancestry[$cacheKey])) { + if (!isset(ClassInfo::$_cache_ancestry[$cacheKey])) { $ancestry = []; do { if (!$tablesOnly || DataObject::getSchema()->classHasTable($parent)) { $ancestry[strtolower($parent)] = $parent; } } while ($parent = get_parent_class($parent ?? '')); - self::$_cache_ancestry[$cacheKey] = array_reverse($ancestry ?? []); + ClassInfo::$_cache_ancestry[$cacheKey] = array_reverse($ancestry ?? []); } - return self::$_cache_ancestry[$cacheKey]; + return ClassInfo::$_cache_ancestry[$cacheKey]; } /** @@ -273,7 +273,7 @@ public static function implementorsOf($interfaceName) public static function classImplements($className, $interfaceName) { $lowerClassName = strtolower($className ?? ''); - $implementors = self::implementorsOf($interfaceName); + $implementors = ClassInfo::implementorsOf($interfaceName); return isset($implementors[$lowerClassName]); } @@ -336,22 +336,22 @@ public static function has_method_from($class, $method, $compclass) $lClass = strtolower($class ?? ''); $lMethod = strtolower($method ?? ''); $lCompclass = strtolower($compclass ?? ''); - if (!isset(self::$_cache_methods[$lClass])) { - self::$_cache_methods[$lClass] = []; + if (!isset(ClassInfo::$_cache_methods[$lClass])) { + ClassInfo::$_cache_methods[$lClass] = []; } - if (!array_key_exists($lMethod, self::$_cache_methods[$lClass] ?? [])) { - self::$_cache_methods[$lClass][$lMethod] = false; + if (!array_key_exists($lMethod, ClassInfo::$_cache_methods[$lClass] ?? [])) { + ClassInfo::$_cache_methods[$lClass][$lMethod] = false; $classRef = new ReflectionClass($class); if ($classRef->hasMethod($method)) { $methodRef = $classRef->getMethod($method); - self::$_cache_methods[$lClass][$lMethod] = $methodRef->getDeclaringClass()->getName(); + ClassInfo::$_cache_methods[$lClass][$lMethod] = $methodRef->getDeclaringClass()->getName(); } } - return strtolower(self::$_cache_methods[$lClass][$lMethod] ?? '') === $lCompclass; + return strtolower(ClassInfo::$_cache_methods[$lClass][$lMethod] ?? '') === $lCompclass; } /** @@ -561,7 +561,7 @@ public static function classesWithExtension( bool $includeBaseClass = false ): array { // get class names - $baseClass = self::class_name($baseClassOrObject); + $baseClass = ClassInfo::class_name($baseClassOrObject); // get a list of all subclasses for a given class $classes = ClassInfo::subclassesFor($baseClass, $includeBaseClass); diff --git a/src/Core/Config/Config.php b/src/Core/Config/Config.php index 89aab2a32d2..2981b7c3d55 100644 --- a/src/Core/Config/Config.php +++ b/src/Core/Config/Config.php @@ -79,7 +79,7 @@ public static function modify() public static function nest() { // Clone current config and nest - $new = self::inst()->nest(); + $new = Config::inst()->nest(); ConfigLoader::inst()->pushManifest($new); return $new; } diff --git a/src/Core/Config/ConfigLoader.php b/src/Core/Config/ConfigLoader.php index 9ea7104e41c..9af5a452367 100644 --- a/src/Core/Config/ConfigLoader.php +++ b/src/Core/Config/ConfigLoader.php @@ -12,7 +12,7 @@ class ConfigLoader { /** * @internal - * @var self + * @var ConfigLoader */ private static $instance; @@ -22,11 +22,11 @@ class ConfigLoader protected $manifests = []; /** - * @return self + * @return ConfigLoader */ public static function inst() { - return self::$instance ? self::$instance : self::$instance = new static(); + return ConfigLoader::$instance ? ConfigLoader::$instance : ConfigLoader::$instance = new static(); } /** @@ -37,7 +37,7 @@ public static function inst() */ public function getManifest() { - if ($this !== self::$instance) { + if ($this !== ConfigLoader::$instance) { throw new BadMethodCallException( "Non-current config manifest cannot be accessed. Please call ->activate() first" ); diff --git a/src/Core/Convert.php b/src/Core/Convert.php index c4140ad863c..c7fbeed4503 100644 --- a/src/Core/Convert.php +++ b/src/Core/Convert.php @@ -36,7 +36,7 @@ class Convert */ public static function raw2att($val) { - return self::raw2xml($val); + return Convert::raw2xml($val); } /** @@ -49,7 +49,7 @@ public static function raw2att($val) */ public static function raw2htmlatt($val) { - return self::raw2att($val); + return Convert::raw2att($val); } /** @@ -68,13 +68,13 @@ public static function raw2htmlname($val) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::raw2htmlname($v); + $val[$k] = Convert::raw2htmlname($v); } return $val; } - return self::raw2att($val); + return Convert::raw2att($val); } /** @@ -93,7 +93,7 @@ public static function raw2htmlid($val) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::raw2htmlid($v); + $val[$k] = Convert::raw2htmlid($v); } return $val; @@ -122,7 +122,7 @@ public static function raw2xml($val) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::raw2xml($v); + $val[$k] = Convert::raw2xml($v); } return $val; } @@ -142,7 +142,7 @@ public static function raw2js($val) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::raw2js($v); + $val[$k] = Convert::raw2js($v); } return $val; } @@ -171,7 +171,7 @@ public static function raw2sql($val, $quoted = false) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::raw2sql($v, $quoted); + $val[$k] = Convert::raw2sql($v, $quoted); } return $val; } @@ -211,14 +211,14 @@ public static function xml2raw($val) { if (is_array($val)) { foreach ($val as $k => $v) { - $val[$k] = self::xml2raw($v); + $val[$k] = Convert::xml2raw($v); } return $val; } // More complex text needs to use html2raw instead if (strpos($val ?? '', '<') !== false) { - return self::html2raw($val); + return Convert::html2raw($val); } return html_entity_decode($val ?? '', ENT_QUOTES, 'UTF-8'); diff --git a/src/Core/Environment.php b/src/Core/Environment.php index a6b0fc7ef56..1e328647d22 100644 --- a/src/Core/Environment.php +++ b/src/Core/Environment.php @@ -217,7 +217,7 @@ public static function putEnv($string) // Parse name-value pairs $envVars = parse_ini_string($string ?? '') ?: []; foreach ($envVars as $name => $value) { - self::setEnv($name, $value); + Environment::setEnv($name, $value); } } diff --git a/src/Core/Extensible.php b/src/Core/Extensible.php index 91bf23ce2a9..7ec91ee4ebc 100644 --- a/src/Core/Extensible.php +++ b/src/Core/Extensible.php @@ -124,7 +124,7 @@ protected function defineExtensionMethods() foreach ($extensions as $extensionClass => $extensionInstance) { foreach ($this->findMethodsFrom($extensionInstance) as $method) { $this->addCallbackMethod($method, function ($inst, $args) use ($method, $extensionClass) { - /** @var Extensible $inst */ + /** @var self $inst */ $extension = $inst->getExtensionInstance($extensionClass); if (!$extension) { return null; diff --git a/src/Core/Injector/Injector.php b/src/Core/Injector/Injector.php index 7af9df4c240..afb909a5b84 100644 --- a/src/Core/Injector/Injector.php +++ b/src/Core/Injector/Injector.php @@ -262,7 +262,7 @@ public static function inst() public static function nest() { // Clone current injector and nest - $new = clone self::inst(); + $new = clone Injector::inst(); InjectorLoader::inst()->pushManifest($new); return $new; } @@ -597,7 +597,7 @@ protected function instantiate($spec, $id = null, $type = null) // If we're dealing with a DataObject singleton without specific constructor params, pass through Singleton // flag as second argument - if ((!$type || $type !== self::PROTOTYPE) + if ((!$type || $type !== Injector::PROTOTYPE) && empty($constructorParams) && is_subclass_of($class, DataObject::class)) { $constructorParams = [null, DataObject::CREATE_SINGLETON]; @@ -651,7 +651,7 @@ protected function instantiate($spec, $id = null, $type = null) $type = isset($spec['type']) ? $spec['type'] : null; } - if ($id && (!$type || $type !== self::PROTOTYPE)) { + if ($id && (!$type || $type !== Injector::PROTOTYPE)) { // this ABSOLUTELY must be set before the object is injected. // This prevents circular reference errors down the line $this->serviceCache[$id] = $object; @@ -1006,16 +1006,16 @@ protected function getNamedService($name, $asSingleton = true, $constructorArgs // Check if we are getting a prototype or singleton $type = $asSingleton - ? (isset($spec['type']) ? $spec['type'] : self::SINGLETON) - : self::PROTOTYPE; + ? (isset($spec['type']) ? $spec['type'] : Injector::SINGLETON) + : Injector::PROTOTYPE; // Return existing instance for singletons - if ($type === self::SINGLETON && isset($this->serviceCache[$name])) { + if ($type === Injector::SINGLETON && isset($this->serviceCache[$name])) { return $this->serviceCache[$name]; } // Update constructor args - if ($type === self::PROTOTYPE && $constructorArgs) { + if ($type === Injector::PROTOTYPE && $constructorArgs) { // Passed in args are expected to already be normalised (no service references) $spec['constructor'] = $constructorArgs; } else { diff --git a/src/Core/Injector/InjectorLoader.php b/src/Core/Injector/InjectorLoader.php index 4b5a857a5a6..6a1e958ef37 100644 --- a/src/Core/Injector/InjectorLoader.php +++ b/src/Core/Injector/InjectorLoader.php @@ -13,7 +13,7 @@ class InjectorLoader /** * @internal - * @var self + * @var InjectorLoader */ private static $instance; @@ -23,11 +23,11 @@ class InjectorLoader protected $manifests = []; /** - * @return self + * @return InjectorLoader */ public static function inst() { - return self::$instance ? self::$instance : self::$instance = new static(); + return InjectorLoader::$instance ? InjectorLoader::$instance : InjectorLoader::$instance = new static(); } /** @@ -38,13 +38,13 @@ public static function inst() */ public function getManifest() { - if ($this !== self::$instance) { + if ($this !== InjectorLoader::$instance) { throw new BadMethodCallException( "Non-current injector manifest cannot be accessed. Please call ->activate() first" ); } if (empty($this->manifests)) { - throw new BadMethodCallException(self::NO_MANIFESTS_AVAILABLE); + throw new BadMethodCallException(InjectorLoader::NO_MANIFESTS_AVAILABLE); } return $this->manifests[count($this->manifests) - 1]; } diff --git a/src/Core/Manifest/ClassLoader.php b/src/Core/Manifest/ClassLoader.php index d8386c5e431..6ce5d65b685 100644 --- a/src/Core/Manifest/ClassLoader.php +++ b/src/Core/Manifest/ClassLoader.php @@ -27,7 +27,7 @@ class ClassLoader */ public static function inst() { - return self::$instance ? self::$instance : self::$instance = new static(); + return ClassLoader::$instance ? ClassLoader::$instance : ClassLoader::$instance = new static(); } /** diff --git a/src/Core/Manifest/ManifestFileFinder.php b/src/Core/Manifest/ManifestFileFinder.php index 493d911752a..f2a110db53e 100644 --- a/src/Core/Manifest/ManifestFileFinder.php +++ b/src/Core/Manifest/ManifestFileFinder.php @@ -41,7 +41,7 @@ public function acceptDir($basename, $pathname, $depth) $inVendor = $this->isInsideVendor($basename, $pathname, $depth); if ($inVendor) { // Skip nested vendor folders (e.g. vendor/silverstripe/framework/vendor) - if ($depth == 4 && basename($pathname ?? '') === self::VENDOR_DIR) { + if ($depth == 4 && basename($pathname ?? '') === ManifestFileFinder::VENDOR_DIR) { return false; } @@ -82,7 +82,7 @@ public function acceptDir($basename, $pathname, $depth) public function isInsideVendor($basename, $pathname, $depth) { $base = basename($this->upLevels($pathname, $depth - 1) ?? ''); - return $base === self::VENDOR_DIR; + return $base === ManifestFileFinder::VENDOR_DIR; } /** @@ -170,12 +170,12 @@ public function isDirectoryModule($basename, $pathname, $depth) } // True if config file exists - if (file_exists($pathname . '/' . self::CONFIG_FILE)) { + if (file_exists($pathname . '/' . ManifestFileFinder::CONFIG_FILE)) { return true; } // True if config dir exists - if (file_exists($pathname . '/' . self::CONFIG_DIR)) { + if (file_exists($pathname . '/' . ManifestFileFinder::CONFIG_DIR)) { return true; } @@ -207,9 +207,9 @@ protected function upLevels($pathname, $depth) */ protected function getIgnoredDirs() { - $ignored = [self::LANG_DIR, 'node_modules']; + $ignored = [ManifestFileFinder::LANG_DIR, 'node_modules']; if ($this->getOption('ignore_tests')) { - $ignored[] = self::TESTS_DIR; + $ignored[] = ManifestFileFinder::TESTS_DIR; } return $ignored; } @@ -229,7 +229,7 @@ public function isDirectoryIgnored($basename, $pathname, $depth) } // Check if manifest-ignored is present - if (file_exists($pathname . '/' . self::EXCLUDE_FILE)) { + if (file_exists($pathname . '/' . ManifestFileFinder::EXCLUDE_FILE)) { return true; } diff --git a/src/Core/Manifest/ModuleLoader.php b/src/Core/Manifest/ModuleLoader.php index 10dbe948b8b..8e1c59bd78e 100644 --- a/src/Core/Manifest/ModuleLoader.php +++ b/src/Core/Manifest/ModuleLoader.php @@ -8,7 +8,7 @@ class ModuleLoader { /** - * @var self + * @var ModuleLoader */ private static $instance; @@ -18,11 +18,11 @@ class ModuleLoader protected $manifests = []; /** - * @return self + * @return ModuleLoader */ public static function inst() { - return self::$instance ? self::$instance : self::$instance = new static(); + return ModuleLoader::$instance ? ModuleLoader::$instance : ModuleLoader::$instance = new static(); } /** diff --git a/src/Core/Manifest/ModuleManifest.php b/src/Core/Manifest/ModuleManifest.php index 1ec7eaedfe0..bb8f29a50bd 100644 --- a/src/Core/Manifest/ModuleManifest.php +++ b/src/Core/Manifest/ModuleManifest.php @@ -241,7 +241,7 @@ public function sort() ); if ($project) { - $sorter->setVariable(self::PROJECT_KEY, $project); + $sorter->setVariable(ModuleManifest::PROJECT_KEY, $project); } $this->modules = $sorter->getSortedList(); diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 4a0d4b48e44..b3477a3ba05 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -175,7 +175,7 @@ private function filterModules(array $modules) */ public function getModules() { - $modules = Config::inst()->get(self::class, 'modules'); + $modules = Config::inst()->get(VersionProvider::class, 'modules'); return !empty($modules) ? $modules : ['silverstripe/framework' => 'Framework']; } diff --git a/src/Core/Path.php b/src/Core/Path.php index 891dc3754ce..7d06a1e8516 100644 --- a/src/Core/Path.php +++ b/src/Core/Path.php @@ -53,9 +53,9 @@ public static function normalise($path, $relative = false) { $path = trim(Convert::slashes($path) ?? ''); if ($relative) { - return trim($path ?? '', self::TRIM_CHARS ?? ''); + return trim($path ?? '', Path::TRIM_CHARS ?? ''); } else { - return rtrim($path ?? '', self::TRIM_CHARS ?? ''); + return rtrim($path ?? '', Path::TRIM_CHARS ?? ''); } } } diff --git a/src/Dev/Backtrace.php b/src/Dev/Backtrace.php index bef017108da..62d402efc51 100644 --- a/src/Dev/Backtrace.php +++ b/src/Dev/Backtrace.php @@ -31,7 +31,7 @@ class Backtrace */ public static function filtered_backtrace($ignoredFunctions = null) { - return self::filter_backtrace(debug_backtrace(), $ignoredFunctions); + return Backtrace::filter_backtrace(debug_backtrace(), $ignoredFunctions); } /** @@ -70,7 +70,7 @@ public static function filter_backtrace($bt, $ignoredFunctions = null) } } - while ($bt && in_array(self::full_func_name($bt[0]), $defaultIgnoredFunctions ?? [])) { + while ($bt && in_array(Backtrace::full_func_name($bt[0]), $defaultIgnoredFunctions ?? [])) { array_shift($bt); } @@ -82,7 +82,7 @@ public static function filter_backtrace($bt, $ignoredFunctions = null) if (!empty($frame['class'])) { foreach ($ignoredArgs as $fnSpec) { if (is_array($fnSpec) - && self::matchesFilterableClass($frame['class'], $fnSpec[0]) + && Backtrace::matchesFilterableClass($frame['class'], $fnSpec[0]) && $frame['function'] == $fnSpec[1] ) { $match = true; @@ -115,7 +115,7 @@ public static function filter_backtrace($bt, $ignoredFunctions = null) public static function backtrace($returnVal = false, $ignoreAjax = false, $ignoredFunctions = null) { $plainText = Director::is_cli() || (Director::is_ajax() && !$ignoreAjax); - $result = self::get_rendered_backtrace(debug_backtrace(), $plainText, $ignoredFunctions); + $result = Backtrace::get_rendered_backtrace(debug_backtrace(), $plainText, $ignoredFunctions); if ($returnVal) { return $result; } else { @@ -176,11 +176,11 @@ public static function get_rendered_backtrace($bt, $plainText = false, $ignoredF if (empty($bt)) { return ''; } - $bt = self::filter_backtrace($bt, $ignoredFunctions); + $bt = Backtrace::filter_backtrace($bt, $ignoredFunctions); $result = ($plainText) ? '' : '