The way that helpers are instantiated (at least for the new Backend (~dev50) module) are via a helperFactory:
/**
* Return helper object
*
* @param string $name
* @return \Magento\Core\Helper\AbstractHelper
*/
public function helper($name)
{
return $this->_helperFactory->get($name);
}
Which is essentially just a specialized type of a model factory. E.g: Magento\Core\Block\Context line 143 (dev50) as part of the constructor:
\Magento\Core\Model\Factory\Helper $helperFactory
The helper factory will return the requested model based on the class name and ensure that it is an instanceof
the helper abstract class:
/**
* Get helper singleton
*
* @param string $className
* @param array $arguments
* @return \Magento\Core\Helper\AbstractHelper
* @throws \LogicException
*/
public function get($className, array $arguments = array())
{
$className = str_replace('_', '\\', $className);
/* Default helper class for a module */
if (strpos($className, '\Helper\\') === false) {
$className .= '\Helper\Data';
}
$helper = $this->_objectManager->get($className, $arguments);
if (false === ($helper instanceof \Magento\Core\Helper\AbstractHelper)) {
throw new \LogicException(
$className . ' doesn\'t extends Magento\App\Helper'
);
}
return $helper;
}
If you were to implement this yourself it seems Magento core is loading it in one of two ways:
Roll your own factory:
$objectManager = \Magento\Core\Model\ObjectManager::getInstance();
$helperFactory = $objectManager->get('\Magento\Core\Model\Factory\Helper');
$helper = $helperFactory->get('\PulseStorm\Commercebug\Helper\Data');
Or just grab it directly:
$helper = \Magento\Core\Model\ObjectManager::getInstance()->get('Magento\Core\Helper\Data');