Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Rest Class Reference
Inheritance diagram for Rest:
FrontControllerInterface

Public Member Functions

 __construct (RestRequest $request, RestResponse $response, Router $router, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\App\State $appState, Authorization $authorization, ServiceInputProcessor $serviceInputProcessor, ErrorProcessor $errorProcessor, PathProcessor $pathProcessor, \Magento\Framework\App\AreaList $areaList, ParamsOverrider $paramsOverrider, StoreManagerInterface $storeManager, RequestProcessorPool $requestProcessorPool)
 
 dispatch (\Magento\Framework\App\RequestInterface $request)
 
- Public Member Functions inherited from FrontControllerInterface
 dispatch (RequestInterface $request)
 

Data Fields

const SCHEMA_PATH = '/schema'
 

Protected Member Functions

 isSchemaRequest ()
 
 getCurrentRoute ()
 
 checkPermissions ()
 
 validateRequest ()
 

Protected Attributes

 $_router
 
 $_route
 
 $_request
 
 $_response
 
 $_objectManager
 
 $_appState
 
 $authorization
 
 $serviceInputProcessor
 
 $_errorProcessor
 
 $_pathProcessor
 
 $areaList
 
 $session
 
 $paramsOverrider
 
 $requestProcessorPool
 

Detailed Description

Front controller for WebAPI REST area.

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields)

Definition at line 31 of file Rest.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( RestRequest  $request,
RestResponse  $response,
Router  $router,
\Magento\Framework\ObjectManagerInterface  $objectManager,
\Magento\Framework\App\State  $appState,
Authorization  $authorization,
ServiceInputProcessor  $serviceInputProcessor,
ErrorProcessor  $errorProcessor,
PathProcessor  $pathProcessor,
\Magento\Framework\App\AreaList  $areaList,
ParamsOverrider  $paramsOverrider,
StoreManagerInterface  $storeManager,
RequestProcessorPool  $requestProcessorPool 
)

Initialize dependencies

Parameters
RestRequest$request
RestResponse$response
Router$router
\Magento\Framework\ObjectManagerInterface$objectManager
\Magento\Framework\App\State$appState
Authorization$authorization
ServiceInputProcessor$serviceInputProcessor
ErrorProcessor$errorProcessor
PathProcessor$pathProcessor
\Magento\Framework\App\AreaList$areaList
ParamsOverrider$paramsOverrider
StoreManagerInterface$storeManager
RequestProcessorPool$requestProcessorPoolTODO: Consider removal of warning suppression @SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 141 of file Rest.php.

155  {
156  $this->_router = $router;
157  $this->_request = $request;
158  $this->_response = $response;
159  $this->_objectManager = $objectManager;
160  $this->_appState = $appState;
161  $this->authorization = $authorization;
162  $this->serviceInputProcessor = $serviceInputProcessor;
163  $this->_errorProcessor = $errorProcessor;
164  $this->_pathProcessor = $pathProcessor;
165  $this->areaList = $areaList;
166  $this->paramsOverrider = $paramsOverrider;
167  $this->storeManager = $storeManager;
168  $this->requestProcessorPool = $requestProcessorPool;
169  }
$response
Definition: 404.php:11
$objectManager
Definition: bootstrap.php:17
$storeManager

Member Function Documentation

◆ checkPermissions()

checkPermissions ( )
protected

Perform authentication and authorization.

Exceptions

Definition at line 231 of file Rest.php.

232  {
233  $route = $this->getCurrentRoute();
234  if (!$this->authorization->isAllowed($route->getAclResources())) {
235  $params = ['resources' => implode(', ', $route->getAclResources())];
236  throw new AuthorizationException(
237  __("The consumer isn't authorized to access %resources.", $params)
238  );
239  }
240  }
__()
Definition: __.php:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ dispatch()

dispatch ( \Magento\Framework\App\RequestInterface  $request)

Handle REST request

Based on request decide is it schema request or API request and process accordingly. Throws Exception in case if cannot be processed properly.

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
\Magento\Framework\App\ResponseInterface

Definition at line 180 of file Rest.php.

181  {
182  $path = $this->_pathProcessor->process($request->getPathInfo());
183  $this->_request->setPathInfo($path);
184  $this->areaList->getArea($this->_appState->getAreaCode())
185  ->load(\Magento\Framework\App\Area::PART_TRANSLATE);
186  try {
187  $processor = $this->requestProcessorPool->getProcessor($this->_request);
188  $processor->process($this->_request);
189  } catch (\Exception $e) {
190  $maskedException = $this->_errorProcessor->maskException($e);
191  $this->_response->setException($maskedException);
192  }
193 
194  return $this->_response;
195  }
$processor
Definition: 404.php:10

◆ getCurrentRoute()

getCurrentRoute ( )
protected

Retrieve current route.

Returns
Route
Deprecated:
100.1.0
See also
\Magento\Webapi\Controller\Rest\InputParamsResolver::getRoute

Definition at line 214 of file Rest.php.

215  {
216  if (!$this->_route) {
217  $this->_route = $this->_router->match($this->_request);
218  }
219 
220  return $this->_route;
221  }

◆ isSchemaRequest()

isSchemaRequest ( )
protected

Check if current request is schema request.

Returns
bool

Definition at line 202 of file Rest.php.

203  {
204  return $this->_request->getPathInfo() === self::SCHEMA_PATH;
205  }

◆ validateRequest()

validateRequest ( )
protected

Validate request

Exceptions
AuthorizationException

Definition at line 251 of file Rest.php.

252  {
253  $this->checkPermissions();
254  if ($this->getCurrentRoute()->isSecure() && !$this->_request->isSecure()) {
255  throw new \Magento\Framework\Webapi\Exception(__('Operation allowed only in HTTPS'));
256  }
257  if ($this->storeManager->getStore()->getCode() === Store::ADMIN_CODE
258  && strtoupper($this->_request->getMethod()) === RestRequest::HTTP_METHOD_GET
259  ) {
260  throw new \Magento\Framework\Webapi\Exception(__('Cannot perform GET operation with store code \'all\''));
261  }
262  }
__()
Definition: __.php:13

Field Documentation

◆ $_appState

$_appState
protected

Definition at line 70 of file Rest.php.

◆ $_errorProcessor

$_errorProcessor
protected

Definition at line 87 of file Rest.php.

◆ $_objectManager

$_objectManager
protected

Definition at line 65 of file Rest.php.

◆ $_pathProcessor

$_pathProcessor
protected

Definition at line 92 of file Rest.php.

◆ $_request

$_request
protected

Definition at line 55 of file Rest.php.

◆ $_response

$_response
protected

Definition at line 60 of file Rest.php.

◆ $_route

$_route
protected

Definition at line 50 of file Rest.php.

◆ $_router

$_router
protected

Definition at line 44 of file Rest.php.

◆ $areaList

$areaList
protected

Definition at line 97 of file Rest.php.

◆ $authorization

$authorization
protected

Definition at line 76 of file Rest.php.

◆ $paramsOverrider

$paramsOverrider
protected

Definition at line 108 of file Rest.php.

◆ $requestProcessorPool

$requestProcessorPool
protected

Definition at line 113 of file Rest.php.

◆ $serviceInputProcessor

$serviceInputProcessor
protected

Definition at line 82 of file Rest.php.

◆ $session

$session
protected

Definition at line 102 of file Rest.php.

◆ SCHEMA_PATH

const SCHEMA_PATH = '/schema'

Path for accessing REST API schema

Deprecated:
100.3.0

Definition at line 38 of file Rest.php.


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