本文整理汇总了PHP中Magento\Framework\App\RequestInterface::getHttpHost方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHttpHost方法的具体用法?PHP RequestInterface::getHttpHost怎么用?PHP RequestInterface::getHttpHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHttpHost方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUris
/**
* Get cache servers' Uris
*
* @return Uri[]
*/
public function getUris()
{
$servers = [];
$configuredHosts = $this->config->get(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS);
if (null == $configuredHosts) {
$httpHost = $this->request->getHttpHost();
$servers[] = $httpHost ? UriFactory::factory('')->setHost($httpHost)->setPort(self::DEFAULT_PORT)->setScheme('http') : UriFactory::factory($this->urlBuilder->getUrl('*', ['_nosid' => true]))->setScheme('http')->setPath(null)->setQuery(null);
} else {
foreach ($configuredHosts as $host) {
$servers[] = UriFactory::factory('')->setHost($host['host'])->setPort(isset($host['port']) ? $host['port'] : self::DEFAULT_PORT)->setScheme('http');
}
}
return $servers;
}
示例2: __construct
/**
* @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(self::XML_PATH_COOKIE_LIFETIME, $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));
}
示例3: __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));
}
示例4: fetch
/**
* Make a http request and return response body
*
* @param string $url
* @return string
*/
protected function fetch($url)
{
$client = $this->httpClientFactory->create();
$client->setUri($url);
$client->setConfig(['maxredirects' => 5, 'timeout' => 30]);
$client->setParameterGet('domain', $this->request->getHttpHost());
return $client->request()->getBody();
}
示例5: getCurrentUrl
/**
* Retrieve current url
*
* @return string
*/
public function getCurrentUrl()
{
$port = $this->_request->getServer('SERVER_PORT');
if ($port) {
$defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
$port = in_array($port, $defaultPorts) ? '' : ':' . $port;
}
$requestUri = $this->_request->getServer('REQUEST_URI');
$url = $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $port . $requestUri;
return $url;
}
示例6: __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));
}
示例7: getCurrentUrl
/**
* Retrieve current url
*
* @return string
*/
public function getCurrentUrl()
{
$httpHostWithPort = $this->_request->getHttpHost(false);
$httpHostWithPort = explode(':', $httpHostWithPort);
$httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] : '';
$port = '';
if (isset($httpHostWithPort[1])) {
$defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
if (!in_array($httpHostWithPort[1], $defaultPorts)) {
/** Custom port */
$port = ':' . $httpHostWithPort[1];
}
}
return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getRequestUri();
}
示例8: __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());
}
示例9: validate
/**
* Validate module using curl request
*
* @return boolean|array
*/
public function validate()
{
if (!$this->canValidate()) {
return true;
}
$key = trim($this->module->getIdentityKey());
if (empty($key)) {
return ['error' => ['Identity key is required']];
}
// key format is: encoded_site:secret_key:optional_suffix
$parts = explode(':', $key);
if (count($parts) < 3) {
return ['error' => ['Identity key is not valid']];
}
list($site, $secret, $suffix) = explode(':', $key);
try {
$client = $this->httpClientFactory->create();
$client->setUri($this->getUrl($site));
$client->setConfig(['maxredirects' => 5, 'timeout' => 30]);
$client->setParameterGet('key', $secret);
$client->setParameterGet('suffix', $suffix);
$purchaseCode = $this->module->getRemote()->getPurchaseCode();
if (!$purchaseCode) {
$purchaseCode = $this->module->getCode();
}
$client->setParameterGet('module', $purchaseCode);
$client->setParameterGet('module_code', $this->module->getCode());
if ($this->module->getConfigSection()) {
$client->setParameterGet('config_section', $this->module->getConfigSection());
}
$client->setParameterGet('domain', $this->request->getHttpHost());
$response = $client->request();
$responseBody = $response->getBody();
} catch (\Exception $e) {
return ['error' => ['Response error: %1', $e->getMessage()], 'response' => $e->getTraceAsString()];
}
return $this->parseResponse($responseBody);
}
示例10: getRequestUrl
/**
* Compute the request Url from the Http request
*
* @param RequestInterface $httpRequest
* @return string
*/
public function getRequestUrl($httpRequest)
{
return $httpRequest->getScheme() . '://' . $httpRequest->getHttpHost(false) . $httpRequest->getRequestUri();
}