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 #1773

Merged
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions code/AdminRootController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function get_admin_route()
*/
public static function admin_url(string $action = '')
{
return Controller::join_links(self::get_admin_route(), $action);
return Controller::join_links(AdminRootController::get_admin_route(), $action);
}

/**
Expand Down Expand Up @@ -69,18 +69,18 @@ public static function admin_url(string $action = '')
*/
public static function rules()
{
if (self::$adminRules === null) {
self::$adminRules = [];
if (AdminRootController::$adminRules === null) {
AdminRootController::$adminRules = [];

// Map over the array calling add_rule_for_controller on each
$classes = CMSMenu::get_cms_classes(null, true, CMSMenu::URL_PRIORITY);
array_map([__CLASS__, 'add_rule_for_controller'], $classes ?? []);
}
return self::$adminRules;
return AdminRootController::$adminRules;
}

/**
* Add the appropriate k/v pair to self::$rules for the given controller.
* Add the appropriate k/v pair to AdminRootController::$rules for the given controller.
*
* @param string $controllerClass Name of class
*/
Expand All @@ -98,8 +98,8 @@ protected static function add_rule_for_controller($controllerClass)
$rule = $urlSegment . '//' . $urlRule;

// ensure that the first call to add_rule_for_controller for a rule takes precedence
if (!isset(self::$adminRules[$rule])) {
self::$adminRules[$rule] = $controllerClass;
if (!isset(AdminRootController::$adminRules[$rule])) {
AdminRootController::$adminRules[$rule] = $controllerClass;
}
}
}
Expand All @@ -111,12 +111,12 @@ public function handleRequest(HTTPRequest $request): HTTPResponse
$segment = Config::forClass($this->config()->get('default_panel'))
->get('url_segment');

$this->redirect(Controller::join_links(self::admin_url(), $segment, '/'));
$this->redirect(Controller::join_links(AdminRootController::admin_url(), $segment, '/'));
return $this->getResponse();
}

// Otherwise
$rules = self::rules();
$rules = AdminRootController::rules();
foreach ($rules as $pattern => $controller) {
if (($arguments = $request->match($pattern, true)) !== false) {
/** @var LeftAndMain $controllerObj */
Expand Down
46 changes: 23 additions & 23 deletions code/CMSMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CMSMenu implements IteratorAggregate, i18nEntityProvider
*/
public static function populate_menu()
{
self::$menu_is_cleared = false;
CMSMenu::$menu_is_cleared = false;
}

/**
Expand All @@ -73,9 +73,9 @@ public static function populate_menu()
*/
public static function add_controller($controllerClass)
{
if ($menuItem = self::menuitem_for_controller($controllerClass)) {
if ($menuItem = CMSMenu::menuitem_for_controller($controllerClass)) {
$code = static::get_menu_code($controllerClass);
self::add_menu_item_obj($code, $menuItem);
CMSMenu::add_menu_item_obj($code, $menuItem);
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ protected static function menuitem_for_controller($controllerClass)
*/
public static function add_link($code, $menuTitle, $url, $priority = -1, $attributes = null, $iconClass = null)
{
return self::add_menu_item($code, $menuTitle, $url, null, $priority, $attributes, $iconClass);
return CMSMenu::add_menu_item($code, $menuTitle, $url, null, $priority, $attributes, $iconClass);
}

/**
Expand Down Expand Up @@ -155,10 +155,10 @@ public static function add_menu_item(
) {
// If a class is defined, then force the use of that as a code. This helps prevent menu item duplication
if ($controllerClass) {
$code = self::get_menu_code($controllerClass);
$code = CMSMenu::get_menu_code($controllerClass);
}

return self::replace_menu_item(
return CMSMenu::replace_menu_item(
$code,
$menuTitle,
$url,
Expand All @@ -177,7 +177,7 @@ public static function add_menu_item(
*/
public static function get_menu_item($code)
{
$menuItems = self::get_menu_items();
$menuItems = CMSMenu::get_menu_items();
return (isset($menuItems[$code])) ? $menuItems[$code] : false;
}

Expand All @@ -202,19 +202,19 @@ public static function get_menu_items()
$menuItems = [];

// Set up default menu items
if (!self::$menu_is_cleared) {
$cmsClasses = self::get_cms_classes();
if (!CMSMenu::$menu_is_cleared) {
$cmsClasses = CMSMenu::get_cms_classes();
foreach ($cmsClasses as $cmsClass) {
$menuItem = self::menuitem_for_controller($cmsClass);
$menuCode = self::get_menu_code($cmsClass);
$menuItem = CMSMenu::menuitem_for_controller($cmsClass);
$menuCode = CMSMenu::get_menu_code($cmsClass);
if ($menuItem) {
$menuItems[$menuCode] = $menuItem;
}
}
}

// Apply changes
foreach (self::$menu_item_changes as $change) {
foreach (CMSMenu::$menu_item_changes as $change) {
switch ($change['type']) {
case 'add':
$menuItems[$change['code']] = $change['item'];
Expand Down Expand Up @@ -255,7 +255,7 @@ public static function get_viewable_menu_items($member = null)
}

$viewableMenuItems = [];
$allMenuItems = self::get_menu_items();
$allMenuItems = CMSMenu::get_menu_items();
if ($allMenuItems) {
foreach ($allMenuItems as $code => $menuItem) {
// exclude all items which have a controller to perform permission
Expand Down Expand Up @@ -286,7 +286,7 @@ public static function get_viewable_menu_items($member = null)
*/
public static function remove_menu_item($code)
{
self::$menu_item_changes[] = ['type' => 'remove', 'code' => $code];
CMSMenu::$menu_item_changes[] = ['type' => 'remove', 'code' => $code];
}

/**
Expand All @@ -296,17 +296,17 @@ public static function remove_menu_item($code)
*/
public static function remove_menu_class($className)
{
$code = self::get_menu_code($className);
self::remove_menu_item($code);
$code = CMSMenu::get_menu_code($className);
CMSMenu::remove_menu_item($code);
}

/**
* Clears the entire menu
*/
public static function clear_menu()
{
self::$menu_item_changes = [];
self::$menu_is_cleared = true;
CMSMenu::$menu_item_changes = [];
CMSMenu::$menu_is_cleared = true;
}

/**
Expand Down Expand Up @@ -341,7 +341,7 @@ public static function replace_menu_item(
$item->setAttributes($attributes);
}

self::$menu_item_changes[] = [
CMSMenu::$menu_item_changes[] = [
'type' => 'add',
'code' => $code,
'item' => $item,
Expand All @@ -356,7 +356,7 @@ public static function replace_menu_item(
*/
protected static function add_menu_item_obj($code, $cmsMenuItem)
{
self::$menu_item_changes[] = [
CMSMenu::$menu_item_changes[] = [
'type' => 'add',
'code' => $code,
'item' => $cmsMenuItem,
Expand All @@ -374,7 +374,7 @@ protected static function add_menu_item_obj($code, $cmsMenuItem)
* @param string $sort Name of config on which to sort. Can be 'menu_priority' or 'url_priority'
* @return array Valid, unique subclasses
*/
public static function get_cms_classes($root = null, $recursive = true, $sort = self::MENU_PRIORITY)
public static function get_cms_classes($root = null, $recursive = true, $sort = CMSMenu::MENU_PRIORITY)
{
if (!$root) {
$root = LeftAndMain::class;
Expand Down Expand Up @@ -415,15 +415,15 @@ public static function get_cms_classes($root = null, $recursive = true, $sort =
*/
public function getIterator(): Traversable
{
return new ArrayIterator(self::get_menu_items());
return new ArrayIterator(CMSMenu::get_menu_items());
}

/**
* Provide menu titles to the i18n entity provider
*/
public function provideI18nEntities()
{
$cmsClasses = self::get_cms_classes();
$cmsClasses = CMSMenu::get_cms_classes();
$entities = [];
foreach ($cmsClasses as $cmsClass) {
$defaultTitle = LeftAndMain::menu_title($cmsClass, false);
Expand Down
8 changes: 4 additions & 4 deletions code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public static function getRequiredPermissions()
{
$class = get_called_class();
// If the user is accessing LeftAndMain directly, only generic permissions are required.
if ($class === self::class) {
if ($class === LeftAndMain::class) {
return 'CMS_ACCESS';
}
$code = Config::inst()->get($class, 'required_permission_codes');
Expand Down Expand Up @@ -814,7 +814,7 @@ public function afterHandleRequest()
$errorCode = $this->response->getStatusCode();
$errorType = $this->response->getStatusDescription();
$defaultMessage = _t(
self::class . '.ErrorMessage',
LeftAndMain::class . '.ErrorMessage',
'Sorry, it seems there was a {errorcode} error.',
['errorcode' => $errorCode]
);
Expand All @@ -825,7 +825,7 @@ public function afterHandleRequest()
'ErrorType' => $errorType,
'Message' => DBField::create_field(
'HTMLFragment',
_t(self::class . '.ErrorMessage' . $errorCode, $defaultMessage)
_t(LeftAndMain::class . '.ErrorMessage' . $errorCode, $defaultMessage)
),
]),
]), $errorCode, $errorType);
Expand Down Expand Up @@ -2067,7 +2067,7 @@ public function getHttpErrorMessage(): string
* Called by {@link LeftAndMainErrorExtension}
* @internal
*/
public function setHttpErrorMessage(string $message): self
public function setHttpErrorMessage(string $message): LeftAndMain
{
$this->httpErrorMessage = $message;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ abstract class ModelAdmin extends LeftAndMain
*
* Sets the `modelClass` field which determines which of the {@link DataObject} objects will have visible data. This
* is determined by the URL (with the first slug being the name of the DataObject class to represent. If this class
* is loaded without any URL, we pick the first DataObject from the list of {@link self::$managed_models}.
* is loaded without any URL, we pick the first DataObject from the list of {@link ModelAdmin::$managed_models}.
*/
protected function init()
{
Expand Down Expand Up @@ -247,7 +247,7 @@ public function getCMSEditLinkForManagedDataObject(DataObject $obj): string
/**
* Produces an edit form that includes a default {@link \SilverStripe\Forms\GridField\GridField} for the currently
* active {@link \SilverStripe\ORM\DataObject}. The GridField will show data from the currently active `modelClass`
* only (see {@link self::init()}).
* only (see {@link ModelAdmin::init()}).
*
* @param int|null $id
* @param \SilverStripe\Forms\FieldList $fields
Expand Down Expand Up @@ -534,8 +534,8 @@ public function isManagedModel(string $modelClassOrModelTab): bool
}

/**
* Returns all importers defined in {@link self::$model_importers}.
* If none are defined, we fall back to {@link self::managed_models}
* Returns all importers defined in {@link ModelAdmin::$model_importers}.
* If none are defined, we fall back to {@link ModelAdmin::managed_models}
* with a default {@link CsvBulkLoader} class. In this case the column names of the first row
* in the CSV file are assumed to have direct mappings to properties on the object.
*
Expand Down Expand Up @@ -645,7 +645,7 @@ public function ImportForm()

/**
* Imports the submitted CSV file based on specifications given in
* {@link self::model_importers}.
* {@link ModelAdmin::model_importers}.
* Redirects back with a success/failure message.
*/
public function import(array $data, Form $form): HTTPResponse
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Navigator/SilverStripeNavigatorTest_TestItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SilverStripeNavigatorTest_TestItem extends SilverStripeNavigatorItem imple
{
public function getTitle()
{
return self::class;
return SilverStripeNavigatorTest_TestItem::class;
}

public function getHTML()
Expand Down
Loading