@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | $cacheKey = urlencode($this->generateCacheKey($subscriber).implode('_', $filters)); |
66 | 66 | |
67 | 67 | return $this->cacheProvider->get($cacheKey, function (ItemInterface $item) use ($subscriber, $filters) { |
68 | - $item->expiresAfter($this->cacheLifeTime); |
|
69 | - return $this->decoratedProvider->getSubscriptions($subscriber, $filters); |
|
68 | + $item->expiresAfter($this->cacheLifeTime); |
|
69 | + return $this->decoratedProvider->getSubscriptions($subscriber, $filters); |
|
70 | 70 | }); |
71 | 71 | } |
72 | 72 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | { |
75 | 75 | $cacheKey = urlencode($this->generateCacheKey($subscriber, self::CACHE_KEY_VALID).implode('_', $filters)); |
76 | 76 | return $this->cacheProvider->get($cacheKey, function (ItemInterface $item) use ($subscriber, $filters) { |
77 | - $item->expiresAfter($this->cacheLifeTime); |
|
78 | - return $this->decoratedProvider->getSubscription($subscriber, $filters); |
|
77 | + $item->expiresAfter($this->cacheLifeTime); |
|
78 | + return $this->decoratedProvider->getSubscription($subscriber, $filters); |
|
79 | 79 | }); |
80 | 80 | } |
81 | 81 |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | $cacheKey = urlencode($this->generateCacheKey($subscriber).implode('_', $filters)); |
66 | 66 | |
67 | - return $this->cacheProvider->get($cacheKey, function (ItemInterface $item) use ($subscriber, $filters) { |
|
67 | + return $this->cacheProvider->get($cacheKey, function(ItemInterface $item) use ($subscriber, $filters) { |
|
68 | 68 | $item->expiresAfter($this->cacheLifeTime); |
69 | 69 | return $this->decoratedProvider->getSubscriptions($subscriber, $filters); |
70 | 70 | }); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function getSubscription(SubscriberInterface $subscriber, array $filters = []): ?SubscriptionInterface |
74 | 74 | { |
75 | 75 | $cacheKey = urlencode($this->generateCacheKey($subscriber, self::CACHE_KEY_VALID).implode('_', $filters)); |
76 | - return $this->cacheProvider->get($cacheKey, function (ItemInterface $item) use ($subscriber, $filters) { |
|
76 | + return $this->cacheProvider->get($cacheKey, function(ItemInterface $item) use ($subscriber, $filters) { |
|
77 | 77 | $item->expiresAfter($this->cacheLifeTime); |
78 | 78 | return $this->decoratedProvider->getSubscription($subscriber, $filters); |
79 | 79 | }); |
@@ -39,18 +39,18 @@ |
||
39 | 39 | /** @var OrganizationFactoryInterface */ |
40 | 40 | private $organizationFactory; |
41 | 41 | |
42 | - /** |
|
43 | - * @param OrganizationRepositoryInterface $organizationRepository |
|
44 | - * @param OrganizationFactoryInterface $organizationFactory |
|
45 | - */ |
|
46 | - public function __construct( OrganizationRepositoryInterface $organizationRepository, OrganizationFactoryInterface $organizationFactory) { |
|
42 | + /** |
|
43 | + * @param OrganizationRepositoryInterface $organizationRepository |
|
44 | + * @param OrganizationFactoryInterface $organizationFactory |
|
45 | + */ |
|
46 | + public function __construct( OrganizationRepositoryInterface $organizationRepository, OrganizationFactoryInterface $organizationFactory) { |
|
47 | 47 | $this->organizationRepository = $organizationRepository; |
48 | 48 | $this->organizationFactory = $organizationFactory; |
49 | 49 | parent::__construct(); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
53 | + /** |
|
54 | 54 | * {@inheritdoc} |
55 | 55 | */ |
56 | 56 | protected function configure() |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param OrganizationRepositoryInterface $organizationRepository |
44 | 44 | * @param OrganizationFactoryInterface $organizationFactory |
45 | 45 | */ |
46 | - public function __construct( OrganizationRepositoryInterface $organizationRepository, OrganizationFactoryInterface $organizationFactory) { |
|
46 | + public function __construct(OrganizationRepositoryInterface $organizationRepository, OrganizationFactoryInterface $organizationFactory) { |
|
47 | 47 | $this->organizationRepository = $organizationRepository; |
48 | 48 | $this->organizationFactory = $organizationFactory; |
49 | 49 | parent::__construct(); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | if (!$input->getArgument($name)) { |
128 | 128 | $question = new Question(sprintf('<question>Please enter %s:</question>', $name)); |
129 | - $question->setValidator(function ($argument) use ($name) { |
|
129 | + $question->setValidator(function($argument) use ($name) { |
|
130 | 130 | if (empty($argument)) { |
131 | 131 | throw new \RuntimeException(sprintf('The %s can not be empty', $name)); |
132 | 132 | } |
@@ -123,8 +123,8 @@ |
||
123 | 123 | |
124 | 124 | $subEvent = new ControllerEvent($event->getKernel(), $controller, $stubRequest, HttpKernelInterface::SUB_REQUEST); |
125 | 125 | $kernelSubEvent = new RequestEvent($event->getKernel(), $stubRequest, HttpKernelInterface::SUB_REQUEST); |
126 | - $dispatcher->dispatch( $kernelSubEvent, KernelEvents::REQUEST); |
|
127 | - $dispatcher->dispatch( $subEvent, KernelEvents::CONTROLLER); |
|
126 | + $dispatcher->dispatch($kernelSubEvent, KernelEvents::REQUEST); |
|
127 | + $dispatcher->dispatch($subEvent, KernelEvents::CONTROLLER); |
|
128 | 128 | $controller = $subEvent->getController(); |
129 | 129 | |
130 | 130 | $argumentResolver = new ArgumentResolver(); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $paginationData = new PaginationData(); |
152 | 152 | } |
153 | 153 | |
154 | - return $this->getPaginator($eventDispatcher,$queryBuilder, $paginationData); |
|
154 | + return $this->getPaginator($eventDispatcher, $queryBuilder, $paginationData); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | ->leftJoin('a.extraEmbedFields', 'eef'); |
173 | 173 | |
174 | 174 | foreach ((array) $criteria->get('extra') as $key => $value) { |
175 | - if(is_array($value)) { |
|
175 | + if (is_array($value)) { |
|
176 | 176 | $andX = $queryBuilder->expr()->andX(); |
177 | 177 | $andX->add($queryBuilder->expr()->eq('eef.fieldName', $queryBuilder->expr()->literal($key))); |
178 | 178 | $andX->add($queryBuilder->expr()->eq('eef.embed', $queryBuilder->expr()->literal($value['embed']))); |
@@ -61,7 +61,7 @@ |
||
61 | 61 | $paginationData = new PaginationData(); |
62 | 62 | } |
63 | 63 | |
64 | - return $this->getPaginator($eventDispatcher,$queryBuilder, $paginationData); |
|
64 | + return $this->getPaginator($eventDispatcher, $queryBuilder, $paginationData); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | private function applyCustomCriteria(QueryBuilder $queryBuilder, Criteria $criteria): void |
@@ -27,32 +27,32 @@ |
||
27 | 27 | |
28 | 28 | class AuthorController extends AbstractController { |
29 | 29 | |
30 | - private ArticleAuthorRepositoryInterface $articleAuthorRepository; // swp.repository.author |
|
30 | + private ArticleAuthorRepositoryInterface $articleAuthorRepository; // swp.repository.author |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param ArticleAuthorRepositoryInterface $articleAuthorRepository |
|
34 | - */ |
|
35 | - public function __construct(ArticleAuthorRepositoryInterface $articleAuthorRepository) { |
|
32 | + /** |
|
33 | + * @param ArticleAuthorRepositoryInterface $articleAuthorRepository |
|
34 | + */ |
|
35 | + public function __construct(ArticleAuthorRepositoryInterface $articleAuthorRepository) { |
|
36 | 36 | $this->articleAuthorRepository = $articleAuthorRepository; |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @Route("/api/{version}/authors/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_author", requirements={"id"="\d+"}) |
|
41 | - */ |
|
42 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
39 | + /** |
|
40 | + * @Route("/api/{version}/authors/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_author", requirements={"id"="\d+"}) |
|
41 | + */ |
|
42 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
43 | 43 | $authorRepository = $this->articleAuthorRepository; |
44 | 44 | $author = $this->findOr404($id); |
45 | 45 | |
46 | 46 | $authorRepository->remove($author); |
47 | 47 | |
48 | 48 | return new SingleResourceResponse(null, new ResponseContext(204)); |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - private function findOr404(int $id): ArticleAuthorInterface { |
|
51 | + private function findOr404(int $id): ArticleAuthorInterface { |
|
52 | 52 | if (null === $author = $this->articleAuthorRepository->findOneById($id)) { |
53 | - throw new NotFoundHttpException('Author was not found.'); |
|
53 | + throw new NotFoundHttpException('Author was not found.'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $author; |
57 | - } |
|
57 | + } |
|
58 | 58 | } |
@@ -42,31 +42,31 @@ discard block |
||
42 | 42 | |
43 | 43 | class RouteController extends FOSRestController { |
44 | 44 | |
45 | - private FormFactoryInterface $formFactory; |
|
46 | - private EventDispatcherInterface $eventDispatcher; |
|
47 | - private RouteProviderInterface $routeProvider; // swp.provider.route |
|
48 | - private RouteRepositoryInterface $routeRepository; // swp.repository.route |
|
49 | - private RouteServiceInterface $routeService; // swp.service.route |
|
50 | - private RouteFactoryInterface $routeFactory; // swp.factory.route |
|
51 | - private KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory; //swp_pagination_rep |
|
52 | - private EntityManagerInterface $entityManager; // swp.object_manager.route |
|
53 | - |
|
54 | - /** |
|
55 | - * @param FormFactoryInterface $formFactory |
|
56 | - * @param EventDispatcherInterface $eventDispatcher |
|
57 | - * @param RouteProviderInterface $routeProvider |
|
58 | - * @param RouteRepositoryInterface $routeRepository |
|
59 | - * @param RouteServiceInterface $routeService |
|
60 | - * @param RouteFactoryInterface $routeFactory |
|
61 | - * @param KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory |
|
62 | - * @param EntityManagerInterface $entityManager |
|
63 | - */ |
|
64 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
65 | - RouteProviderInterface $routeProvider, |
|
66 | - RouteRepositoryInterface $routeRepository, RouteServiceInterface $routeService, |
|
67 | - RouteFactoryInterface $routeFactory, |
|
68 | - KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory, |
|
69 | - EntityManagerInterface $entityManager) { |
|
45 | + private FormFactoryInterface $formFactory; |
|
46 | + private EventDispatcherInterface $eventDispatcher; |
|
47 | + private RouteProviderInterface $routeProvider; // swp.provider.route |
|
48 | + private RouteRepositoryInterface $routeRepository; // swp.repository.route |
|
49 | + private RouteServiceInterface $routeService; // swp.service.route |
|
50 | + private RouteFactoryInterface $routeFactory; // swp.factory.route |
|
51 | + private KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory; //swp_pagination_rep |
|
52 | + private EntityManagerInterface $entityManager; // swp.object_manager.route |
|
53 | + |
|
54 | + /** |
|
55 | + * @param FormFactoryInterface $formFactory |
|
56 | + * @param EventDispatcherInterface $eventDispatcher |
|
57 | + * @param RouteProviderInterface $routeProvider |
|
58 | + * @param RouteRepositoryInterface $routeRepository |
|
59 | + * @param RouteServiceInterface $routeService |
|
60 | + * @param RouteFactoryInterface $routeFactory |
|
61 | + * @param KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory |
|
62 | + * @param EntityManagerInterface $entityManager |
|
63 | + */ |
|
64 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
65 | + RouteProviderInterface $routeProvider, |
|
66 | + RouteRepositoryInterface $routeRepository, RouteServiceInterface $routeService, |
|
67 | + RouteFactoryInterface $routeFactory, |
|
68 | + KnpPaginatorRepresentationFactory $knpPaginatorRepresentationFactory, |
|
69 | + EntityManagerInterface $entityManager) { |
|
70 | 70 | $this->formFactory = $formFactory; |
71 | 71 | $this->eventDispatcher = $eventDispatcher; |
72 | 72 | $this->routeProvider = $routeProvider; |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | $this->routeFactory = $routeFactory; |
76 | 76 | $this->knpPaginatorRepresentationFactory = $knpPaginatorRepresentationFactory; |
77 | 77 | $this->entityManager = $entityManager; |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * @Route("/api/{version}/content/routes/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_routes") |
|
83 | - */ |
|
84 | - public function listAction(Request $request) { |
|
81 | + /** |
|
82 | + * @Route("/api/{version}/content/routes/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_routes") |
|
83 | + */ |
|
84 | + public function listAction(Request $request) { |
|
85 | 85 | $routeRepository = $this->routeRepository; |
86 | 86 | |
87 | 87 | $routes = $routeRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria([ |
@@ -89,28 +89,28 @@ discard block |
||
89 | 89 | ]), $request->query->all('sorting'), new PaginationData($request)); |
90 | 90 | |
91 | 91 | return $this->handleView(View::create($this->knpPaginatorRepresentationFactory->createRepresentation($routes, $request), 200)); |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @Route("/api/{version}/content/routes/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_routes", requirements={"id"=".+"}) |
|
96 | - */ |
|
97 | - public function getAction($id) { |
|
94 | + /** |
|
95 | + * @Route("/api/{version}/content/routes/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_routes", requirements={"id"=".+"}) |
|
96 | + */ |
|
97 | + public function getAction($id) { |
|
98 | 98 | return new SingleResourceResponse($this->findOr404($id)); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @Route("/api/{version}/content/routes/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_routes", requirements={"id"=".+"}) |
|
103 | - */ |
|
104 | - public function deleteAction(int $id): Response { |
|
101 | + /** |
|
102 | + * @Route("/api/{version}/content/routes/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_routes", requirements={"id"=".+"}) |
|
103 | + */ |
|
104 | + public function deleteAction(int $id): Response { |
|
105 | 105 | $repository = $this->routeRepository; |
106 | 106 | $route = $this->findOr404($id); |
107 | 107 | |
108 | 108 | if (null !== $route->getContent()) { |
109 | - throw new ConflictHttpException('Route has content attached to it.'); |
|
109 | + throw new ConflictHttpException('Route has content attached to it.'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | if (0 < $route->getChildren()->count()) { |
113 | - throw new ConflictHttpException('Remove route children before removing this route.'); |
|
113 | + throw new ConflictHttpException('Remove route children before removing this route.'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $eventDispatcher = $this->eventDispatcher; |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $eventDispatcher->dispatch(new RouteEvent($route, RouteEvents::POST_DELETE), RouteEvents::POST_DELETE); |
120 | 120 | |
121 | 121 | return $this->handleView(View::create(true, 204)); |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @Route("/api/{version}/content/routes/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_create_routes") |
|
126 | - */ |
|
127 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
124 | + /** |
|
125 | + * @Route("/api/{version}/content/routes/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_create_routes") |
|
126 | + */ |
|
127 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
128 | 128 | /** @var RouteInterface $route */ |
129 | 129 | $route = $this->routeFactory->create(); |
130 | 130 | $form = $this->formFactory->createNamed('', RouteType::class, $route, ['method' => $request->getMethod()]); |
@@ -133,20 +133,20 @@ discard block |
||
133 | 133 | $this->ensureRouteExists($route->getName()); |
134 | 134 | |
135 | 135 | if ($form->isSubmitted() && $form->isValid()) { |
136 | - $route = $this->routeService->createRoute($form->getData()); |
|
136 | + $route = $this->routeService->createRoute($form->getData()); |
|
137 | 137 | |
138 | - $this->routeRepository->add($route); |
|
138 | + $this->routeRepository->add($route); |
|
139 | 139 | |
140 | - return new SingleResourceResponse($route, new ResponseContext(201)); |
|
140 | + return new SingleResourceResponse($route, new ResponseContext(201)); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return new SingleResourceResponse($form, new ResponseContext(400)); |
144 | - } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @Route("/api/{version}/content/routes/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_routes", requirements={"id"=".+"}) |
|
148 | - */ |
|
149 | - public function updateAction(Request $request, $id): Response { |
|
146 | + /** |
|
147 | + * @Route("/api/{version}/content/routes/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_routes", requirements={"id"=".+"}) |
|
148 | + */ |
|
149 | + public function updateAction(Request $request, $id): Response { |
|
150 | 150 | $objectManager = $this->entityManager; |
151 | 151 | $route = $this->findOr404($id); |
152 | 152 | $previousRoute = clone $route; |
@@ -154,27 +154,27 @@ discard block |
||
154 | 154 | $form->handleRequest($request); |
155 | 155 | |
156 | 156 | if ($form->isSubmitted() && $form->isValid()) { |
157 | - $route = $this->routeService->updateRoute($previousRoute, $form->getData()); |
|
157 | + $route = $this->routeService->updateRoute($previousRoute, $form->getData()); |
|
158 | 158 | |
159 | - $objectManager->flush(); |
|
159 | + $objectManager->flush(); |
|
160 | 160 | |
161 | - return $this->handleView(View::create($route, 200)); |
|
161 | + return $this->handleView(View::create($route, 200)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return $this->handleView(View::create($form, 400)); |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - private function findOr404($id) { |
|
167 | + private function findOr404($id) { |
|
168 | 168 | if (null === $route = $this->routeProvider->getOneById($id)) { |
169 | - throw new NotFoundHttpException('Route was not found.'); |
|
169 | + throw new NotFoundHttpException('Route was not found.'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | return $route; |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - private function ensureRouteExists($name) { |
|
175 | + private function ensureRouteExists($name) { |
|
176 | 176 | if (null !== $this->routeRepository->findOneByName($name)) { |
177 | - throw new ConflictHttpException(sprintf('Route "%s" already exists!', $name)); |
|
177 | + throw new ConflictHttpException(sprintf('Route "%s" already exists!', $name)); |
|
178 | + } |
|
178 | 179 | } |
179 | - } |
|
180 | 180 | } |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | use Symfony\Component\HttpFoundation\Request; |
29 | 29 | |
30 | 30 | class RelatedArticleController extends AbstractController { |
31 | - private RelatedArticleRepositoryInterface $relatedArticleRepository; |
|
32 | - private ArticleProviderInterface $articleProvider; |
|
33 | - private EventDispatcherInterface $eventDispatcher; |
|
31 | + private RelatedArticleRepositoryInterface $relatedArticleRepository; |
|
32 | + private ArticleProviderInterface $articleProvider; |
|
33 | + private EventDispatcherInterface $eventDispatcher; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param RelatedArticleRepositoryInterface $relatedArticleRepository |
|
37 | - * @param ArticleProviderInterface $articleProvider |
|
38 | - * @param EventDispatcherInterface $eventDispatcher |
|
39 | - */ |
|
40 | - public function __construct(RelatedArticleRepositoryInterface $relatedArticleRepository, |
|
41 | - ArticleProviderInterface $articleProvider, |
|
42 | - EventDispatcherInterface $eventDispatcher) { |
|
35 | + /** |
|
36 | + * @param RelatedArticleRepositoryInterface $relatedArticleRepository |
|
37 | + * @param ArticleProviderInterface $articleProvider |
|
38 | + * @param EventDispatcherInterface $eventDispatcher |
|
39 | + */ |
|
40 | + public function __construct(RelatedArticleRepositoryInterface $relatedArticleRepository, |
|
41 | + ArticleProviderInterface $articleProvider, |
|
42 | + EventDispatcherInterface $eventDispatcher) { |
|
43 | 43 | $this->relatedArticleRepository = $relatedArticleRepository; |
44 | 44 | $this->articleProvider = $articleProvider; |
45 | 45 | $this->eventDispatcher = $eventDispatcher; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - public function listAction(Request $request, string $id) { |
|
49 | + public function listAction(Request $request, string $id) { |
|
50 | 50 | $article = $this->findOr404($id); |
51 | 51 | |
52 | 52 | $repository = $this->relatedArticleRepository; |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | ); |
62 | 62 | |
63 | 63 | return new ResourcesListResponse($items); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - private function findOr404(string $id): ArticleInterface { |
|
66 | + private function findOr404(string $id): ArticleInterface { |
|
67 | 67 | $article = $this->articleProvider->getOneById($id); |
68 | 68 | |
69 | 69 | if (null === $article) { |
70 | - throw new NotFoundHttpException(sprintf('Article "%s" was not found.', $id)); |
|
70 | + throw new NotFoundHttpException(sprintf('Article "%s" was not found.', $id)); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $article; |
74 | - } |
|
74 | + } |
|
75 | 75 | } |
@@ -36,27 +36,27 @@ discard block |
||
36 | 36 | |
37 | 37 | class ArticleController extends AbstractController { |
38 | 38 | |
39 | - private FormFactoryInterface $formFactory; |
|
40 | - private RouteProviderInterface $routeProvider; // swp.provider.route |
|
41 | - private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
42 | - private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
43 | - private EventDispatcherInterface $eventDispatcher; |
|
44 | - private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
45 | - private ArticleServiceInterface $articleService; // swp.service.article |
|
46 | - |
|
47 | - /** |
|
48 | - * @param FormFactoryInterface $formFactory |
|
49 | - * @param RouteProviderInterface $routeProvider |
|
50 | - * @param ArticleRepositoryInterface $articleRepository |
|
51 | - * @param ArticleProviderInterface $articleProvider |
|
52 | - * @param EventDispatcherInterface $eventDispatcher |
|
53 | - * @param EntityManagerInterface $entityManager |
|
54 | - * @param ArticleServiceInterface $articleService |
|
55 | - */ |
|
56 | - public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
57 | - ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
58 | - EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
59 | - ArticleServiceInterface $articleService) { |
|
39 | + private FormFactoryInterface $formFactory; |
|
40 | + private RouteProviderInterface $routeProvider; // swp.provider.route |
|
41 | + private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
42 | + private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
43 | + private EventDispatcherInterface $eventDispatcher; |
|
44 | + private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
45 | + private ArticleServiceInterface $articleService; // swp.service.article |
|
46 | + |
|
47 | + /** |
|
48 | + * @param FormFactoryInterface $formFactory |
|
49 | + * @param RouteProviderInterface $routeProvider |
|
50 | + * @param ArticleRepositoryInterface $articleRepository |
|
51 | + * @param ArticleProviderInterface $articleProvider |
|
52 | + * @param EventDispatcherInterface $eventDispatcher |
|
53 | + * @param EntityManagerInterface $entityManager |
|
54 | + * @param ArticleServiceInterface $articleService |
|
55 | + */ |
|
56 | + public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
57 | + ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
58 | + EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
59 | + ArticleServiceInterface $articleService) { |
|
60 | 60 | $this->formFactory = $formFactory; |
61 | 61 | $this->routeProvider = $routeProvider; |
62 | 62 | $this->articleRepository = $articleRepository; |
@@ -64,30 +64,30 @@ discard block |
||
64 | 64 | $this->eventDispatcher = $eventDispatcher; |
65 | 65 | $this->entityManager = $entityManager; |
66 | 66 | $this->articleService = $articleService; |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
72 | - * |
|
73 | - * @throws \Exception |
|
74 | - */ |
|
75 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
70 | + /** |
|
71 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
72 | + * |
|
73 | + * @throws \Exception |
|
74 | + */ |
|
75 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
76 | 76 | $authors = ''; |
77 | 77 | if (null !== $request->query->get('author', null)) { |
78 | - $authors = explode(', ', $request->query->get('author')); |
|
78 | + $authors = explode(', ', $request->query->get('author')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) { |
82 | - $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
82 | + $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
83 | 83 | |
84 | - if (null !== $routeObject) { |
|
84 | + if (null !== $routeObject) { |
|
85 | 85 | $ids = [$routeObject->getId()]; |
86 | 86 | foreach ($routeObject->getChildren() as $child) { |
87 | - $ids[] = $child->getId(); |
|
87 | + $ids[] = $child->getId(); |
|
88 | 88 | } |
89 | 89 | $request->query->set('route', $ids); |
90 | - } |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $articles = $this->articleRepository |
@@ -102,25 +102,25 @@ discard block |
||
102 | 102 | ]), $request->query->all('sorting'), new PaginationData($request)); |
103 | 103 | |
104 | 104 | return new ResourcesListResponse($articles); |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
109 | - */ |
|
110 | - public function getAction($id): SingleResourceResponseInterface { |
|
107 | + /** |
|
108 | + * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
109 | + */ |
|
110 | + public function getAction($id): SingleResourceResponseInterface { |
|
111 | 111 | $article = $this->articleProvider->getOneById($id); |
112 | 112 | |
113 | 113 | if (null === $article) { |
114 | - throw new NotFoundHttpException('Article was not found.'); |
|
114 | + throw new NotFoundHttpException('Article was not found.'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return new SingleResourceResponse($article); |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
122 | - */ |
|
123 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
120 | + /** |
|
121 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
122 | + */ |
|
123 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
124 | 124 | $objectManager = $this->entityManager; |
125 | 125 | $article = $this->findOr404($id); |
126 | 126 | $originalArticleStatus = $article->getStatus(); |
@@ -129,32 +129,32 @@ discard block |
||
129 | 129 | |
130 | 130 | $form->handleRequest($request); |
131 | 131 | if ($form->isSubmitted() && $form->isValid()) { |
132 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
133 | - $objectManager->flush(); |
|
134 | - $objectManager->refresh($article); |
|
132 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
133 | + $objectManager->flush(); |
|
134 | + $objectManager->refresh($article); |
|
135 | 135 | |
136 | - return new SingleResourceResponse($article); |
|
136 | + return new SingleResourceResponse($article); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return new SingleResourceResponse($form, new ResponseContext(500)); |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
144 | - */ |
|
145 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
142 | + /** |
|
143 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
144 | + */ |
|
145 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
146 | 146 | $objectManager = $this->entityManager; |
147 | 147 | $objectManager->remove($this->findOr404($id)); |
148 | 148 | $objectManager->flush(); |
149 | 149 | |
150 | 150 | return new SingleResourceResponse(null, new ResponseContext(204)); |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | - private function findOr404($id) { |
|
153 | + private function findOr404($id) { |
|
154 | 154 | if (null === $article = $this->articleProvider->getOneById($id)) { |
155 | - throw new NotFoundHttpException('Article was not found.'); |
|
155 | + throw new NotFoundHttpException('Article was not found.'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $article; |
159 | - } |
|
159 | + } |
|
160 | 160 | } |