@@ -35,38 +35,38 @@ discard block |
||
35 | 35 | |
36 | 36 | class FbApplicationController extends Controller { |
37 | 37 | |
38 | - private FormFactoryInterface $formFactory; |
|
39 | - private RepositoryInterface $facebookAppRepository; |
|
40 | - private RepositoryInterface $facebookPageRepository; |
|
41 | - private Factory $facebookAppFactory; |
|
42 | - private EventDispatcherInterface $eventDispatcher; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param FormFactoryInterface $formFactory |
|
46 | - * @param RepositoryInterface $facebookAppRepository |
|
47 | - * @param RepositoryInterface $facebookPageRepository |
|
48 | - * @param Factory $facebookAppFactory |
|
49 | - * @param EventDispatcherInterface $eventDispatcher |
|
50 | - */ |
|
51 | - public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $facebookAppRepository, |
|
52 | - RepositoryInterface $facebookPageRepository, Factory $facebookAppFactory, |
|
53 | - EventDispatcherInterface $eventDispatcher) { |
|
38 | + private FormFactoryInterface $formFactory; |
|
39 | + private RepositoryInterface $facebookAppRepository; |
|
40 | + private RepositoryInterface $facebookPageRepository; |
|
41 | + private Factory $facebookAppFactory; |
|
42 | + private EventDispatcherInterface $eventDispatcher; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param FormFactoryInterface $formFactory |
|
46 | + * @param RepositoryInterface $facebookAppRepository |
|
47 | + * @param RepositoryInterface $facebookPageRepository |
|
48 | + * @param Factory $facebookAppFactory |
|
49 | + * @param EventDispatcherInterface $eventDispatcher |
|
50 | + */ |
|
51 | + public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $facebookAppRepository, |
|
52 | + RepositoryInterface $facebookPageRepository, Factory $facebookAppFactory, |
|
53 | + EventDispatcherInterface $eventDispatcher) { |
|
54 | 54 | $this->formFactory = $formFactory; |
55 | 55 | $this->facebookAppRepository = $facebookAppRepository; |
56 | 56 | $this->facebookPageRepository = $facebookPageRepository; |
57 | 57 | $this->facebookAppFactory = $facebookAppFactory; |
58 | 58 | $this->eventDispatcher = $eventDispatcher; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_applications") |
|
64 | - */ |
|
65 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
62 | + /** |
|
63 | + * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_applications") |
|
64 | + */ |
|
65 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
66 | 66 | $repository = $this->facebookAppRepository; |
67 | 67 | $sort = $request->query->all('sorting'); |
68 | 68 | if (empty($sort)) { |
69 | - $sort = ['id' => 'asc']; |
|
69 | + $sort = ['id' => 'asc']; |
|
70 | 70 | } |
71 | 71 | $items = $repository->getPaginatedByCriteria( |
72 | 72 | $this->eventDispatcher, |
@@ -76,51 +76,51 @@ discard block |
||
76 | 76 | ); |
77 | 77 | |
78 | 78 | return new ResourcesListResponse($items); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_applications") |
|
83 | - */ |
|
84 | - public function createAction(Request $request) { |
|
81 | + /** |
|
82 | + * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_applications") |
|
83 | + */ |
|
84 | + public function createAction(Request $request) { |
|
85 | 85 | /* @var FacebookApplication $feed */ |
86 | 86 | $application = $this->facebookAppFactory->create(); |
87 | 87 | $form = $this->formFactory->createNamed('', FacebookApplicationType::class, $application, ['method' => $request->getMethod()]); |
88 | 88 | |
89 | 89 | $form->handleRequest($request); |
90 | 90 | if ($form->isSubmitted() && $form->isValid()) { |
91 | - $this->checkIfApplicationExists($application); |
|
92 | - $this->facebookAppRepository->add($application); |
|
91 | + $this->checkIfApplicationExists($application); |
|
92 | + $this->facebookAppRepository->add($application); |
|
93 | 93 | |
94 | - return new SingleResourceResponse($application, new ResponseContext(201)); |
|
94 | + return new SingleResourceResponse($application, new ResponseContext(201)); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return new SingleResourceResponse($form, new ResponseContext(400)); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @Route("/api/{version}/facebook/applications/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_applications") |
|
102 | - */ |
|
103 | - public function deleteAction($id) { |
|
100 | + /** |
|
101 | + * @Route("/api/{version}/facebook/applications/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_applications") |
|
102 | + */ |
|
103 | + public function deleteAction($id) { |
|
104 | 104 | $repository = $this->facebookAppRepository; |
105 | 105 | if (null === $application = $repository->findOneBy(['id' => $id])) { |
106 | - throw new NotFoundHttpException('There is no Application with provided id!'); |
|
106 | + throw new NotFoundHttpException('There is no Application with provided id!'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | if (null !== $page = $this->facebookPageRepository->findOneBy(['id' => $id])) { |
110 | - throw new ConflictHttpException(sprintf('This Application is used by page with id: %s!', $page->getId())); |
|
110 | + throw new ConflictHttpException(sprintf('This Application is used by page with id: %s!', $page->getId())); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $repository->remove($application); |
114 | 114 | |
115 | 115 | return new SingleResourceResponse(null, new ResponseContext(204)); |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - private function checkIfApplicationExists(ApplicationInterface $application) { |
|
118 | + private function checkIfApplicationExists(ApplicationInterface $application) { |
|
119 | 119 | if (null !== $this->facebookAppRepository->findOneBy([ |
120 | 120 | 'appId' => $application->getAppId(), |
121 | 121 | ]) |
122 | 122 | ) { |
123 | - throw new ConflictHttpException('This Application already exists!'); |
|
123 | + throw new ConflictHttpException('This Application already exists!'); |
|
124 | + } |
|
124 | 125 | } |
125 | - } |
|
126 | 126 | } |
@@ -37,98 +37,98 @@ discard block |
||
37 | 37 | use Symfony\Component\Security\Core\User\UserProviderInterface; |
38 | 38 | |
39 | 39 | class AuthController extends AbstractController { |
40 | - protected FormFactoryInterface $formFactory; |
|
41 | - protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
42 | - protected ApiKeyFactory $apiKeyFactory; |
|
43 | - protected LockFactory $lockFactory; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param FormFactoryInterface $formFactory |
|
47 | - * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
48 | - * @param ApiKeyFactory $apiKeyFactory |
|
49 | - * @param LockFactory $lockFactory |
|
50 | - */ |
|
51 | - public function __construct(FormFactoryInterface $formFactory, ApiKeyRepositoryInterface $apiKeyRepository, |
|
52 | - ApiKeyFactory $apiKeyFactory, LockFactory $lockFactory) { |
|
40 | + protected FormFactoryInterface $formFactory; |
|
41 | + protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
42 | + protected ApiKeyFactory $apiKeyFactory; |
|
43 | + protected LockFactory $lockFactory; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param FormFactoryInterface $formFactory |
|
47 | + * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
48 | + * @param ApiKeyFactory $apiKeyFactory |
|
49 | + * @param LockFactory $lockFactory |
|
50 | + */ |
|
51 | + public function __construct(FormFactoryInterface $formFactory, ApiKeyRepositoryInterface $apiKeyRepository, |
|
52 | + ApiKeyFactory $apiKeyFactory, LockFactory $lockFactory) { |
|
53 | 53 | $this->formFactory = $formFactory; |
54 | 54 | $this->apiKeyRepository = $apiKeyRepository; |
55 | 55 | $this->apiKeyFactory = $apiKeyFactory; |
56 | 56 | $this->lockFactory = $lockFactory; |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @Route("/api/{version}/auth/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_auth") |
|
62 | - */ |
|
63 | - public function authenticateAction(Request $request, UserProviderInterface $userProvider, |
|
64 | - UserPasswordHasherInterface $userPasswordEncoder) { |
|
60 | + /** |
|
61 | + * @Route("/api/{version}/auth/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_auth") |
|
62 | + */ |
|
63 | + public function authenticateAction(Request $request, UserProviderInterface $userProvider, |
|
64 | + UserPasswordHasherInterface $userPasswordEncoder) { |
|
65 | 65 | $form = $this->formFactory->createNamed('', UserAuthenticationType::class, []); |
66 | 66 | $form->handleRequest($request); |
67 | 67 | if ($form->isSubmitted() && $form->isValid()) { |
68 | - $formData = $form->getData(); |
|
68 | + $formData = $form->getData(); |
|
69 | 69 | |
70 | - try { |
|
70 | + try { |
|
71 | 71 | $user = $userProvider->loadUserByUsername($formData['username']); |
72 | - } catch (AuthenticationException $e) { |
|
72 | + } catch (AuthenticationException $e) { |
|
73 | 73 | $user = null; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
76 | + if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
77 | 77 | return $this->returnApiTokenResponse($user); |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return new SingleResourceResponse([ |
82 | 82 | 'status' => 401, |
83 | 83 | 'message' => 'Unauthorized', |
84 | 84 | ], new ResponseContext(401)); |
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @Route("/api/{version}/auth/superdesk/", options={"expose"=true}, methods={"POST"}, defaults={"version"="v2"}, name="swp_api_auth_superdesk") |
|
89 | - */ |
|
90 | - public function authenticateWithSuperdeskAction( |
|
91 | - Request $request, |
|
92 | - LoggerInterface $logger, |
|
93 | - array $superdeskServers, |
|
94 | - UserProviderInterface $userProvider, |
|
95 | - UserManagerInterface $userManager |
|
96 | - ) { |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @Route("/api/{version}/auth/superdesk/", options={"expose"=true}, methods={"POST"}, defaults={"version"="v2"}, name="swp_api_auth_superdesk") |
|
89 | + */ |
|
90 | + public function authenticateWithSuperdeskAction( |
|
91 | + Request $request, |
|
92 | + LoggerInterface $logger, |
|
93 | + array $superdeskServers, |
|
94 | + UserProviderInterface $userProvider, |
|
95 | + UserManagerInterface $userManager |
|
96 | + ) { |
|
97 | 97 | $form = $this->formFactory->createNamed('', SuperdeskCredentialAuthenticationType::class, []); |
98 | 98 | $form->handleRequest($request); |
99 | 99 | if ($form->isSubmitted() && $form->isValid()) { |
100 | - $formData = $form->getData(); |
|
101 | - $authorizedSuperdeskHosts = $superdeskServers; |
|
102 | - $superdeskUser = null; |
|
103 | - $client = new GuzzleHttp\Client(); |
|
100 | + $formData = $form->getData(); |
|
101 | + $authorizedSuperdeskHosts = $superdeskServers; |
|
102 | + $superdeskUser = null; |
|
103 | + $client = new GuzzleHttp\Client(); |
|
104 | 104 | |
105 | - foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
105 | + foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
106 | 106 | try { |
107 | - $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
108 | - 'Authorization' => $formData['token'], |
|
109 | - ]); |
|
107 | + $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
108 | + 'Authorization' => $formData['token'], |
|
109 | + ]); |
|
110 | 110 | |
111 | - $apiResponse = $client->send($apiRequest); |
|
112 | - if (200 !== $apiResponse->getStatusCode()) { |
|
111 | + $apiResponse = $client->send($apiRequest); |
|
112 | + if (200 !== $apiResponse->getStatusCode()) { |
|
113 | 113 | $logger->warning(sprintf('[%s] Unsuccessful response from Superdesk Server: %s', $apiResponse->getStatusCode(), $apiResponse->getBody()->getContents())); |
114 | 114 | |
115 | 115 | continue; |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
119 | - if (is_array($content) && array_key_exists('user', $content)) { |
|
118 | + $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
119 | + if (is_array($content) && array_key_exists('user', $content)) { |
|
120 | 120 | $superdeskUser = $content['user']; |
121 | 121 | |
122 | 122 | break; |
123 | - } |
|
123 | + } |
|
124 | 124 | } catch (GuzzleHttp\Exception\ClientException $e) { |
125 | - $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
125 | + $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
126 | 126 | |
127 | - continue; |
|
127 | + continue; |
|
128 | + } |
|
128 | 129 | } |
129 | - } |
|
130 | 130 | |
131 | - if (null === $superdeskUser) { |
|
131 | + if (null === $superdeskUser) { |
|
132 | 132 | return new SingleResourceResponse([ |
133 | 133 | 'status' => 401, |
134 | 134 | 'message' => <<<'MESSAGE' |
@@ -136,18 +136,18 @@ discard block |
||
136 | 136 | Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
137 | 137 | MESSAGE, |
138 | 138 | ], new ResponseContext(401)); |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
142 | - if (null === $publisherUser) { |
|
141 | + $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
142 | + if (null === $publisherUser) { |
|
143 | 143 | try { |
144 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
144 | + $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
145 | 145 | } catch (AuthenticationException $e) { |
146 | - $publisherUser = null; |
|
146 | + $publisherUser = null; |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | |
150 | - if (null === $publisherUser) { |
|
150 | + if (null === $publisherUser) { |
|
151 | 151 | /** @var UserInterface $publisherUser */ |
152 | 152 | $publisherUser = $userManager->createUser(); |
153 | 153 | $publisherUser->setUsername($superdeskUser['username']); |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
158 | 158 | $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
159 | 159 | $userManager->updateUser($publisherUser); |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - if (null !== $publisherUser) { |
|
162 | + if (null !== $publisherUser) { |
|
163 | 163 | return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
164 | - } |
|
164 | + } |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return new SingleResourceResponse([ |
168 | 168 | 'status' => 401, |
169 | 169 | 'message' => 'Unauthorized', |
170 | 170 | ], new ResponseContext(401)); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
173 | + private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
174 | 174 | /** @var ApiKeyInterface $apiKey */ |
175 | 175 | $apiKey = $this->generateOrGetApiKey($user, $token); |
176 | 176 | |
@@ -181,36 +181,36 @@ discard block |
||
181 | 181 | ], |
182 | 182 | 'user' => $user, |
183 | 183 | ]); |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
186 | + private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
187 | 187 | $apiKey = null; |
188 | 188 | if (null !== $token) { |
189 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
189 | + $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
190 | 190 | } else { |
191 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
192 | - if (count($validKeys) > 0) { |
|
191 | + $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
192 | + if (count($validKeys) > 0) { |
|
193 | 193 | $apiKey = reset($validKeys); |
194 | - } |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | if (null === $apiKey) { |
198 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
198 | + $apiKey = $this->apiKeyFactory->create($user, $token); |
|
199 | 199 | |
200 | - try { |
|
200 | + try { |
|
201 | 201 | $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
202 | 202 | if (!$lock->acquire()) { |
203 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
203 | + throw new RuntimeException('Other api key is created right now for this user'); |
|
204 | 204 | } |
205 | 205 | $this->apiKeyRepository->add($apiKey); |
206 | 206 | $lock->release(); |
207 | - } catch (RuntimeException $e) { |
|
207 | + } catch (RuntimeException $e) { |
|
208 | 208 | sleep(2); |
209 | 209 | |
210 | 210 | return $this->generateOrGetApiKey($user, $token); |
211 | - } |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return $apiKey; |
215 | - } |
|
215 | + } |
|
216 | 216 | } |
@@ -29,32 +29,32 @@ discard block |
||
29 | 29 | |
30 | 30 | class FbiaArticleController extends Controller { |
31 | 31 | |
32 | - private FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository; |
|
33 | - private FacebookInstantArticlesService $facebookInstantArticlesService; |
|
34 | - private EventDispatcherInterface $eventDispatcher; |
|
32 | + private FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository; |
|
33 | + private FacebookInstantArticlesService $facebookInstantArticlesService; |
|
34 | + private EventDispatcherInterface $eventDispatcher; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository |
|
38 | - * @param FacebookInstantArticlesService $facebookInstantArticlesService |
|
39 | - * @param EventDispatcherInterface $eventDispatcher |
|
40 | - */ |
|
41 | - public function __construct(FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository, |
|
42 | - FacebookInstantArticlesService $facebookInstantArticlesService, |
|
43 | - EventDispatcherInterface $eventDispatcher) { |
|
36 | + /** |
|
37 | + * @param FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository |
|
38 | + * @param FacebookInstantArticlesService $facebookInstantArticlesService |
|
39 | + * @param EventDispatcherInterface $eventDispatcher |
|
40 | + */ |
|
41 | + public function __construct(FacebookInstantArticlesArticleRepository $facebookInstantArticlesArticleRepository, |
|
42 | + FacebookInstantArticlesService $facebookInstantArticlesService, |
|
43 | + EventDispatcherInterface $eventDispatcher) { |
|
44 | 44 | $this->facebookInstantArticlesArticleRepository = $facebookInstantArticlesArticleRepository; |
45 | 45 | $this->facebookInstantArticlesService = $facebookInstantArticlesService; |
46 | 46 | $this->eventDispatcher = $eventDispatcher; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @Route("/api/{version}/facebook/instantarticles/articles/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_instant_articles_articles") |
|
52 | - */ |
|
53 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
50 | + /** |
|
51 | + * @Route("/api/{version}/facebook/instantarticles/articles/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_instant_articles_articles") |
|
52 | + */ |
|
53 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
54 | 54 | $repository = $this->facebookInstantArticlesArticleRepository; |
55 | 55 | $sort = $request->query->all('sorting'); |
56 | 56 | if (empty($sort)) { |
57 | - $sort = ['createdAt' => 'desc']; |
|
57 | + $sort = ['createdAt' => 'desc']; |
|
58 | 58 | } |
59 | 59 | $items = $repository->getPaginatedByCriteria( |
60 | 60 | $this->eventDispatcher, |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | ); |
65 | 65 | |
66 | 66 | return new ResourcesListResponse($items); |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @Route("/api/{version}/facebook/instantarticles/articles/{submissionId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_facebook_instant_articles_articles_update") |
|
71 | - */ |
|
72 | - public function updateSubmissionAction(string $submissionId): SingleResourceResponseInterface { |
|
69 | + /** |
|
70 | + * @Route("/api/{version}/facebook/instantarticles/articles/{submissionId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_facebook_instant_articles_articles_update") |
|
71 | + */ |
|
72 | + public function updateSubmissionAction(string $submissionId): SingleResourceResponseInterface { |
|
73 | 73 | $instantArticlesService = $this->facebookInstantArticlesService; |
74 | 74 | $instantArticle = $instantArticlesService->updateSubmissionStatus($submissionId); |
75 | 75 | |
76 | 76 | return new SingleResourceResponse($instantArticle); |
77 | - } |
|
77 | + } |
|
78 | 78 | } |
@@ -43,29 +43,29 @@ |
||
43 | 43 | { |
44 | 44 | $collectionRouteCacheKey = md5('route_'.$url); |
45 | 45 | return $this->cacheProvider->get($collectionRouteCacheKey, function (ItemInterface $item, &$save) use ($url) { |
46 | - try { |
|
46 | + try { |
|
47 | 47 | $route = $this->matcher->match($this->getFragmentFromUrl($url, 'path')); |
48 | - } catch(ResourceNotFoundException $e) { |
|
48 | + } catch(ResourceNotFoundException $e) { |
|
49 | 49 | $save = false; |
50 | 50 | return null; |
51 | - } |
|
52 | - if(!isset($route['_article_meta'])) { |
|
51 | + } |
|
52 | + if(!isset($route['_article_meta'])) { |
|
53 | 53 | $save = false; |
54 | 54 | return null; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - if(!($route['_article_meta'] instanceof Meta)) { |
|
57 | + if(!($route['_article_meta'] instanceof Meta)) { |
|
58 | 58 | $save = false; |
59 | 59 | return null; |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - $values = $route['_article_meta']->getValues(); |
|
63 | - if(!($values instanceof ArticleInterface)) { |
|
62 | + $values = $route['_article_meta']->getValues(); |
|
63 | + if(!($values instanceof ArticleInterface)) { |
|
64 | 64 | $save = false; |
65 | 65 | return null; |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - return $values; |
|
68 | + return $values; |
|
69 | 69 | }); |
70 | 70 | } |
71 | 71 |
@@ -64,16 +64,16 @@ |
||
64 | 64 | ParameterBagInterface $parameterBag, |
65 | 65 | ThemeServiceInterface $themeService |
66 | 66 | ) { |
67 | - $this->tenantContext = $tenantContext; |
|
68 | - $this->tenantRepository = $tenantRepository; |
|
69 | - $this->eventDispatcher = $eventDispatcher; |
|
70 | - $this->parameterBag = $parameterBag; |
|
71 | - $this->themeService = $themeService; |
|
72 | - parent::__construct(); |
|
67 | + $this->tenantContext = $tenantContext; |
|
68 | + $this->tenantRepository = $tenantRepository; |
|
69 | + $this->eventDispatcher = $eventDispatcher; |
|
70 | + $this->parameterBag = $parameterBag; |
|
71 | + $this->themeService = $themeService; |
|
72 | + parent::__construct(); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | - /** |
|
76 | + /** |
|
77 | 77 | * {@inheritdoc} |
78 | 78 | */ |
79 | 79 | protected function configure() |
@@ -45,9 +45,9 @@ |
||
45 | 45 | * @param OrganizationRepositoryInterface $organizationRepository |
46 | 46 | */ |
47 | 47 | public function __construct(ParameterBagInterface $parameterBag, OrganizationRepositoryInterface $organizationRepository) { |
48 | - $this->parameterBag = $parameterBag; |
|
49 | - $this->organizationRepository = $organizationRepository; |
|
50 | - parent::__construct(); |
|
48 | + $this->parameterBag = $parameterBag; |
|
49 | + $this->organizationRepository = $organizationRepository; |
|
50 | + parent::__construct(); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -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 |
@@ -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() |
@@ -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 | } |