123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\App\Helper;
- /**
- * Abstract helper
- *
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- */
- abstract class AbstractHelper
- {
- /**
- * Helper module name
- *
- * @var string
- */
- protected $_moduleName;
- /**
- * Request object
- *
- * @var \Magento\Framework\App\RequestInterface
- */
- protected $_request;
- /**
- * @var \Magento\Framework\Module\Manager
- */
- protected $_moduleManager;
- /**
- * @var \Psr\Log\LoggerInterface
- */
- protected $_logger;
- /**
- * @var \Magento\Framework\UrlInterface
- */
- protected $_urlBuilder;
- /**
- * @var \Magento\Framework\HTTP\Header
- */
- protected $_httpHeader;
- /**
- * Event manager
- *
- * @var \Magento\Framework\Event\ManagerInterface
- */
- protected $_eventManager;
- /**
- * @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress
- */
- protected $_remoteAddress;
- /**
- * @var \Magento\Framework\Url\EncoderInterface
- */
- protected $urlEncoder;
- /**
- * @var \Magento\Framework\Url\DecoderInterface
- */
- protected $urlDecoder;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $scopeConfig;
- /**
- * @var \Magento\Framework\Cache\ConfigInterface
- */
- protected $_cacheConfig;
- /**
- * @param Context $context
- */
- public function __construct(Context $context)
- {
- $this->_moduleManager = $context->getModuleManager();
- $this->_logger = $context->getLogger();
- $this->_request = $context->getRequest();
- $this->_urlBuilder = $context->getUrlBuilder();
- $this->_httpHeader = $context->getHttpHeader();
- $this->_eventManager = $context->getEventManager();
- $this->_remoteAddress = $context->getRemoteAddress();
- $this->_cacheConfig = $context->getCacheConfig();
- $this->urlEncoder = $context->getUrlEncoder();
- $this->urlDecoder = $context->getUrlDecoder();
- $this->scopeConfig = $context->getScopeConfig();
- }
- /**
- * Retrieve request object
- *
- * @return \Magento\Framework\App\RequestInterface
- */
- protected function _getRequest()
- {
- return $this->_request;
- }
- /**
- * Retrieve helper module name
- *
- * @return string
- */
- protected function _getModuleName()
- {
- if (!$this->_moduleName) {
- $class = get_class($this);
- $this->_moduleName = substr($class, 0, strpos($class, '\\Helper'));
- }
- return str_replace('\\', '_', $this->_moduleName);
- }
- /**
- * Check whether or not the module output is enabled in Configuration
- *
- * @param string $moduleName Full module name
- * @return boolean
- * use \Magento\Framework\Module\Manager::isOutputEnabled()
- */
- public function isModuleOutputEnabled($moduleName = null)
- {
- if ($moduleName === null) {
- $moduleName = $this->_getModuleName();
- }
- return $this->_moduleManager->isOutputEnabled($moduleName);
- }
- /**
- * Retrieve url
- *
- * @param string $route
- * @param array $params
- * @return string
- */
- protected function _getUrl($route, $params = [])
- {
- return $this->_urlBuilder->getUrl($route, $params);
- }
- }
|