本文整理汇总了PHP中Magento\Framework\App\RequestInterface::getBasePath方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getBasePath方法的具体用法?PHP RequestInterface::getBasePath怎么用?PHP RequestInterface::getBasePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getBasePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @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));
}
示例2: getCookiePath
/**
* 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');
}
示例3: __construct
/**
* @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));
}
示例4: __construct
/**
* @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());
}