|
1 |
| -snippet ld "Ladybug Dump" b |
2 |
| -ld($${1:var}); |
3 |
| -endsnippet |
4 |
| - |
5 |
| -snippet ldd "Ladybug Dump Die" b |
6 |
| -ldd($${1:var}); |
7 |
| -endsnippet |
8 |
| - |
9 | 1 | snippet atoum "atoum bootstrap" b
|
10 | 2 | $this
|
11 | 3 | ->given($this->newTestedInstance)
|
12 | 4 | ->then
|
13 | 5 | ->${1}
|
14 | 6 | ;
|
15 | 7 | endsnippet
|
16 |
| - |
17 |
| - |
18 |
| -snippet rest_controller "FOS Rest controller" b |
19 |
| -<?php |
20 |
| - |
21 |
| -namespace Mapado\TicketingBundle\Controller; |
22 |
| - |
23 |
| -use FOS\RestBundle\Controller\Annotations as Rest; |
24 |
| -use InvalidArgumentException; |
25 |
| -use Mapado\TicketingBundle\Entity\\${1:ClassName}; |
26 |
| -use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
27 |
| -use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
28 |
| -use Symfony\Component\HttpFoundation\Request; |
29 |
| -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
30 |
| - |
31 |
| -/** |
32 |
| - * Class $1Controller |
33 |
| - * @author Julien Deniau < [email protected]> |
34 |
| - * |
35 |
| - * @Rest\RouteResource("$1") |
36 |
| - */ |
37 |
| -class $1Controller extends FOSRestBaseController |
38 |
| -{ |
39 |
| - /** |
40 |
| - * cgetAction |
41 |
| - * |
42 |
| - * @access public |
43 |
| - * @return Response |
44 |
| - * |
45 |
| - * @ApiDoc( |
46 |
| - * resource=true, |
47 |
| - * section="$1", |
48 |
| - * description="Get a $1", |
49 |
| - * requirements={ |
50 |
| - * {"name"="id", "description"="$1 id", "dataType"="int"} |
51 |
| - * } |
52 |
| - * ) |
53 |
| - * |
54 |
| - * @Rest\Get("/${2:underscore_case}s", defaults={"_resource": "$1"}) |
55 |
| - * |
56 |
| - * @Rest\QueryParam(name="itemsPerPage", requirements="\d+", strict=true, nullable=true, description="Item count limit") |
57 |
| - * @Rest\QueryParam(name="page", requirements="\d+", strict=true, nullable=true, description="Page to fetch") |
58 |
| - * |
59 |
| - * @ParamConverter("page") |
60 |
| - * @ParamConverter("itemsPerPage") |
61 |
| - */ |
62 |
| - public function cgetAction(Request $request, $page, $itemsPerPage) |
63 |
| - { |
64 |
| - if (!$this->get('api_authorization_checker')->isGrantedAccess($request)) { |
65 |
| - throw $this->createAccessDeniedException('forbidden'); |
66 |
| - } |
67 |
| - |
68 |
| - $queryBuilder = $this->get('mapado_ticketing.repository.$2') |
69 |
| - ->createQueryBuilder('${3:qbAlias}'); |
70 |
| - |
71 |
| - $this->applyFilters($1::class, $queryBuilder, $request); |
72 |
| - |
73 |
| - $data = $this->getPaginatedData($queryBuilder, $itemsPerPage, $page); |
74 |
| - |
75 |
| - $view = $this->view($data); |
76 |
| - |
77 |
| - return $this->handleView($view); |
78 |
| - } |
79 |
| - |
80 |
| - /** |
81 |
| - * getAction |
82 |
| - * |
83 |
| - * @access public |
84 |
| - * @return Response |
85 |
| - * |
86 |
| - * @ApiDoc( |
87 |
| - * resource=true, |
88 |
| - * section="$1", |
89 |
| - * description="Get a $1", |
90 |
| - * requirements={ |
91 |
| - * {"name"="id", "description"="$1 id", "dataType"="int"} |
92 |
| - * } |
93 |
| - * ) |
94 |
| - * |
95 |
| - * @Rest\Get("/$2s/{id}", defaults={"_resource": "$1"}) |
96 |
| - * |
97 |
| - * @ParamConverter( |
98 |
| - * "${4:snakeCase}", |
99 |
| - * class="Mapado\TicketingBundle\Entity\\$1", |
100 |
| - * options={"mapping" = {"id" = "id"}, "entity_manager" = "default"} |
101 |
| - * ) |
102 |
| - */ |
103 |
| - public function getAction($1 $$4) |
104 |
| - { |
105 |
| - $view = $this->view($$4); |
106 |
| - |
107 |
| - return $this->handleView($view); |
108 |
| - } |
109 |
| - |
110 |
| - /** |
111 |
| - * putAction |
112 |
| - * |
113 |
| - * @access public |
114 |
| - * @return Response |
115 |
| - * |
116 |
| - * @ApiDoc( |
117 |
| - * resource=true, |
118 |
| - * section="$1", |
119 |
| - * description="Update a $1", |
120 |
| - * requirements={ |
121 |
| - * {"name"="id", "description"="$1 id", "dataType"="int"} |
122 |
| - * } |
123 |
| - * ) |
124 |
| - * |
125 |
| - * @Rest\Put("/$2s/{id}", defaults={"_resource": "$1"}) |
126 |
| - */ |
127 |
| - public function putAction() |
128 |
| - { |
129 |
| - try { |
130 |
| - $$4 = $this->get('mapado.json_ld_handler') |
131 |
| - ->deserializeFromRequest('Mapado\TicketingBundle\Entity\\$1'); |
132 |
| - } catch (InvalidArgumentException $e) { |
133 |
| - throw new BadRequestHttpException($e->getMessage(), $e); |
134 |
| - } |
135 |
| - |
136 |
| - if (!$this->get('api_authorization_checker')->isGrantedEdit($$4, $this->getUser())) { |
137 |
| - throw $this->createAccessDeniedException('forbidden'); |
138 |
| - } |
139 |
| - |
140 |
| - $this->get('doctrine.orm.entity_manager')->flush(); |
141 |
| - $view = $this->view($$4); |
142 |
| - |
143 |
| - return $this->handleView($view); |
144 |
| - } |
145 |
| - |
146 |
| - /** |
147 |
| - * postAction |
148 |
| - * |
149 |
| - * @access public |
150 |
| - * @return Response |
151 |
| - * |
152 |
| - * @ApiDoc( |
153 |
| - * resource=true, |
154 |
| - * section="$1", |
155 |
| - * description="Create a $1" |
156 |
| - * ) |
157 |
| - * |
158 |
| - * @Rest\Post("/$2s", defaults={"_resource": "$1"}) |
159 |
| - */ |
160 |
| - public function postAction() |
161 |
| - { |
162 |
| - try { |
163 |
| - $$4 = $this->get('mapado.json_ld_handler') |
164 |
| - ->deserializeFromRequest('Mapado\TicketingBundle\Entity\\$1'); |
165 |
| - } catch (InvalidArgumentException $e) { |
166 |
| - throw new BadRequestHttpException($e->getMessage(), $e); |
167 |
| - } |
168 |
| - |
169 |
| - if (!$this->get('api_authorization_checker')->isGrantedEdit($$4, $this->getUser())) { |
170 |
| - throw $this->createAccessDeniedException('forbidden'); |
171 |
| - } |
172 |
| - |
173 |
| - $entityManager = $this->get('doctrine.orm.entity_manager'); |
174 |
| - |
175 |
| - $entityManager->persist($$4); |
176 |
| - $entityManager->flush(); |
177 |
| - |
178 |
| - $view = $this->view($$4, 201); |
179 |
| - |
180 |
| - return $this->handleView($view); |
181 |
| - } |
182 |
| - |
183 |
| - /** |
184 |
| - * deleteAction |
185 |
| - * |
186 |
| - * @access public |
187 |
| - * @return Response |
188 |
| - * |
189 |
| - * @ApiDoc( |
190 |
| - * resource=true, |
191 |
| - * section="$1", |
192 |
| - * description="Delete a $1", |
193 |
| - * requirements={ |
194 |
| - * {"name"="id", "description"="$1 id", "dataType"="int"} |
195 |
| - * } |
196 |
| - * ) |
197 |
| - * |
198 |
| - * @Rest\Delete("/$2s/{id}", defaults={"_resource": "$1"}) |
199 |
| - * |
200 |
| - * @ParamConverter( |
201 |
| - * "$4", |
202 |
| - * class="Mapado\TicketingBundle\Entity\\$1", |
203 |
| - * options={"mapping" = {"id" = "id"}, "entity_manager" = "default"} |
204 |
| - * ) |
205 |
| - */ |
206 |
| - public function deleteAction($1 $$4) |
207 |
| - { |
208 |
| - if (!$this->get('api_authorization_checker')->isGrantedEdit($$4, $this->getUser())) { |
209 |
| - throw $this->createAccessDeniedException('forbidden'); |
210 |
| - } |
211 |
| - |
212 |
| - $entityManager = $this->get('doctrine.orm.entity_manager'); |
213 |
| - $entityManager->remove($$4); |
214 |
| - $entityManager->flush(); |
215 |
| - |
216 |
| - return $this->handleView($this->view(null, 204)); |
217 |
| - } |
218 |
| - ${5: |
219 |
| -
|
220 |
| - /** |
221 |
| - * getFilterList |
222 |
| - * |
223 |
| - * @access protected |
224 |
| - * @return array |
225 |
| - */ |
226 |
| - protected function getFilterList() : array |
227 |
| - { |
228 |
| - return []; |
229 |
| - } |
230 |
| - } |
231 |
| -} |
232 |
| -endsnippet |
0 commit comments