/** * Retrieve url of a view file * * @param string $fileId * @param array $params * @return string */ public function getViewFileUrl($fileId, array $params = []) { try { $params = array_merge(['_secure' => $this->_request->isSecure()], $params); return $this->_assetRepo->getUrlWithParams($fileId, $params); } catch (\Magento\Framework\Exception\LocalizedException $e) { return ''; } }
/** * Retrieve url of a view file * * @param string $fileId * @param array $params * @return string */ protected function getViewFileUrl($fileId, array $params = []) { try { $params = array_merge(['_secure' => $this->request->isSecure()], $params); return $this->assetRepo->getUrlWithParams($fileId, $params); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->logger->critical($e); return $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']); } }
/** * @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()); }
/** * Retrieve is secure mode URL * * @return bool */ protected function _isSecure() { if ($this->_request->isSecure()) { return true; } if ($this->getRouteParamsResolver()->hasData('secure_is_forced')) { return (bool) $this->getRouteParamsResolver()->getData('secure'); } if (!$this->_getScope()->isUrlSecure()) { return false; } if (!$this->getRouteParamsResolver()->hasData('secure')) { if ($this->_getType() == UrlInterface::URL_TYPE_LINK) { $pathSecure = $this->_urlSecurityInfo->isSecure('/' . $this->_getActionPath()); $this->getRouteParamsResolver()->setData('secure', $pathSecure); } elseif ($this->_getType() == UrlInterface::URL_TYPE_STATIC) { $isRequestSecure = $this->_getRequest()->isSecure(); $this->getRouteParamsResolver()->setData('secure', $isRequestSecure); } else { $this->getRouteParamsResolver()->setData('secure', true); } } return $this->getRouteParamsResolver()->getData('secure'); }
/** * Check that request uses https protocol if it should. * Function redirects user to correct URL if needed. * * @param \Magento\Framework\App\RequestInterface $request * @param string $path * @return void */ protected function _checkShouldBeSecure(\Magento\Framework\App\RequestInterface $request, $path = '') { if ($request->getPost()) { return; } if ($this->_shouldBeSecure($path) && !$request->isSecure()) { $url = $this->_getCurrentSecureUrl($request); if ($this->_shouldRedirectToSecure()) { $url = $this->_url->getRedirectUrl($url); } $this->_responseFactory->create()->setRedirect($url)->sendResponse(); exit; } }
/** * Check if request was secure * * @return boolean */ public function isCurrentlySecure() { if ($this->_request->isSecure()) { return true; } $secureBaseUrl = $this->_config->getValue(self::XML_PATH_SECURE_BASE_URL, ScopeInterface::SCOPE_STORE); $secureFrontend = $this->_config->getValue(self::XML_PATH_SECURE_IN_FRONTEND, ScopeInterface::SCOPE_STORE); if (!$secureBaseUrl || !$secureFrontend) { return false; } $uri = \Zend_Uri::factory($secureBaseUrl); $port = $uri->getPort(); $serverPort = $this->_request->getServer('SERVER_PORT'); $isSecure = $uri->getScheme() == 'https' && isset($serverPort) && $port == $serverPort; return $isSecure; }
/** * Retrieve save order url on front * * @return string */ protected function getSaveOrderUrl() { return $this->urlBuilder->getUrl('checkout/onepage/saveOrder', ['_secure' => $this->request->isSecure()]); }
/** * Return survey url * * @return string */ public function getSurveyUrl() { $host = $this->_request->isSecure() ? 'https://' : 'http://'; return $host . self::SURVEY_URL; }
/** * is payment method available? * * @param \Magento\Quote\Api\Data\CartInterface|null $quote * * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { $parent = parent::isAvailable($quote); if (!$this->_accessToken) { $this->_accessToken = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_ACCESS_TOKEN); } if (!$this->_publicKey) { $this->_publicKey = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_PUBLIC_KEY); } $custom = !empty($this->_publicKey) && !empty($this->_accessToken); if (!$parent || !$custom) { return false; } $debugMode = $this->_scopeConfig->getValue('payment/mercadopago/debug_mode'); $secure = $this->_request->isSecure(); if (!$secure && !$debugMode) { return false; } return $this->_helperData->isValidAccessToken($this->_accessToken); }
/** * Create a file asset that's subject of fallback system * * @param string $fileId * @param array $params * @return \Magento\Framework\View\Asset\File */ public function createAsset($fileId, array $params = []) { $params = array_merge(['_secure' => $this->request->isSecure()], $params); return $this->assetRepo->createAsset($fileId, $params); }
/** * Update secure value, set it to request setting if it has no explicit value assigned. * * @return void */ private function updateSecureValue() { if (null === $this->get(self::KEY_SECURE)) { $this->set(self::KEY_SECURE, $this->request->isSecure()); } }