Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdminConfig.php
Go to the documentation of this file.
1 <?php
9 
14 
20 class AdminConfig extends Config
21 {
25  const SESSION_NAME_ADMIN = 'admin';
26 
31 
35  private $backendAppList;
36 
40  private $backendUrlFactory;
41 
57  public function __construct(
58  \Magento\Framework\ValidatorFactory $validatorFactory,
59  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
60  \Magento\Framework\Stdlib\StringUtils $stringHelper,
64  $scopeType,
65  \Magento\Backend\App\BackendAppList $backendAppList,
66  FrontNameResolver $frontNameResolver,
67  \Magento\Backend\Model\UrlFactory $backendUrlFactory,
68  $lifetimePath = self::XML_PATH_COOKIE_LIFETIME,
69  $sessionName = self::SESSION_NAME_ADMIN
70  ) {
71  parent::__construct(
72  $validatorFactory,
73  $scopeConfig,
74  $stringHelper,
75  $request,
78  $scopeType,
80  );
81  $this->_frontNameResolver = $frontNameResolver;
82  $this->backendAppList = $backendAppList;
83  $this->backendUrlFactory = $backendUrlFactory;
84  $adminPath = $this->extractAdminPath();
85  $this->setCookiePath($adminPath);
86  $this->setName($sessionName);
87  $this->setCookieSecure($this->_httpRequest->isSecure());
88  }
89 
95  private function extractAdminPath()
96  {
97  $backendApp = $this->backendAppList->getCurrentApp();
98  $cookiePath = null;
99  $baseUrl = parse_url($this->backendUrlFactory->create()->getBaseUrl(), PHP_URL_PATH);
100  if (!$backendApp) {
101  $cookiePath = $baseUrl . $this->_frontNameResolver->getFrontName();
102  return $cookiePath;
103  }
104  //In case of application authenticating through the admin login, the script name should be removed
105  //from the path, because application has own script.
107  $cookiePath = $baseUrl . $backendApp->getCookiePath();
108  return $cookiePath;
109  }
110 
117  protected function configureCookieLifetime()
118  {
119  return $this->setCookieLifetime(0);
120  }
121 }
setCookiePath($cookiePath, $default=null)
Definition: Config.php:345
setName($name, $default=null)
Definition: Config.php:263
setCookieLifetime($cookieLifetime, $default=null)
Definition: Config.php:313
$deploymentConfig
setCookieSecure($cookieSecure)
Definition: Config.php:409
$filesystem
__construct(\Magento\Framework\ValidatorFactory $validatorFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\StringUtils $stringHelper, \Magento\Framework\App\RequestInterface $request, Filesystem $filesystem, DeploymentConfig $deploymentConfig, $scopeType, \Magento\Backend\App\BackendAppList $backendAppList, FrontNameResolver $frontNameResolver, \Magento\Backend\Model\UrlFactory $backendUrlFactory, $lifetimePath=self::XML_PATH_COOKIE_LIFETIME, $sessionName=self::SESSION_NAME_ADMIN)
Definition: AdminConfig.php:57