/** * @param \Magento\Framework\ValidatorFactory $validatorFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\String $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param Filesystem $filesystem * @param DeploymentConfig $deploymentConfig * @param string $scopeType * @param string $lifetimePath * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __construct(\Magento\Framework\ValidatorFactory $validatorFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\String $stringHelper, \Magento\Framework\App\RequestInterface $request, Filesystem $filesystem, DeploymentConfig $deploymentConfig, $scopeType, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME) { $this->_validatorFactory = $validatorFactory; $this->_scopeConfig = $scopeConfig; $this->_stringHelper = $stringHelper; $this->_httpRequest = $request; $this->_scopeType = $scopeType; $saveMethod = $deploymentConfig->get(self::PARAM_SESSION_SAVE_METHOD, \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER); $savePath = $deploymentConfig->get(self::PARAM_SESSION_SAVE_PATH); $cacheLimiter = $deploymentConfig->get(self::PARAM_SESSION_CACHE_LIMITER); $this->setSaveHandler($saveMethod === 'db' ? 'user' : $saveMethod); if (!$savePath && !ini_get('session.save_path')) { $sessionDir = $filesystem->getDirectoryWrite(DirectoryList::SESSION); $savePath = $sessionDir->getAbsolutePath(); $sessionDir->create(); } if ($savePath) { $this->setSavePath($savePath); } if ($cacheLimiter) { $this->setOption('session.cache_limiter', $cacheLimiter); } $lifetime = $this->_scopeConfig->getValue($lifetimePath, $this->_scopeType); $this->setCookieLifetime($lifetime, self::COOKIE_LIFETIME_DEFAULT); $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); $path = empty($path) ? $this->_httpRequest->getBasePath() : $path; $this->setCookiePath($path, $this->_httpRequest->getBasePath()); $domain = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_DOMAIN, $this->_scopeType); $domain = empty($domain) ? $this->_httpRequest->getHttpHost() : $domain; $this->setCookieDomain((string) $domain, $this->_httpRequest->getHttpHost()); $this->setCookieHttpOnly($this->_scopeConfig->getValue(self::XML_PATH_COOKIE_HTTPONLY, $this->_scopeType)); }
/** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\String $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Framework\App\State $appState * @param \Magento\Framework\App\Filesystem $filesystem * @param string $scopeType * @param string $saveMethod * @param null|string $savePath * @param null|string $cacheLimiter * @param string $lifetimePath */ public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\String $stringHelper, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\App\State $appState, \Magento\Framework\App\Filesystem $filesystem, $scopeType, $saveMethod = \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER, $savePath = null, $cacheLimiter = null, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME) { $this->_scopeConfig = $scopeConfig; $this->_stringHelper = $stringHelper; $this->_httpRequest = $request; $this->_appState = $appState; $this->_filesystem = $filesystem; $this->_scopeType = $scopeType; $this->setSaveHandler($saveMethod === 'db' ? 'user' : $saveMethod); if (!$this->_appState->isInstalled() || !$savePath) { $savePath = $this->_filesystem->getPath('session'); } $this->setSavePath($savePath); if ($cacheLimiter) { $this->setOption('session.cache_limiter', $cacheLimiter); } $lifetime = $this->_scopeConfig->getValue($lifetimePath, $this->_scopeType); $lifetime = is_numeric($lifetime) ? $lifetime : self::COOKIE_LIFETIME_DEFAULT; $this->setCookieLifetime($lifetime); $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); if (empty($path)) { $path = $this->_httpRequest->getBasePath(); } $this->setCookiePath($path); $domain = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_DOMAIN, $this->_scopeType); $domain = empty($domain) ? $this->_httpRequest->getHttpHost() : $domain; $this->setCookieDomain((string) $domain); $this->setCookieHttpOnly($this->_scopeConfig->getValue(self::XML_PATH_COOKIE_HTTPONLY, $this->_scopeType)); }
/** * Get session.cookie_path * * @return string */ public function getCookiePath() { if (!$this->hasOption('session.cookie_path')) { $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); if (empty($path)) { $path = $this->_httpRequest->getBasePath(); } $this->setCookiePath($path); } return (string) $this->getOption('session.cookie_path'); }
/** * @param \Magento\Framework\ValidatorFactory $validatorFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\StringUtils $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param Filesystem $filesystem * @param DeploymentConfig $deploymentConfig * @param string $scopeType * @param string $lifetimePath * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __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, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME) { $this->_validatorFactory = $validatorFactory; $this->_scopeConfig = $scopeConfig; $this->_stringHelper = $stringHelper; $this->_httpRequest = $request; $this->_scopeType = $scopeType; /** * Session handler * * Save handler may be set to custom value in deployment config, which will override everything else. * Otherwise, try to read PHP settings for session.save_handler value. Otherwise, use 'files' as default. */ $defaultSaveHandler = $this->getStorageOption('session.save_handler') ?: SaveHandlerInterface::DEFAULT_HANDLER; $saveMethod = $deploymentConfig->get(self::PARAM_SESSION_SAVE_METHOD, $defaultSaveHandler); $saveMethod = $saveMethod === 'db' ? 'user' : $saveMethod; $this->setSaveHandler($saveMethod); /** * Session path */ $savePath = $deploymentConfig->get(self::PARAM_SESSION_SAVE_PATH); if (!$savePath && !ini_get('session.save_path')) { $sessionDir = $filesystem->getDirectoryWrite(DirectoryList::SESSION); $savePath = $sessionDir->getAbsolutePath(); $sessionDir->create(); } if ($savePath) { $this->setSavePath($savePath); } /** * Session cache limiter */ $cacheLimiter = $deploymentConfig->get(self::PARAM_SESSION_CACHE_LIMITER); if ($cacheLimiter) { $this->setOption('session.cache_limiter', $cacheLimiter); } /** * Cookie settings: lifetime, path, domain, httpOnly. These govern settings for the session cookie. */ $lifetime = $this->_scopeConfig->getValue($lifetimePath, $this->_scopeType); $this->setCookieLifetime($lifetime, self::COOKIE_LIFETIME_DEFAULT); $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); $path = empty($path) ? $this->_httpRequest->getBasePath() : $path; $this->setCookiePath($path, $this->_httpRequest->getBasePath()); $domain = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_DOMAIN, $this->_scopeType); $domain = empty($domain) ? $this->_httpRequest->getHttpHost() : $domain; $this->setCookieDomain((string) $domain, $this->_httpRequest->getHttpHost()); $this->setCookieHttpOnly($this->_scopeConfig->getValue(self::XML_PATH_COOKIE_HTTPONLY, $this->_scopeType)); }
/** * @param \Magento\Framework\ValidatorFactory $validatorFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\StringUtils $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param Filesystem $filesystem * @param DeploymentConfig $deploymentConfig * @param string $scopeType * @param string $lifetimePath * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __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, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME) { $this->_validatorFactory = $validatorFactory; $this->_scopeConfig = $scopeConfig; $this->_stringHelper = $stringHelper; $this->_httpRequest = $request; $this->_scopeType = $scopeType; $this->lifetimePath = $lifetimePath; /** * Session path */ $savePath = $deploymentConfig->get(self::PARAM_SESSION_SAVE_PATH); if (!$savePath && !ini_get('session.save_path')) { $sessionDir = $filesystem->getDirectoryWrite(DirectoryList::SESSION); $savePath = $sessionDir->getAbsolutePath(); $sessionDir->create(); } if ($savePath) { $this->setSavePath($savePath); } /** * Session cache limiter */ $cacheLimiter = $deploymentConfig->get(self::PARAM_SESSION_CACHE_LIMITER); if ($cacheLimiter) { $this->setOption('session.cache_limiter', $cacheLimiter); } /** * Cookie settings: lifetime, path, domain, httpOnly. These govern settings for the session cookie. */ $this->configureCookieLifetime(); $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); $path = empty($path) ? $this->_httpRequest->getBasePath() : $path; $this->setCookiePath($path, $this->_httpRequest->getBasePath()); $domain = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_DOMAIN, $this->_scopeType); $domain = empty($domain) ? $this->_httpRequest->getHttpHost() : $domain; $this->setCookieDomain((string) $domain, $this->_httpRequest->getHttpHost()); $this->setCookieHttpOnly($this->_scopeConfig->getValue(self::XML_PATH_COOKIE_HTTPONLY, $this->_scopeType)); $secureURL = $this->_scopeConfig->getValue('web/secure/base_url', $this->_scopeType); $unsecureURL = $this->_scopeConfig->getValue('web/unsecure/base_url', $this->_scopeType); $isFullySecuredURL = $secureURL == $unsecureURL; $this->setCookieSecure($isFullySecuredURL && $this->_httpRequest->isSecure()); }