Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RequestValidator.php
Go to the documentation of this file.
1 <?php
8 
13 
18 {
22  private $request;
23 
27  private $router;
28 
32  private $storeManager;
33 
37  private $authorization;
38 
47  public function __construct(
48  RestRequest $request,
49  Router $router,
50  StoreManagerInterface $storeManager,
51  Authorization $authorization
52  ) {
53  $this->request = $request;
54  $this->router = $router;
55  $this->storeManager = $storeManager;
56  $this->authorization = $authorization;
57  }
58 
66  public function validate()
67  {
68  $this->checkPermissions();
69  $route = $this->router->match($this->request);
70  if ($route->isSecure() && !$this->request->isSecure()) {
71  throw new \Magento\Framework\Webapi\Exception(__('Operation allowed only in HTTPS'));
72  }
73  }
74 
81  private function checkPermissions()
82  {
83  $route = $this->router->match($this->request);
84  if (!$this->authorization->isAllowed($route->getAclResources())) {
85  $params = ['resources' => implode(', ', $route->getAclResources())];
86  throw new AuthorizationException(
87  __("The consumer isn't authorized to access %resources.", $params)
88  );
89  }
90  }
91 }
$storeManager
__()
Definition: __.php:13
__construct(RestRequest $request, Router $router, StoreManagerInterface $storeManager, Authorization $authorization)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18