1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Saxulum\RestCrud\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
6
|
|
|
use JMS\Serializer\SerializerInterface; |
7
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
8
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
9
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
10
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
11
|
|
|
|
12
|
|
|
abstract class AbstractRestCrudController |
13
|
|
|
{ |
14
|
|
|
use RestCrudTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var AuthorizationCheckerInterface |
18
|
|
|
*/ |
19
|
|
|
protected $authorizationChecker; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ManagerRegistry |
23
|
|
|
*/ |
24
|
|
|
protected $doctrine; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var UrlGeneratorInterface |
28
|
|
|
*/ |
29
|
|
|
protected $urlGenerator; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var SerializerInterface |
33
|
|
|
*/ |
34
|
|
|
protected $serializer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var FormFactoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $formFactory; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var PaginatorInterface |
43
|
|
|
*/ |
44
|
|
|
protected $paginator; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param AuthorizationCheckerInterface $authorizationChecker |
48
|
|
|
* @param ManagerRegistry $doctrine |
49
|
|
|
* @param UrlGeneratorInterface $urlGenerator |
50
|
|
|
* @param SerializerInterface $serializer |
51
|
|
|
* @param FormFactoryInterface|null $formFactory |
52
|
|
|
* @param PaginatorInterface|null $paginator |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
AuthorizationCheckerInterface $authorizationChecker, |
56
|
|
|
ManagerRegistry $doctrine, |
57
|
|
|
UrlGeneratorInterface $urlGenerator, |
58
|
|
|
SerializerInterface $serializer, |
59
|
|
|
FormFactoryInterface $formFactory = null, |
60
|
|
|
PaginatorInterface $paginator = null |
61
|
|
|
) { |
62
|
|
|
$this->authorizationChecker = $authorizationChecker; |
63
|
|
|
$this->doctrine = $doctrine; |
64
|
|
|
$this->urlGenerator = $urlGenerator; |
65
|
|
|
$this->serializer = $serializer; |
66
|
|
|
$this->paginator = $paginator; |
67
|
|
|
$this->formFactory = $formFactory; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return AuthorizationCheckerInterface |
72
|
|
|
*/ |
73
|
|
|
protected function restCrudAuthorizationChecker() |
74
|
|
|
{ |
75
|
|
|
return $this->authorizationChecker; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return ManagerRegistry |
80
|
|
|
*/ |
81
|
|
|
protected function restCrudDoctrine() |
82
|
|
|
{ |
83
|
|
|
return $this->doctrine; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return UrlGeneratorInterface |
88
|
|
|
*/ |
89
|
|
|
protected function restCrudUrlGenerator() |
90
|
|
|
{ |
91
|
|
|
return $this->urlGenerator; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return SerializerInterface |
96
|
|
|
*/ |
97
|
|
|
protected function restCrudSerializer() |
98
|
|
|
{ |
99
|
|
|
return $this->serializer; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return PaginatorInterface |
104
|
|
|
*/ |
105
|
|
|
protected function restCrudPaginator() |
106
|
|
|
{ |
107
|
|
|
return $this->paginator; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return FormFactoryInterface |
112
|
|
|
*/ |
113
|
|
|
protected function restCrudFormFactory() |
114
|
|
|
{ |
115
|
|
|
return $this->formFactory; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|