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

Public Member Functions

 __construct (CookieReaderInterface $cookieReader, StringUtils $converter, AreaList $areaList, ScopeInterface $configScope, $uri=null)
 
 getHeader ($header, $default=false)
 
 getRequestedServices ($default=null)
 
- Public Member Functions inherited from Http
 __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 ()
 

Data Fields

const REQUEST_PARAM_SERVICES = 'services'
 
const ALL_SERVICES = 'all'
 
- Data Fields inherited from Http
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 Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from Http
static getDistroBaseUrlPath ($server)
 
static getUrlNoScript ($url)
 
- Protected Attributes inherited from Http
 $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
 

Detailed Description

Definition at line 18 of file Request.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( CookieReaderInterface  $cookieReader,
StringUtils  $converter,
AreaList  $areaList,
ScopeInterface  $configScope,
  $uri = null 
)

Modify pathInfo: strip down the front name and query parameters.

Parameters
CookieReaderInterface$cookieReader
StringUtils$converter
AreaList$areaList
ScopeInterface$configScope
null | string$uri

Remove base url and area from path

Remove GET parameters from path

Definition at line 39 of file Request.php.

45  {
46  parent::__construct($cookieReader, $converter, $uri);
47 
48  $pathInfo = $this->getRequestUri();
50  $areaFrontName = $areaList->getFrontName($configScope->getCurrentScope());
51  $pathInfo = preg_replace("#.*?/{$areaFrontName}/?#", '/', $pathInfo);
53  $pathInfo = preg_replace('#\?.*#', '', $pathInfo);
54  $this->setPathInfo($pathInfo);
55  }
setPathInfo($pathInfo=null)
Definition: Http.php:175

Member Function Documentation

◆ _convertRequestParamToServiceArray()

_convertRequestParamToServiceArray (   $param)
protected

Extract the resources query param value and return associative array of the form 'resource' => 'version'

Parameters
string$parameg
 testModule1AllSoapAndRestV1,testModule2AllSoapNoRestV1 
Returns
string|array
 eg array (
     'testModule1AllSoapAndRestV1',
     'testModule2AllSoapNoRestV1',
     )
Exceptions

Definition at line 98 of file Request.php.

99  {
100  $serviceSeparator = ',';
101  $serviceVerPattern = "[a-zA-Z\d]*V[\d]+";
102  $regexp = "/^({$serviceVerPattern})([{$serviceSeparator}]{$serviceVerPattern})*\$/";
103  if ($param == 'all') {
104  return $param;
105  }
106  //Check if the $param is of valid format
107  if (empty($param) || !preg_match($regexp, $param)) {
108  $message = new Phrase('Incorrect format of request URI or Requested services are missing.');
109  throw new \Magento\Framework\Webapi\Exception($message);
110  }
111  //Split the $param string to create an array of 'service' => 'version'
112  $serviceVersionArray = explode($serviceSeparator, $param);
113  $serviceArray = [];
114  foreach ($serviceVersionArray as $service) {
115  $serviceArray[] = $service;
116  }
117  return $serviceArray;
118  }
$message

◆ getHeader()

getHeader (   $header,
  $default = false 
)

{}

Added CGI environment support.

Workaround for hhvm environment

Definition at line 62 of file Request.php.

63  {
64  $headerValue = parent::getHeader($header, $default);
65  if ($headerValue == false) {
67  $header = 'REDIRECT_HTTP_' . strtoupper(str_replace('-', '_', $header));
68  if (isset($_SERVER[$header])) {
69  $headerValue = $_SERVER[$header];
70  }
71  }
72  return $headerValue;
73  }

◆ getRequestedServices()

getRequestedServices (   $default = null)

Identify versions of resources that should be used for API configuration generation.

Parameters
string | null$default
Returns
array|string
Exceptions

Definition at line 82 of file Request.php.

83  {
84  $param = $this->getParam(self::REQUEST_PARAM_SERVICES, $default);
85  return $this->_convertRequestParamToServiceArray($param);
86  }
getParam($key, $defaultValue=null)
_convertRequestParamToServiceArray($param)
Definition: Request.php:98

Field Documentation

◆ ALL_SERVICES

const ALL_SERVICES = 'all'

services parameter value to indicate that a schema for all services should be generated

Definition at line 28 of file Request.php.

◆ REQUEST_PARAM_SERVICES

const REQUEST_PARAM_SERVICES = 'services'

Name of query parameter to specify services for which to generate schema

Definition at line 23 of file Request.php.


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