-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestedService.php
More file actions
108 lines (86 loc) · 2.84 KB
/
Copy pathRestedService.php
File metadata and controls
108 lines (86 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Rested\Bundle\RestedBundle;
use Rested\Bundle\RestedBundle\EventListener\KernelEventListener;
use Rested\Compiler\CompilerCacheInterface;
use Rested\FactoryInterface;
use Rested\Http\RequestParser;
use Rested\ResourceInterface;
use Rested\RestedResourceInterface;
use Rested\RestedServiceInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class RestedService implements RestedServiceInterface
{
/**
* @var \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
*/
private $authorizationChecker;
/**
* @var \Rested\Compiler\CompilerCacheInterface
*/
private $compilerCache;
/**
* @var \Rested\RequestContext[]
*/
private $contexts = [];
/**
* @var \Rested\FactoryInterface
*/
private $factory;
/**
* @var string[]
*/
private $resources = [];
public function __construct(FactoryInterface $factory, CompilerCacheInterface $compilerCache, AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
$this->compilerCache = $compilerCache;
$this->factory = $factory;
}
public function addResource($class)
{
$this->resources[] = $class;
}
public function execute($url, $method = 'get', $data = [], &$statusCode = null)
{
}
/**
* {@inheritdoc}
*/
public function findActionByRouteName($routeName)
{
$resourceDefinition = $this->compilerCache->findResourceDefinition($routeName);
if ($resourceDefinition !== null) {
return $resourceDefinition->findActionByRouteName($routeName);
}
return null;
}
public function getResources()
{
return $this->resources;
}
/**
* {@inheritdoc}
*/
public function resolveContextFromRequest(Request $request, ResourceInterface $resource)
{
$requestId = $request->headers->get(KernelEventListener::SUB_HEADER);
if (array_key_exists($requestId, $this->contexts) === true) {
return $this->contexts[$requestId];
}
$spec = $request->get('_rested');
$requestParser = new RequestParser();
$requestParser->parse($request->getRequestUri(), $request->query->all());
$cache = $this->compilerCache;
$cache->setAuthorizationChecker($this->authorizationChecker);
$factory = $this->factory;
$compiledResourceDefinition = $cache->findResourceDefinition($spec['route_name']);
$context = $factory->createContext(
$requestParser->getParameters(),
$spec['action'],
$spec['route_name'],
$compiledResourceDefinition
);
return ($this->contexts[$requestId] = $context);
}
}