Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Use class name instead of self #110

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/ErrorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ErrorPage extends Page

/**
* An array of error codes to allow in the CMS
* If null, defaults to all available codes (see self::getCodes())
* If null, defaults to all available codes (see ErrorPage::getCodes())
*/
private static ?array $allowed_error_codes = null;

Expand Down Expand Up @@ -120,7 +120,7 @@ public static function response_for($statusCode, $errorMessage = null)
Requirements::clear_combined_files();

//set @var dev_append_error_message to false to opt out of dev message
$showDevMessage = (self::config()->dev_append_error_message === true);
$showDevMessage = (static::config()->dev_append_error_message === true);

if ($errorMessage) {
// Dev environments will have the error message added regardless of template changes
Expand All @@ -140,7 +140,7 @@ public static function response_for($statusCode, $errorMessage = null)
}

// then fall back on a cached version
$content = self::get_content_for_errorcode($statusCode);
$content = ErrorPage::get_content_for_errorcode($statusCode);
if ($content) {
$response = new HTTPResponse();
$response->setStatusCode($statusCode);
Expand All @@ -163,7 +163,7 @@ public function requireDefaultRecords()
parent::requireDefaultRecords();

// Only run on ErrorPage class directly, not subclasses
if (static::class !== self::class || !SiteTree::config()->get('create_default_pages')) {
if (static::class !== ErrorPage::class || !SiteTree::config()->get('create_default_pages')) {
return;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ protected function requireDefaultRecordFixture($defaultData)
}

// Check if static files are enabled
if (!self::config()->get('enable_static_file')) {
if (!static::config()->get('enable_static_file')) {
return;
}

Expand Down Expand Up @@ -297,14 +297,14 @@ public function publishSingle()
*/
protected function hasStaticPage()
{
if (!self::config()->get('enable_static_file')) {
if (!static::config()->get('enable_static_file')) {
return false;
}

// Attempt to retrieve content from generated file handler
$filename = $this->getErrorFilename();
$storeFilename = File::join_paths(self::config()->get('store_filepath'), $filename);
$result = self::get_asset_handler()->getContent($storeFilename);
$storeFilename = File::join_paths(static::config()->get('store_filepath'), $filename);
$result = ErrorPage::get_asset_handler()->getContent($storeFilename);
return !empty($result);
}

Expand All @@ -315,7 +315,7 @@ protected function hasStaticPage()
*/
public function writeStaticPage()
{
if (!self::config()->get('enable_static_file')) {
if (!static::config()->get('enable_static_file')) {
return false;
}

Expand All @@ -342,10 +342,10 @@ public function writeStaticPage()
if ($errorContent) {
// Store file content in the default store
$storeFilename = File::join_paths(
self::config()->get('store_filepath'),
static::config()->get('store_filepath'),
$this->getErrorFilename()
);
self::get_asset_handler()->setContent($storeFilename, $errorContent);
ErrorPage::get_asset_handler()->setContent($storeFilename, $errorContent);

return true;
} else {
Expand Down Expand Up @@ -373,17 +373,17 @@ public function fieldLabels($includerelations = true)
*/
public static function get_content_for_errorcode($statusCode)
{
if (!self::config()->get('enable_static_file')) {
if (!static::config()->get('enable_static_file')) {
return null;
}

// Attempt to retrieve content from generated file handler
$filename = self::get_error_filename($statusCode);
$filename = ErrorPage::get_error_filename($statusCode);
$storeFilename = File::join_paths(
self::config()->get('store_filepath'),
static::config()->get('store_filepath'),
$filename
);
return self::get_asset_handler()->getContent($storeFilename);
return ErrorPage::get_asset_handler()->getContent($storeFilename);
}

protected function getCodes()
Expand Down Expand Up @@ -466,7 +466,7 @@ protected static function get_error_filename($statusCode, $instance = null)
*/
protected function getErrorFilename()
{
return self::get_error_filename($this->ErrorCode, $this);
return ErrorPage::get_error_filename($this->ErrorCode, $this);
}

/**
Expand Down
Loading