cancel
Showing results for 
Search instead for 
Did you mean: 

Magento\Backend\App\AbstractAction::_isAllowed() should use a static binding

0 Kudos

Magento\Backend\App\AbstractAction::_isAllowed() should use a static binding

Feature request from brideo, posted on GitHub Nov 13, 2015

http://php.net/manual/en/language.oop5.late-static-bindings.php

Rather than this:

/**
 * @return bool
 */
protected function _isAllowed()
{
    return $this->_authorization->isAllowed(self::ADMIN_RESOURCE);
}

We should have this:

/**
 * @return bool
 */
protected function _isAllowed()
{
    return $this->_authorization->isAllowed(static::ADMIN_RESOURCE);
}

By using a static binding, we don't have to completely re-write the _isAllowed method in our controller action, instead we can simply define our ADMIN_RESOURCE constant, we then can let the AbstractAction handle our logic.

This would be a completely backwards compatible change.

6 Comments
Not applicable

Comment from ashsmith, posted on GitHub Nov 13, 2015

:+1:

Not applicable

Comment from pantaoran, posted on GitHub Jan 15, 2016

I also just stumbled across this. Please implement this.

Not applicable

Comment from karthickannan, posted on GitHub Jan 20, 2016

Not applicable

Comment from antonkril, posted on GitHub Jan 20, 2016

We have plans to move Action Resource configuration to XML files.

But agree that static might be a good quick improvement

Not applicable

Comment from brideo, posted on GitHub Jan 20, 2016

I'm happy to submit a pull request if this gets approved.

Not applicable

Comment from brideo, posted on GitHub Feb 16, 2016

I see the static binding has been added but the controllers weren't updated, I have done so in the following pull request:

https://github.com/magento/magento2/pull/3428