Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

RestProvider.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\CorsOptions;
8
9 use Nelmio\CorsBundle\Options\ProviderInterface;
10 use Symfony\Component\HttpFoundation\Request;
11 use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
12 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
13 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
14
20 class RestProvider implements ProviderInterface
21 {
23 protected $requestMatcher;
24
28 public function __construct(RequestMatcherInterface $requestMatcher)
29 {
30 $this->requestMatcher = $requestMatcher;
31 }
32
40 public function getOptions(Request $request)
41 {
42 $return = [];
43 if ($request->attributes->has('is_rest_request') && $request->attributes->get('is_rest_request') === true) {
44 $return['allow_methods'] = $this->getAllowedMethods($request->getPathInfo());
45 }
46
47 return $return;
48 }
49
50 protected function getAllowedMethods($uri)
51 {
52 try {
53 $route = $this->requestMatcher->matchRequest(
54 Request::create($uri, 'OPTIONS')
55 );
56 if (isset($route['allowedMethods'])) {
57 return explode(',', $route['allowedMethods']);
58 }
59 } catch (ResourceNotFoundException $e) {
60 // the provider doesn't care about a not found
61 } catch (MethodNotAllowedException $e) {
62 // neither does it care about a method not allowed
63 }
64
65 return [];
66 }
67 }
eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider
REST Cors Options provider.
Definition: RestProvider.php:21
eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider\$requestMatcher
$requestMatcher
Definition: RestProvider.php:23
eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider\getOptions
getOptions(Request $request)
Returns allowed CORS methods for a REST route.
Definition: RestProvider.php:40
eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider\__construct
__construct(RequestMatcherInterface $requestMatcher)
Definition: RestProvider.php:28
eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider\getAllowedMethods
getAllowedMethods($uri)
Definition: RestProvider.php:50
eZ\Bundle\EzPublishRestBundle\CorsOptions
Definition: RestProvider.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.