diff --git a/.github/workflows/add-prs-to-project.yml b/.github/workflows/add-prs-to-project.yml new file mode 100644 index 000000000..2d3f41ada --- /dev/null +++ b/.github/workflows/add-prs-to-project.yml @@ -0,0 +1,22 @@ +name: Add new PRs to github project + +on: + pull_request_target: + types: + - opened + - ready_for_review + +permissions: {} + +jobs: + addprtoproject: + name: Add PR to GitHub Project + # Only run on the silverstripe account + if: github.repository_owner == 'silverstripe' + runs-on: ubuntu-latest + steps: + - name: Add PR to github project + uses: silverstripe/gha-add-pr-to-project@v1 + with: + app_id: ${{ vars.PROJECT_PERMISSIONS_APP_ID }} + private_key: ${{ secrets.PROJECT_PERMISSIONS_APP_PRIVATE_KEY }} diff --git a/src/Control/ContentNegotiator.php b/src/Control/ContentNegotiator.php index 21ec89f3e..aeb3b9f54 100644 --- a/src/Control/ContentNegotiator.php +++ b/src/Control/ContentNegotiator.php @@ -116,7 +116,7 @@ class ContentNegotiator */ 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 80d7047c0..5b94f0ad6 100644 --- a/src/Control/Controller.php +++ b/src/Control/Controller.php @@ -573,7 +573,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider { // 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 @@ class Controller extends RequestHandler implements TemplateGlobalProvider */ 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 @@ class Controller extends RequestHandler implements TemplateGlobalProvider } // 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 2995e844f..2bcafa606 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 @@ class Cookie $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 @@ class Cookie */ 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 @@ class Cookie */ public static function get_all($includeUnsent = true) { - return self::get_inst()->getAll($includeUnsent); + return Cookie::get_inst()->getAll($includeUnsent); } /** @@ -104,7 +104,7 @@ class Cookie */ 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 @@ class Cookie 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 f91fc93b4..8318e5dd6 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -238,7 +238,7 @@ class Director implements TemplateGlobalProvider // 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 @@ class Director implements TemplateGlobalProvider */ 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 @@ class Director implements TemplateGlobalProvider */ public static function set_current_page($page) { - self::$current_page = $page; + Director::$current_page = $page; } /** @@ -394,7 +394,7 @@ class Director implements TemplateGlobalProvider * - 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 @@ class Director implements TemplateGlobalProvider // 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 @@ class Director implements TemplateGlobalProvider $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 @@ class Director implements TemplateGlobalProvider public static function host(HTTPRequest $request = null) { // Check if overridden by alternate_base_url - if ($baseURL = self::config()->get('alternate_base_url')) { + if ($baseURL = static::config()->get('alternate_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $host = static::parseHost($baseURL); if ($host) { @@ -508,7 +508,7 @@ class Director implements TemplateGlobalProvider } // Check base url - if ($baseURL = self::config()->uninherited('default_base_url')) { + if ($baseURL = static::config()->uninherited('default_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $host = static::parseHost($baseURL); if ($host) { @@ -566,7 +566,7 @@ class Director implements TemplateGlobalProvider */ 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 @@ class Director implements TemplateGlobalProvider public static function is_https(HTTPRequest $request = null) { // Check override from alternate_base_url - if ($baseURL = self::config()->uninherited('alternate_base_url')) { + if ($baseURL = static::config()->uninherited('alternate_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME); if ($protocol) { @@ -593,7 +593,7 @@ class Director implements TemplateGlobalProvider } // Check default_base_url - if ($baseURL = self::config()->uninherited('default_base_url')) { + if ($baseURL = static::config()->uninherited('default_base_url')) { $baseURL = Injector::inst()->convertServiceProperty($baseURL); $protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME); if ($protocol) { @@ -612,7 +612,7 @@ class Director implements TemplateGlobalProvider public static function baseURL() { // Check override base_url - $alternate = self::config()->get('alternate_base_url'); + $alternate = static::config()->get('alternate_base_url'); if ($alternate) { $alternate = Injector::inst()->convertServiceProperty($alternate); return rtrim(parse_url($alternate ?? '', PHP_URL_PATH) ?? '', '/') . '/'; @@ -659,8 +659,8 @@ class Director implements TemplateGlobalProvider */ 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 @@ class Director implements TemplateGlobalProvider } // 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 @@ class Director implements TemplateGlobalProvider } // Relative urls always are site urls - return self::is_relative_url($url); + return Director::is_relative_url($url); } /** @@ -840,20 +840,20 @@ class Director implements TemplateGlobalProvider 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 @@ class Director implements TemplateGlobalProvider */ 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 @@ class Director implements TemplateGlobalProvider */ 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 @@ class Director implements TemplateGlobalProvider */ public static function isLive() { - return self::get_environment_type() === 'live'; + return Director::get_environment_type() === 'live'; } /** @@ -1065,7 +1065,7 @@ class Director implements TemplateGlobalProvider */ public static function isDev() { - return self::get_environment_type() === 'dev'; + return Director::get_environment_type() === 'dev'; } /** @@ -1076,7 +1076,7 @@ class Director implements TemplateGlobalProvider */ 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 21420d61f..52b05dc94 100644 --- a/src/Control/Email/Email.php +++ b/src/Control/Email/Email.php @@ -104,10 +104,10 @@ class Email extends SymfonyEmail { $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 @@ class Email extends SymfonyEmail } 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 d13bd7728..d8a3b7248 100644 --- a/src/Control/HTTP.php +++ b/src/Control/HTTP.php @@ -226,7 +226,7 @@ class HTTP */ 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 @@ class HTTP */ public static function getLinksIn($content) { - return self::findByTagAndAttribute($content, ["a" => "href"]); + return HTTP::findByTagAndAttribute($content, ["a" => "href"]); } /** @@ -278,7 +278,7 @@ class HTTP */ 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 8cc1ab915..ee014d0fd 100644 --- a/src/Control/HTTPRequest.php +++ b/src/Control/HTTPRequest.php @@ -850,7 +850,7 @@ class HTTPRequest implements ArrayAccess */ 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 b7e47cbbe..3cb4a498b 100644 --- a/src/Control/HTTPResponse.php +++ b/src/Control/HTTPResponse.php @@ -174,7 +174,7 @@ class HTTPResponse */ 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 @@ class HTTPResponse if ($description) { $this->statusDescription = $description; } else { - $this->statusDescription = self::$status_codes[$code]; + $this->statusDescription = HTTPResponse::$status_codes[$code]; } return $this; } @@ -320,7 +320,7 @@ class HTTPResponse 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 @@ EOT */ 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 94fb0e2c3..c3da4f756 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -68,20 +68,20 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable * @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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable * @config * @var string */ - private static $defaultState = self::STATE_ENABLED; + private static $defaultState = HTTPCacheControlMiddleware::STATE_ENABLED; /** * Current state @@ -307,7 +307,7 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable */ 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable */ 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable 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 6bee1a6b7..4c2ee1b23 100644 --- a/src/Control/RequestHandler.php +++ b/src/Control/RequestHandler.php @@ -130,7 +130,7 @@ class RequestHandler extends ViewableData /** * 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 @@ class RequestHandler extends ViewableData /** * 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 8bdf6e0e9..51194b378 100644 --- a/src/Control/Session.php +++ b/src/Control/Session.php @@ -235,7 +235,7 @@ class Session } // Funny business detected! - if (self::config()->get('strict_user_agent_check') && isset($this->data['HTTP_USER_AGENT'])) { + if (static::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 0d8d4e57c..be3cdc522 100644 --- a/src/Control/Util/IPUtils.php +++ b/src/Control/Util/IPUtils.php @@ -44,7 +44,7 @@ class IPUtils $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 e749ac19e..ee6889602 100644 --- a/src/Core/BaseKernel.php +++ b/src/Core/BaseKernel.php @@ -140,7 +140,7 @@ abstract class BaseKernel implements Kernel */ 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 { @@ -263,7 +263,7 @@ abstract class BaseKernel implements Kernel return $env; } - return self::LIVE; + return BaseKernel::LIVE; } abstract public function boot($flush = false); @@ -431,7 +431,7 @@ abstract class BaseKernel implements Kernel 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 a1f95939b..46b0fa914 100644 --- a/src/Core/ClassInfo.php +++ b/src/Core/ClassInfo.php @@ -84,7 +84,7 @@ class ClassInfo implements Flushable */ public static function hasTable($tableName) { - $cache = self::getCache(); + $cache = ClassInfo::getCache(); $configData = serialize(DB::getConfig()); $cacheKey = 'tableList_' . md5($configData); $tableList = $cache->get($cacheKey) ?? []; @@ -103,13 +103,13 @@ class ClassInfo implements Flushable public static function reset_db_cache() { - self::getCache()->clear(); - self::$_cache_ancestry = []; + ClassInfo::getCache()->clear(); + ClassInfo::$_cache_ancestry = []; } public static function flush() { - self::reset_db_cache(); + ClassInfo::reset_db_cache(); } /** @@ -126,7 +126,7 @@ class ClassInfo implements Flushable 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'); @@ -150,10 +150,10 @@ class ClassInfo implements Flushable } // 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 @@ -190,7 +190,7 @@ class ClassInfo implements Flushable } // Get class names - $className = self::class_name($nameOrObject); + $className = ClassInfo::class_name($nameOrObject); $lowerClassName = strtolower($className ?? ''); // Merge with descendants @@ -204,7 +204,7 @@ class ClassInfo implements Flushable /** * 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 @@ -246,23 +246,23 @@ class ClassInfo implements Flushable 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]; } /** @@ -285,7 +285,7 @@ class ClassInfo implements Flushable public static function classImplements($className, $interfaceName) { $lowerClassName = strtolower($className ?? ''); - $implementors = self::implementorsOf($interfaceName); + $implementors = ClassInfo::implementorsOf($interfaceName); return isset($implementors[$lowerClassName]); } @@ -348,22 +348,22 @@ class ClassInfo implements Flushable $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; } /** @@ -573,7 +573,7 @@ class ClassInfo implements Flushable 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 89aab2a32..2981b7c3d 100644 --- a/src/Core/Config/Config.php +++ b/src/Core/Config/Config.php @@ -79,7 +79,7 @@ abstract class Config 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 9ea7104e4..9af5a4523 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 @@ class ConfigLoader */ 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 c4140ad86..c7fbeed45 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 @@ class Convert */ public static function raw2htmlatt($val) { - return self::raw2att($val); + return Convert::raw2att($val); } /** @@ -68,13 +68,13 @@ class Convert { 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 @@ class Convert { 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 @@ class Convert { 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 @@ class Convert { 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 @@ class Convert { 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 @@ class Convert { 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 aa39a0cc0..5860971b7 100644 --- a/src/Core/Environment.php +++ b/src/Core/Environment.php @@ -224,7 +224,7 @@ class Environment // 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/Injector/Injector.php b/src/Core/Injector/Injector.php index 7af9df4c2..afb909a5b 100644 --- a/src/Core/Injector/Injector.php +++ b/src/Core/Injector/Injector.php @@ -262,7 +262,7 @@ class Injector implements ContainerInterface 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 @@ class Injector implements ContainerInterface // 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 @@ class Injector implements ContainerInterface $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 @@ class Injector implements ContainerInterface // 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 4b5a857a5..6a1e958ef 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 @@ class InjectorLoader */ 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 d8386c5e4..6ce5d65b6 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 493d91175..f2a110db5 100644 --- a/src/Core/Manifest/ManifestFileFinder.php +++ b/src/Core/Manifest/ManifestFileFinder.php @@ -41,7 +41,7 @@ class ManifestFileFinder extends FileFinder $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 @@ class ManifestFileFinder extends FileFinder 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 @@ class ManifestFileFinder extends FileFinder } // 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 @@ class ManifestFileFinder extends FileFinder */ 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 @@ class ManifestFileFinder extends FileFinder } // 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 10dbe948b..8e1c59bd7 100644 --- a/src/Core/Manifest/ModuleLoader.php +++ b/src/Core/Manifest/ModuleLoader.php @@ -8,7 +8,7 @@ namespace SilverStripe\Core\Manifest; 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 1ec7eaedf..bb8f29a50 100644 --- a/src/Core/Manifest/ModuleManifest.php +++ b/src/Core/Manifest/ModuleManifest.php @@ -241,7 +241,7 @@ class ModuleManifest ); 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 4a0d4b48e..b3477a3ba 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -175,7 +175,7 @@ class VersionProvider */ 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 891dc3754..7d06a1e85 100644 --- a/src/Core/Path.php +++ b/src/Core/Path.php @@ -53,9 +53,9 @@ class Path { $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 bef017108..62d402efc 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 @@ class Backtrace } } - 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 @@ class Backtrace 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 @@ class Backtrace 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 @@ class Backtrace if (empty($bt)) { return ''; } - $bt = self::filter_backtrace($bt, $ignoredFunctions); + $bt = Backtrace::filter_backtrace($bt, $ignoredFunctions); $result = ($plainText) ? '' : '