Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
Http Class Reference
Inheritance diagram for Http:
Request RequestContentInterface RequestSafetyInterface HttpRequestInterface RequestInterface PlainTextRequestInterface Request Request Request

Public Member Functions

 __construct (CookieReaderInterface $cookieReader, StringUtils $converter, ConfigInterface $routeConfig, PathInfoProcessorInterface $pathInfoProcessor, ObjectManagerInterface $objectManager, $uri=null, $directFrontNames=[], PathInfo $pathInfoService=null)
 
 getOriginalPathInfo ()
 
 getPathInfo ()
 
 setPathInfo ($pathInfo=null)
 
 isDirectAccessFrontendName ($code)
 
 getBasePath ()
 
 getFrontName ()
 
 setRouteName ($route)
 
 getRouteName ()
 
 setControllerModule ($module)
 
 getControllerModule ()
 
 initForward ()
 
 getBeforeForwardInfo ($name=null)
 
 isAjax ()
 
 getDistroBaseUrl ()
 
 getFullActionName ($delimiter='_')
 
 __sleep ()
 
 isSafeMethod ()
 
- Public Member Functions inherited from Request
 __construct (CookieReaderInterface $cookieReader, StringUtils $converter, $uri=null)
 
 getModuleName ()
 
 setModuleName ($value)
 
 getControllerName ()
 
 setControllerName ($value)
 
 getActionName ()
 
 setActionName ($value)
 
 getPathInfo ()
 
 setPathInfo ($pathInfo=null)
 
 getRequestString ()
 
 getAlias ($name)
 
 setAlias ($name, $target)
 
 getParam ($key, $default=null)
 
 setParam ($key, $value)
 
 getParams ()
 
 setParams (array $array)
 
 clearParams ()
 
 getScheme ()
 
 setDispatched ($flag=true)
 
 isDispatched ()
 
 isSecure ()
 
 getCookie ($name=null, $default=null)
 
 getServerValue ($name=null, $default=null)
 
 getQueryValue ($name=null, $default=null)
 
 setQueryValue ($name, $value=null)
 
 getPostValue ($name=null, $default=null)
 
 setPostValue ($name, $value=null)
 
 __get ($key)
 
 get ($key)
 
 __isset ($key)
 
 has ($key)
 
 getHeader ($name, $default=false)
 
 getHttpHost ($trimPort=true)
 
 getClientIp ($checkProxy=true)
 
 getUserParams ()
 
 getUserParam ($key, $default=null)
 
 setRequestUri ($requestUri=null)
 
 getBaseUrl ()
 
 isForwarded ()
 
 setForwarded ($forwarded)
 
- Public Member Functions inherited from RequestInterface
 getModuleName ()
 
 setModuleName ($name)
 
 getActionName ()
 
 setActionName ($name)
 
 getParam ($key, $defaultValue=null)
 
 setParams (array $params)
 
 getParams ()
 
 getCookie ($name, $default)
 
 isSecure ()
 
- Public Member Functions inherited from PlainTextRequestInterface
 getContent ()
 
- Public Member Functions inherited from HttpRequestInterface
 isPost ()
 
 isGet ()
 
 isPatch ()
 
 isDelete ()
 
 isPut ()
 

Static Public Member Functions

static getDistroBaseUrlPath ($server)
 
static getUrlNoScript ($url)
 

Data Fields

const DEFAULT_HTTP_PORT = 80
 
const DEFAULT_HTTPS_PORT = 443
 
const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header'
 
- Data Fields inherited from Request
const SCHEME_HTTP = 'http'
 
const SCHEME_HTTPS = 'https'
 
const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header'
 

Protected Attributes

 $route
 
 $pathInfo = ''
 
 $originalPathInfo = ''
 
 $directFrontNames
 
 $controllerModule
 
 $beforeForwardInfo = []
 
 $routeConfig
 
 $pathInfoProcessor
 
 $objectManager
 
 $isSafeMethod = null
 
 $safeRequestTypes = ['GET', 'HEAD', 'TRACE', 'OPTIONS']
 
- Protected Attributes inherited from Request
 $module
 
 $controller
 
 $action
 
 $pathInfo = ''
 
 $requestString = ''
 
 $params = []
 
 $aliases = []
 
 $dispatched = false
 
 $forwarded
 
 $cookieReader
 
 $converter
 
 $appConfig
 
 $sslOffloadHeader
 

Additional Inherited Members

- Protected Member Functions inherited from Request
 immediateRequestSecure ()
 
 initialRequestSecure ($offLoaderHeader)
 

Detailed Description

Http request

Definition at line 20 of file Http.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( CookieReaderInterface  $cookieReader,
StringUtils  $converter,
ConfigInterface  $routeConfig,
PathInfoProcessorInterface  $pathInfoProcessor,
ObjectManagerInterface  $objectManager,
  $uri = null,
  $directFrontNames = [],
PathInfo  $pathInfoService = null 
)
Parameters
CookieReaderInterface$cookieReader
StringUtils$converter
ConfigInterface$routeConfig
PathInfoProcessorInterface$pathInfoProcessor
ObjectManagerInterface$objectManager
\Zend\Uri\UriInterface | string | null$uri
array$directFrontNames
PathInfo | null$pathInfoService

Definition at line 113 of file Http.php.

122  {
123  parent::__construct($cookieReader, $converter, $uri);
124  $this->routeConfig = $routeConfig;
125  $this->pathInfoProcessor = $pathInfoProcessor;
126  $this->objectManager = $objectManager;
127  $this->directFrontNames = $directFrontNames;
128  $this->pathInfoService = $pathInfoService ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
129  PathInfo::class
130  );
131  }

Member Function Documentation

◆ __sleep()

__sleep ( )

Sleep

Returns
array

Definition at line 416 of file Http.php.

417  {
418  return [];
419  }

◆ getBasePath()

getBasePath ( )

Get base path

Returns
string

Definition at line 199 of file Http.php.

200  {
201  $path = parent::getBasePath();
202  if (empty($path)) {
203  $path = '/';
204  } else {
205  $path = str_replace('\\', '/', $path);
206  }
207  return $path;
208  }

◆ getBeforeForwardInfo()

getBeforeForwardInfo (   $name = null)

Retrieve property's value which was before _forward call. If property was not changed during _forward call null will be returned. If passed name will be null whole state array will be returned.

Parameters
string$name
Returns
array|string|null

Definition at line 296 of file Http.php.

297  {
298  if ($name === null) {
300  } elseif (isset($this->beforeForwardInfo[$name])) {
301  return $this->beforeForwardInfo[$name];
302  }
303  return null;
304  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getControllerModule()

getControllerModule ( )

Get module name of currently used controller

Returns
string

Definition at line 264 of file Http.php.

265  {
267  }

◆ getDistroBaseUrl()

getDistroBaseUrl ( )

Get website instance base url

Returns
string

@SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 329 of file Http.php.

330  {
331  if ($this->distroBaseUrl) {
332  return $this->distroBaseUrl;
333  }
334  $headerHttpHost = $this->getServer('HTTP_HOST');
335  $headerHttpHost = $this->converter->cleanString($headerHttpHost);
336  $headerScriptName = $this->getServer('SCRIPT_NAME');
337 
338  if (isset($headerScriptName) && isset($headerHttpHost)) {
339  if ($secure = $this->isSecure()) {
340  $scheme = 'https://';
341  } else {
342  $scheme = 'http://';
343  }
344 
345  $hostArr = explode(':', $headerHttpHost);
346  $host = $hostArr[0];
347  $port = isset($hostArr[1])
348  && (!$secure && $hostArr[1] != 80 || $secure && $hostArr[1] != 443) ? ':' . $hostArr[1] : '';
349  $path = $this->getBasePath();
350 
351  return $this->distroBaseUrl = $scheme . $host . $port . rtrim($path, '/') . '/';
352  }
353  return 'http://localhost/';
354  }

◆ getDistroBaseUrlPath()

static getDistroBaseUrlPath (   $server)
static

Determines a base URL path from environment

Parameters
array$server
Returns
string

Definition at line 362 of file Http.php.

363  {
364  $result = '';
365  if (isset($server['SCRIPT_NAME'])) {
366  $envPath = str_replace('\\', '/', dirname(str_replace('\\', '/', $server['SCRIPT_NAME'])));
367  if ($envPath != '.' && $envPath != '/') {
368  $result = $envPath;
369  }
370  }
371  if (!preg_match('/\/$/', $result)) {
372  $result .= '/';
373  }
374  return $result;
375  }

◆ getFrontName()

getFrontName ( )

Retrieve request front name

Returns
string|null

Definition at line 215 of file Http.php.

216  {
217  $pathParts = explode('/', trim($this->getPathInfo(), '/'));
218  return reset($pathParts);
219  }

◆ getFullActionName()

getFullActionName (   $delimiter = '_')

Retrieve full action name

Parameters
string$delimiter
Returns
string

Definition at line 402 of file Http.php.

403  {
404  return $this->getRouteName() .
405  $delimiter .
406  $this->getControllerName() .
407  $delimiter .
408  $this->getActionName();
409  }

◆ getOriginalPathInfo()

getOriginalPathInfo ( )

Return the ORIGINAL_PATH_INFO. This value is calculated and processed from $_SERVER due to cross-platform differences. instead of reading PATH_INFO

Returns
string

Definition at line 140 of file Http.php.

141  {
142  if (empty($this->originalPathInfo)) {
143  $originalPathInfoFromRequest = $this->pathInfoService->getPathInfo(
144  $this->getRequestUri(),
145  $this->getBaseUrl()
146  );
147  $this->originalPathInfo = (string)$this->pathInfoProcessor->process($this, $originalPathInfoFromRequest);
148  $this->requestString = $this->originalPathInfo
149  . $this->pathInfoService->getQueryString($this->getRequestUri());
150  }
152  }

◆ getPathInfo()

getPathInfo ( )

Return the path info

Returns
string

Definition at line 159 of file Http.php.

160  {
161  if (empty($this->pathInfo)) {
162  $this->pathInfo = $this->getOriginalPathInfo();
163  }
164  return $this->pathInfo;
165  }

◆ getRouteName()

getRouteName ( )

Retrieve route name

Returns
string|null

Definition at line 242 of file Http.php.

243  {
244  return $this->route;
245  }

◆ getUrlNoScript()

static getUrlNoScript (   $url)
static

Return url with no script name

Parameters
string$url
Returns
string

Definition at line 383 of file Http.php.

384  {
385  if (!isset($_SERVER['SCRIPT_NAME'])) {
386  return $url;
387  }
388 
389  if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
390  $url = substr($url, 0, $pos);
391  }
392 
393  return $url;
394  }
$pos
Definition: list.phtml:42

◆ initForward()

initForward ( )

Collect properties changed by _forward in protected storage before _forward was called first time.

Returns
$this

Definition at line 274 of file Http.php.

275  {
276  if (empty($this->beforeForwardInfo)) {
277  $this->beforeForwardInfo = [
278  'params' => $this->getParams(),
279  'action_name' => $this->getActionName(),
280  'controller_name' => $this->getControllerName(),
281  'module_name' => $this->getModuleName(),
282  'route_name' => $this->getRouteName(),
283  ];
284  }
285  return $this;
286  }

◆ isAjax()

isAjax ( )

Check is Request from AJAX

Returns
boolean

Implements HttpRequestInterface.

Definition at line 311 of file Http.php.

312  {
313  if ($this->isXmlHttpRequest()) {
314  return true;
315  }
316  if ($this->getParam('ajax') || $this->getParam('isAjax')) {
317  return true;
318  }
319  return false;
320  }

◆ isDirectAccessFrontendName()

isDirectAccessFrontendName (   $code)

Check if code declared as direct access frontend name.

This means what this url can be used without store code.

Parameters
string$code
Returns
bool

Definition at line 189 of file Http.php.

190  {
191  return isset($this->directFrontNames[$code]);
192  }
$code
Definition: info.phtml:12

◆ isSafeMethod()

isSafeMethod ( )

Check that this is safe request

Returns
bool

Implements RequestSafetyInterface.

Definition at line 424 of file Http.php.

425  {
426  if ($this->isSafeMethod === null) {
427  if (isset($_SERVER['REQUEST_METHOD']) && (in_array($_SERVER['REQUEST_METHOD'], $this->safeRequestTypes))) {
428  $this->isSafeMethod = true;
429  } else {
430  $this->isSafeMethod = false;
431  }
432  }
433  return $this->isSafeMethod;
434  }

◆ setControllerModule()

setControllerModule (   $module)

Specify module name where was found currently used controller

Parameters
string$module
Returns
$this

Definition at line 253 of file Http.php.

254  {
255  $this->controllerModule = $module;
256  return $this;
257  }

◆ setPathInfo()

setPathInfo (   $pathInfo = null)

Set the PATH_INFO string.

Set the ORIGINAL_PATH_INFO string.

Parameters
string | null$pathInfo
Returns
$this

Definition at line 175 of file Http.php.

176  {
177  $this->pathInfo = (string)$pathInfo;
178  return $this;
179  }

◆ setRouteName()

setRouteName (   $route)

Set route name

Parameters
string$route
Returns
$this

Definition at line 227 of file Http.php.

228  {
229  $this->route = $route;
230  $module = $this->routeConfig->getRouteFrontName($route);
231  if ($module) {
232  $this->setModuleName($module);
233  }
234  return $this;
235  }

Field Documentation

◆ $beforeForwardInfo

$beforeForwardInfo = []
protected

Definition at line 66 of file Http.php.

◆ $controllerModule

$controllerModule
protected

Definition at line 59 of file Http.php.

◆ $directFrontNames

$directFrontNames
protected

Definition at line 54 of file Http.php.

◆ $isSafeMethod

$isSafeMethod = null
protected

Definition at line 86 of file Http.php.

◆ $objectManager

$objectManager
protected

Definition at line 81 of file Http.php.

◆ $originalPathInfo

$originalPathInfo = ''
protected

Definition at line 49 of file Http.php.

◆ $pathInfo

$pathInfo = ''
protected

Definition at line 42 of file Http.php.

◆ $pathInfoProcessor

$pathInfoProcessor
protected

Definition at line 76 of file Http.php.

◆ $route

$route
protected

Definition at line 35 of file Http.php.

◆ $routeConfig

$routeConfig
protected

Definition at line 71 of file Http.php.

◆ $safeRequestTypes

$safeRequestTypes = ['GET', 'HEAD', 'TRACE', 'OPTIONS']
protected

Definition at line 91 of file Http.php.

◆ DEFAULT_HTTP_PORT

const DEFAULT_HTTP_PORT = 80

#+ HTTP Ports

Definition at line 25 of file Http.php.

◆ DEFAULT_HTTPS_PORT

const DEFAULT_HTTPS_PORT = 443

Definition at line 26 of file Http.php.

◆ XML_PATH_OFFLOADER_HEADER

const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header'

#-

Definition at line 30 of file Http.php.


The documentation for this class was generated from the following file: