-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractResource.php
More file actions
107 lines (90 loc) · 2.79 KB
/
Copy pathAbstractResource.php
File metadata and controls
107 lines (90 loc) · 2.79 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
<?php
namespace Rested\Bundle\RestedBundle;
use Rested\Definition\ActionDefinition;
use Rested\FactoryInterface;
use Rested\Resource;
use Rested\ResourceInterface;
use Rested\RestedServiceInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
abstract class AbstractResource implements ContainerAwareInterface, ResourceInterface
{
use Resource;
/**
* @var \Rested\FactoryInterface
*/
private $factory;
/**
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private $requestStack;
/**
* @var \Rested\RestedServiceInterface
*/
private $restedService;
/**
* @var \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
*/
private $tokenStorage;
public function export($instance, $allFields = false)
{
$action = $this->getCurrentAction();
$context = $this->getCurrentContext();
$transform = $action->getTransform();
// always export using the instance action
$transformMapping = $context
->getResourceDefinition()
->findFirstAction(ActionDefinition::TYPE_INSTANCE)
->getTransformMapping()
;
if ($allFields === true) {
return $transform->exportAll($context, $transformMapping, $instance);
} else {
return $transform->export($context, $transformMapping, $instance);
}
}
public function exportAll($instance)
{
return $this->export($instance, true);
}
/**
* {@inheritdoc}
*/
public function getAuthorizationChecker()
{
return $this->authorizationChecker;
}
/**
* {@inheritdoc}
*/
public function getCurrentRequest()
{
return $this->requestStack->getCurrentRequest();
}
public function getFactory()
{
return $this->factory;
}
/**
* {@inheritdoc}
*/
public function getRestedService()
{
return $this->restedService;
}
public function getUser()
{
return $this->tokenStorage->getToken()->getUser();
}
public function setContainer(ContainerInterface $container = null)
{
$this->authorizationChecker = $container->get('security.authorization_checker');
$this->factory = $container->get('rested.factory');
$this->requestStack = $container->get('request_stack');
$this->restedService = $container->get('rested');
$this->tokenStorage = $container->get('security.token_storage');
}
}