@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function findChildrenAsTree(EventDispatcherInterface $eventDispatcher,MenuItemInterface $menuItem) |
|
105 | + public function findChildrenAsTree(EventDispatcherInterface $eventDispatcher, MenuItemInterface $menuItem) |
|
106 | 106 | { |
107 | 107 | $queryBuilder = $this->createQueryBuilder('m'); |
108 | 108 | $queryBuilder |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ->orderBy('m.lft', 'asc') |
115 | 115 | ; |
116 | 116 | |
117 | - return $this->getPaginator($eventDispatcher,$queryBuilder, new PaginationData()); |
|
117 | + return $this->getPaginator($eventDispatcher, $queryBuilder, new PaginationData()); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,19 +128,19 @@ |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * @param MenuItemInterface $node |
|
133 | - * @param MenuItemInterface $parent |
|
134 | - */ |
|
135 | - public function persistAsFirstChildOf(MenuItemInterface $node, MenuItemInterface $parent) { |
|
131 | + /** |
|
132 | + * @param MenuItemInterface $node |
|
133 | + * @param MenuItemInterface $parent |
|
134 | + */ |
|
135 | + public function persistAsFirstChildOf(MenuItemInterface $node, MenuItemInterface $parent) { |
|
136 | 136 | parent::persistAsFirstChildOf($node, $parent); |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param MenuItemInterface $node |
|
141 | - * @param MenuItemInterface $sibling |
|
142 | - */ |
|
143 | - public function persistAsNextSiblingOf(MenuItemInterface $node, MenuItemInterface $sibling) { |
|
139 | + /** |
|
140 | + * @param MenuItemInterface $node |
|
141 | + * @param MenuItemInterface $sibling |
|
142 | + */ |
|
143 | + public function persistAsNextSiblingOf(MenuItemInterface $node, MenuItemInterface $sibling) { |
|
144 | 144 | parent::persistAsNextSiblingOf($node, $sibling); |
145 | - } |
|
145 | + } |
|
146 | 146 | } |
@@ -32,122 +32,122 @@ |
||
32 | 32 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
33 | 33 | |
34 | 34 | class ContentListsItemLoader extends PaginatedLoader implements LoaderInterface { |
35 | - protected ContentListRepositoryInterface $contentListRepository; |
|
36 | - protected ContentListItemRepositoryInterface $contentListItemsRepository; |
|
37 | - protected MetaFactoryInterface $metaFactory; |
|
38 | - private CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector; |
|
39 | - private EventDispatcherInterface $eventDispatcher; |
|
40 | - |
|
41 | - public function __construct( |
|
42 | - ContentListRepositoryInterface $contentListRepository, |
|
43 | - ContentListItemRepositoryInterface $contentListItemRepository, |
|
44 | - MetaFactoryInterface $metaFactory, |
|
45 | - CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector, |
|
46 | - EventDispatcherInterface $eventDispatcher |
|
47 | - ) { |
|
35 | + protected ContentListRepositoryInterface $contentListRepository; |
|
36 | + protected ContentListItemRepositoryInterface $contentListItemsRepository; |
|
37 | + protected MetaFactoryInterface $metaFactory; |
|
38 | + private CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector; |
|
39 | + private EventDispatcherInterface $eventDispatcher; |
|
40 | + |
|
41 | + public function __construct( |
|
42 | + ContentListRepositoryInterface $contentListRepository, |
|
43 | + ContentListItemRepositoryInterface $contentListItemRepository, |
|
44 | + MetaFactoryInterface $metaFactory, |
|
45 | + CacheBlockTagsCollectorInterface $cacheBlocksTagsCollector, |
|
46 | + EventDispatcherInterface $eventDispatcher |
|
47 | + ) { |
|
48 | 48 | $this->contentListRepository = $contentListRepository; |
49 | 49 | $this->contentListItemsRepository = $contentListItemRepository; |
50 | 50 | $this->metaFactory = $metaFactory; |
51 | 51 | $this->cacheBlocksTagsCollector = $cacheBlocksTagsCollector; |
52 | 52 | $this->eventDispatcher = $eventDispatcher; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function load($type, $parameters = [], $withoutParameters = [], $responseType = LoaderInterface::SINGLE) { |
|
55 | + public function load($type, $parameters = [], $withoutParameters = [], $responseType = LoaderInterface::SINGLE) { |
|
56 | 56 | $criteria = new Criteria(); |
57 | 57 | if (LoaderInterface::COLLECTION === $responseType) { |
58 | - if (array_key_exists('contentListId', $parameters) && is_numeric($parameters['contentListId'])) { |
|
58 | + if (array_key_exists('contentListId', $parameters) && is_numeric($parameters['contentListId'])) { |
|
59 | 59 | $contentList = $this->contentListRepository->findOneBy(['id' => $parameters['contentListId']]); |
60 | 60 | $criteria->set('contentList', $contentList); |
61 | - } elseif (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
61 | + } elseif (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
62 | 62 | $contentList = $this->contentListRepository->findOneBy(['name' => $parameters['contentListName']]); |
63 | 63 | $criteria->set('contentList', $contentList); |
64 | - } elseif ( |
|
65 | - array_key_exists('contentList', $parameters) && |
|
64 | + } elseif ( |
|
65 | + array_key_exists('contentList', $parameters) && |
|
66 | 66 | $parameters['contentList'] instanceof Meta && |
67 | 67 | $parameters['contentList']->getValues() instanceof ContentListInterface |
68 | - ) { |
|
68 | + ) { |
|
69 | 69 | $criteria->set('contentList', $parameters['contentList']->getValues()); |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - if (!$criteria->has('contentList')) { |
|
72 | + if (!$criteria->has('contentList')) { |
|
73 | 73 | return false; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - if (array_key_exists('sticky', $parameters) && is_bool($parameters['sticky'])) { |
|
76 | + if (array_key_exists('sticky', $parameters) && is_bool($parameters['sticky'])) { |
|
77 | 77 | $criteria->set('sticky', $parameters['sticky']); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - if (isset($withoutParameters['content']) && !empty($withoutParameters['content'])) { |
|
80 | + if (isset($withoutParameters['content']) && !empty($withoutParameters['content'])) { |
|
81 | 81 | $criteria->set('exclude_content', $withoutParameters['content']); |
82 | - } |
|
83 | - |
|
84 | - $criteria = $this->applyPaginationToCriteria($criteria, $parameters); |
|
85 | - $contentListItems = $this->contentListItemsRepository->getPaginatedByCriteria($this->eventDispatcher, $criteria, $criteria->get('order', [ |
|
86 | - 'sticky' => 'desc', |
|
87 | - ])); |
|
88 | - $itemsCollection = new ArrayCollection($contentListItems->getItems()); |
|
89 | - if ($itemsCollection->count() > 0) { |
|
82 | + } |
|
83 | + |
|
84 | + $criteria = $this->applyPaginationToCriteria($criteria, $parameters); |
|
85 | + $contentListItems = $this->contentListItemsRepository->getPaginatedByCriteria($this->eventDispatcher, $criteria, $criteria->get('order', [ |
|
86 | + 'sticky' => 'desc', |
|
87 | + ])); |
|
88 | + $itemsCollection = new ArrayCollection($contentListItems->getItems()); |
|
89 | + if ($itemsCollection->count() > 0) { |
|
90 | 90 | $metaCollection = new MetaCollection(); |
91 | 91 | $metaCollection->setTotalItemsCount($contentListItems->getTotalItemCount()); |
92 | 92 | foreach ($itemsCollection as $item) { |
93 | - $itemMeta = $this->getItemMeta($item); |
|
94 | - if (null !== $itemMeta) { |
|
93 | + $itemMeta = $this->getItemMeta($item); |
|
94 | + if (null !== $itemMeta) { |
|
95 | 95 | $metaCollection->add($itemMeta); |
96 | - } |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | unset($itemsCollection, $criteria); |
99 | 99 | |
100 | 100 | return $metaCollection; |
101 | - } |
|
101 | + } |
|
102 | 102 | } elseif (LoaderInterface::SINGLE === $responseType) { |
103 | - if (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
103 | + if (array_key_exists('contentListName', $parameters) && is_string($parameters['contentListName'])) { |
|
104 | 104 | $contentList = $this->contentListRepository->findOneBy(['name' => $parameters['contentListName']]); |
105 | 105 | $criteria->set('contentList', $contentList); |
106 | - } elseif ( |
|
107 | - array_key_exists('contentList', $parameters) && |
|
106 | + } elseif ( |
|
107 | + array_key_exists('contentList', $parameters) && |
|
108 | 108 | $parameters['contentList'] instanceof Meta && |
109 | 109 | $parameters['contentList']->getValues() instanceof ContentListInterface |
110 | - ) { |
|
110 | + ) { |
|
111 | 111 | $criteria->set('contentList', $parameters['contentList']->getValues()); |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - if ( |
|
115 | - isset($contentList) |
|
114 | + if ( |
|
115 | + isset($contentList) |
|
116 | 116 | && array_key_exists('article', $parameters) |
117 | 117 | && $parameters['article'] instanceof Meta |
118 | 118 | && $parameters['article']->getValues() instanceof ArticleInterface |
119 | - ) { |
|
119 | + ) { |
|
120 | 120 | /** @var ContentListItemInterface $currentContentListItem */ |
121 | 121 | $currentContentListItem = $this->contentListItemsRepository->getQueryByCriteria(new Criteria([ |
122 | 122 | 'contentList' => $contentList, |
123 | 123 | 'content' => $parameters['article']->getValues(), |
124 | 124 | ]), [], 'n')->getQuery()->getOneOrNullResult(); |
125 | 125 | $position = $currentContentListItem->getPosition(); |
126 | - } |
|
126 | + } |
|
127 | 127 | |
128 | - if (isset($position) && array_key_exists('prev', $parameters) && true === $parameters['prev']) { |
|
128 | + if (isset($position) && array_key_exists('prev', $parameters) && true === $parameters['prev']) { |
|
129 | 129 | ++$position; |
130 | - } elseif (isset($position) && array_key_exists('next', $parameters) && true === $parameters['next']) { |
|
130 | + } elseif (isset($position) && array_key_exists('next', $parameters) && true === $parameters['next']) { |
|
131 | 131 | --$position; |
132 | - } else { |
|
132 | + } else { |
|
133 | 133 | return null; |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - return $this->getItemMeta($this->contentListItemsRepository->getOneOrNullByPosition($criteria, $position)); |
|
136 | + return $this->getItemMeta($this->contentListItemsRepository->getOneOrNullByPosition($criteria, $position)); |
|
137 | + } |
|
137 | 138 | } |
138 | - } |
|
139 | 139 | |
140 | - public function isSupported(string $type): bool { |
|
140 | + public function isSupported(string $type): bool { |
|
141 | 141 | return in_array($type, ['contentListItems', 'contentListItem']); |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - private function getItemMeta($item) { |
|
144 | + private function getItemMeta($item) { |
|
145 | 145 | if (null !== $item) { |
146 | - if ($item instanceof ContentListItemInterface) { |
|
146 | + if ($item instanceof ContentListItemInterface) { |
|
147 | 147 | $this->cacheBlocksTagsCollector->addTagToCurrentCacheBlock('a-' . $item->getContent()->getId()); |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - return $this->metaFactory->create($item); |
|
150 | + return $this->metaFactory->create($item); |
|
151 | + } |
|
151 | 152 | } |
152 | - } |
|
153 | 153 | } |
@@ -144,7 +144,7 @@ |
||
144 | 144 | private function getItemMeta($item) { |
145 | 145 | if (null !== $item) { |
146 | 146 | if ($item instanceof ContentListItemInterface) { |
147 | - $this->cacheBlocksTagsCollector->addTagToCurrentCacheBlock('a-' . $item->getContent()->getId()); |
|
147 | + $this->cacheBlocksTagsCollector->addTagToCurrentCacheBlock('a-'.$item->getContent()->getId()); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return $this->metaFactory->create($item); |
@@ -121,7 +121,7 @@ |
||
121 | 121 | */ |
122 | 122 | public function verifyUserEmail(Request $request, GuardAuthenticatorHandler $guardHandler, |
123 | 123 | LoginAuthenticator $authenticator): Response { |
124 | - $id = (int)$request->get('id'); // retrieve the user id from the url |
|
124 | + $id = (int) $request->get('id'); // retrieve the user id from the url |
|
125 | 125 | |
126 | 126 | if ($request->isXmlHttpRequest()) { |
127 | 127 | return $this->verifyUserEmailFromPWA($id, $request); |
@@ -40,43 +40,43 @@ discard block |
||
40 | 40 | |
41 | 41 | class RegistrationController extends AbstractController { |
42 | 42 | |
43 | - private SettingsManagerInterface $settingsManager; |
|
44 | - private ScopeContextInterface $scopeContext; |
|
45 | - private EmailVerifier $emailVerifier; |
|
46 | - private UserManagerInterface $userManager; |
|
47 | - private EntityManagerInterface $entityManager; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param SettingsManagerInterface $settingsManager |
|
51 | - * @param ScopeContextInterface $scopeContext |
|
52 | - * @param EmailVerifier $emailVerifier |
|
53 | - * @param UserManagerInterface $userManager |
|
54 | - * @param EntityManagerInterface $entityManager |
|
55 | - */ |
|
56 | - public function __construct(SettingsManagerInterface $settingsManager, ScopeContextInterface $scopeContext, |
|
57 | - EmailVerifier $emailVerifier, UserManagerInterface $userManager, |
|
58 | - EntityManagerInterface $entityManager) { |
|
43 | + private SettingsManagerInterface $settingsManager; |
|
44 | + private ScopeContextInterface $scopeContext; |
|
45 | + private EmailVerifier $emailVerifier; |
|
46 | + private UserManagerInterface $userManager; |
|
47 | + private EntityManagerInterface $entityManager; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param SettingsManagerInterface $settingsManager |
|
51 | + * @param ScopeContextInterface $scopeContext |
|
52 | + * @param EmailVerifier $emailVerifier |
|
53 | + * @param UserManagerInterface $userManager |
|
54 | + * @param EntityManagerInterface $entityManager |
|
55 | + */ |
|
56 | + public function __construct(SettingsManagerInterface $settingsManager, ScopeContextInterface $scopeContext, |
|
57 | + EmailVerifier $emailVerifier, UserManagerInterface $userManager, |
|
58 | + EntityManagerInterface $entityManager) { |
|
59 | 59 | $this->settingsManager = $settingsManager; |
60 | 60 | $this->scopeContext = $scopeContext; |
61 | 61 | $this->emailVerifier = $emailVerifier; |
62 | 62 | $this->userManager = $userManager; |
63 | 63 | $this->entityManager = $entityManager; |
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @FOSRoute("/api/{version}/users/register/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_register_user") |
|
69 | - */ |
|
70 | - public function registerAction( |
|
71 | - Request $request, |
|
72 | - UserPasswordEncoderInterface $passwordEncoder, |
|
73 | - UserManagerInterface $userManager, |
|
74 | - MailerInterface $mailer |
|
75 | - ) { |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @FOSRoute("/api/{version}/users/register/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_register_user") |
|
69 | + */ |
|
70 | + public function registerAction( |
|
71 | + Request $request, |
|
72 | + UserPasswordEncoderInterface $passwordEncoder, |
|
73 | + UserManagerInterface $userManager, |
|
74 | + MailerInterface $mailer |
|
75 | + ) { |
|
76 | 76 | try { |
77 | - $this->ensureThatRegistrationIsEnabled(); |
|
77 | + $this->ensureThatRegistrationIsEnabled(); |
|
78 | 78 | } catch (NotFoundHttpException $e) { |
79 | - return new SingleResourceResponse(null, new ResponseContext(404)); |
|
79 | + return new SingleResourceResponse(null, new ResponseContext(404)); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $user = $userManager->createUser(); |
@@ -85,66 +85,66 @@ discard block |
||
85 | 85 | $form->handleRequest($request); |
86 | 86 | |
87 | 87 | if ($form->isSubmitted() && $form->isValid()) { |
88 | - $user->addRole('ROLE_USER'); |
|
89 | - // encode the plain password |
|
90 | - $user->setPassword( |
|
91 | - $passwordEncoder->encodePassword( |
|
92 | - $user, |
|
93 | - $form->get('plainPassword')->getData() |
|
94 | - ) |
|
95 | - ); |
|
96 | - |
|
97 | - $entityManager = $this->entityManager; |
|
98 | - $entityManager->persist($user); |
|
99 | - $entityManager->flush(); |
|
100 | - |
|
101 | - $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
102 | - $url = $signatureComponents->getSignedUrl(); |
|
103 | - |
|
104 | - $mailer->sendConfirmationEmail($user, $url); |
|
105 | - |
|
106 | - return new JsonResponse([ |
|
107 | - 'message' => sprintf( |
|
108 | - 'The user has been created successfully. |
|
88 | + $user->addRole('ROLE_USER'); |
|
89 | + // encode the plain password |
|
90 | + $user->setPassword( |
|
91 | + $passwordEncoder->encodePassword( |
|
92 | + $user, |
|
93 | + $form->get('plainPassword')->getData() |
|
94 | + ) |
|
95 | + ); |
|
96 | + |
|
97 | + $entityManager = $this->entityManager; |
|
98 | + $entityManager->persist($user); |
|
99 | + $entityManager->flush(); |
|
100 | + |
|
101 | + $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
102 | + $url = $signatureComponents->getSignedUrl(); |
|
103 | + |
|
104 | + $mailer->sendConfirmationEmail($user, $url); |
|
105 | + |
|
106 | + return new JsonResponse([ |
|
107 | + 'message' => sprintf( |
|
108 | + 'The user has been created successfully. |
|
109 | 109 | An email has been sent to %s. It contains an activation link you must click to activate your account.', |
110 | - $user->getEmail() |
|
111 | - ), |
|
112 | - 'url' => $url, |
|
113 | - ]); |
|
110 | + $user->getEmail() |
|
111 | + ), |
|
112 | + 'url' => $url, |
|
113 | + ]); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | return new SingleResourceResponse($form, new ResponseContext(400)); |
117 | - } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @Route("/verify/email", name="swp_user_verify_email") |
|
121 | - */ |
|
122 | - public function verifyUserEmail(Request $request, GuardAuthenticatorHandler $guardHandler, |
|
123 | - LoginAuthenticator $authenticator): Response { |
|
119 | + /** |
|
120 | + * @Route("/verify/email", name="swp_user_verify_email") |
|
121 | + */ |
|
122 | + public function verifyUserEmail(Request $request, GuardAuthenticatorHandler $guardHandler, |
|
123 | + LoginAuthenticator $authenticator): Response { |
|
124 | 124 | $id = (int)$request->get('id'); // retrieve the user id from the url |
125 | 125 | |
126 | 126 | if ($request->isXmlHttpRequest()) { |
127 | - return $this->verifyUserEmailFromPWA($id, $request); |
|
127 | + return $this->verifyUserEmailFromPWA($id, $request); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | // Verify the user id exists and is not null |
131 | 131 | if (null === $id) { |
132 | - return $this->redirectToRoute('homepage'); |
|
132 | + return $this->redirectToRoute('homepage'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $user = $this->userManager->find($id); |
136 | 136 | |
137 | 137 | // Ensure the user exists in persistence |
138 | 138 | if (null === $user) { |
139 | - return $this->redirectToRoute('homepage'); |
|
139 | + return $this->redirectToRoute('homepage'); |
|
140 | 140 | } |
141 | 141 | // validate email confirmation link, sets User::isVerified=true and persists |
142 | 142 | try { |
143 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
143 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
144 | 144 | } catch (VerifyEmailExceptionInterface $exception) { |
145 | - $this->addFlash('verify_email_error', $exception->getReason()); |
|
145 | + $this->addFlash('verify_email_error', $exception->getReason()); |
|
146 | 146 | |
147 | - return $this->redirectToRoute('homepage'); |
|
147 | + return $this->redirectToRoute('homepage'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $guardHandler->authenticateUserAndHandleSuccess( |
@@ -157,63 +157,63 @@ discard block |
||
157 | 157 | $this->addFlash('success', 'The user has been created successfully.'); |
158 | 158 | |
159 | 159 | return $this->redirectToRoute('swp_user_registration_confirmed'); |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Tell the user his account is now confirmed. |
|
164 | - */ |
|
165 | - public function confirmedAction(Request $request) { |
|
162 | + /** |
|
163 | + * Tell the user his account is now confirmed. |
|
164 | + */ |
|
165 | + public function confirmedAction(Request $request) { |
|
166 | 166 | $user = $this->getUser(); |
167 | 167 | if (!is_object($user) || !$user instanceof UserInterface) { |
168 | - $this->createAccessDeniedException('This user does not have access to this section.'); |
|
168 | + $this->createAccessDeniedException('This user does not have access to this section.'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $this->render('@SWPUser/Registration/confirmed.html.twig', [ |
172 | 172 | 'user' => $user, |
173 | 173 | ]); |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @throws NotFoundHttpException |
|
178 | - */ |
|
179 | - private function ensureThatRegistrationIsEnabled() { |
|
176 | + /** |
|
177 | + * @throws NotFoundHttpException |
|
178 | + */ |
|
179 | + private function ensureThatRegistrationIsEnabled() { |
|
180 | 180 | $settingName = 'registration_enabled'; |
181 | 181 | $setting = $this->settingsManager->getOneSettingByName($settingName); |
182 | 182 | $registrationEnabled = $this->settingsManager |
183 | 183 | ->get($settingName, $setting['scope'], $this->scopeContext->getScopeOwner($setting['scope'])); |
184 | 184 | if (!$registrationEnabled) { |
185 | - throw new NotFoundHttpException('Registration is disabled.'); |
|
185 | + throw new NotFoundHttpException('Registration is disabled.'); |
|
186 | + } |
|
186 | 187 | } |
187 | - } |
|
188 | 188 | |
189 | - private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
189 | + private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
190 | 190 | // Verify the user id exists and is not null |
191 | 191 | if (null === $id) { |
192 | - return new JsonResponse( |
|
193 | - ['error' => 'User does not exist'] |
|
194 | - ); |
|
192 | + return new JsonResponse( |
|
193 | + ['error' => 'User does not exist'] |
|
194 | + ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | $user = $this->userManager->find($id); |
198 | 198 | |
199 | 199 | // Ensure the user exists in persistence |
200 | 200 | if (null === $user) { |
201 | - return new JsonResponse( |
|
202 | - ['error' => 'User does not exist'] |
|
203 | - ); |
|
201 | + return new JsonResponse( |
|
202 | + ['error' => 'User does not exist'] |
|
203 | + ); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // validate email confirmation link, sets User::isVerified=true and persists |
207 | 207 | try { |
208 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
208 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
209 | 209 | } catch (VerifyEmailExceptionInterface $exception) { |
210 | - return new JsonResponse( |
|
211 | - ['error' => 'Registration confirmation invalid'] |
|
212 | - ); |
|
210 | + return new JsonResponse( |
|
211 | + ['error' => 'Registration confirmation invalid'] |
|
212 | + ); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return new JsonResponse( |
216 | 216 | ['message' => 'The user has been created successfully.'] |
217 | 217 | ); |
218 | - } |
|
218 | + } |
|
219 | 219 | } |
@@ -32,44 +32,44 @@ discard block |
||
32 | 32 | |
33 | 33 | class ProfileController extends AbstractController { |
34 | 34 | |
35 | - private EntityManagerInterface $entityManager; |
|
36 | - private AuthorizationCheckerInterface $authorizationChecker; |
|
37 | - private UserRepository $userRepository; |
|
38 | - |
|
39 | - /** |
|
40 | - * @param EntityManagerInterface $entityManager |
|
41 | - * @param AuthorizationCheckerInterface $authorizationChecker |
|
42 | - * @param UserRepository $userRepository |
|
43 | - */ |
|
44 | - public function __construct(EntityManagerInterface $entityManager, |
|
45 | - AuthorizationCheckerInterface $authorizationChecker, UserRepository $userRepository) { |
|
35 | + private EntityManagerInterface $entityManager; |
|
36 | + private AuthorizationCheckerInterface $authorizationChecker; |
|
37 | + private UserRepository $userRepository; |
|
38 | + |
|
39 | + /** |
|
40 | + * @param EntityManagerInterface $entityManager |
|
41 | + * @param AuthorizationCheckerInterface $authorizationChecker |
|
42 | + * @param UserRepository $userRepository |
|
43 | + */ |
|
44 | + public function __construct(EntityManagerInterface $entityManager, |
|
45 | + AuthorizationCheckerInterface $authorizationChecker, UserRepository $userRepository) { |
|
46 | 46 | $this->entityManager = $entityManager; |
47 | 47 | $this->authorizationChecker = $authorizationChecker; |
48 | 48 | $this->userRepository = $userRepository; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
54 | - */ |
|
55 | - public function getAction($id) { |
|
52 | + /** |
|
53 | + * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
54 | + */ |
|
55 | + public function getAction($id) { |
|
56 | 56 | $requestedUser = $this->userRepository->find($id); |
57 | 57 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
58 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
58 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $this->checkIfCanAccess($requestedUser); |
62 | 62 | |
63 | 63 | return new SingleResourceResponse($requestedUser); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
68 | - */ |
|
69 | - public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
66 | + /** |
|
67 | + * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
68 | + */ |
|
69 | + public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
70 | 70 | $requestedUser = $this->userRepository->find($id); |
71 | 71 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
72 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
72 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->checkIfCanAccess($requestedUser); |
@@ -80,32 +80,32 @@ discard block |
||
80 | 80 | $form->handleRequest($request); |
81 | 81 | |
82 | 82 | if ($form->isSubmitted() && $form->isValid()) { |
83 | - if (!empty($form->get('plainPassword')->getData())) { |
|
83 | + if (!empty($form->get('plainPassword')->getData())) { |
|
84 | 84 | $requestedUser->setPassword( |
85 | 85 | $passwordEncoder->encodePassword( |
86 | 86 | $requestedUser, |
87 | 87 | $form->get('plainPassword')->getData() |
88 | 88 | ) |
89 | 89 | ); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - $entityManager = $this->entityManager; |
|
93 | - $entityManager->flush(); |
|
92 | + $entityManager = $this->entityManager; |
|
93 | + $entityManager->flush(); |
|
94 | 94 | |
95 | - return new SingleResourceResponse($requestedUser); |
|
95 | + return new SingleResourceResponse($requestedUser); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return new SingleResourceResponse($form, new ResponseContext(400)); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - private function checkIfCanAccess($requestedUser) { |
|
101 | + private function checkIfCanAccess($requestedUser) { |
|
102 | 102 | /** @var UserInterface $currentUser */ |
103 | 103 | $currentUser = $this->getUser(); |
104 | 104 | if ( |
105 | 105 | !$this->authorizationChecker->isGranted('ROLE_ADMIN') && |
106 | 106 | $requestedUser->getId() !== $currentUser->getId() |
107 | 107 | ) { |
108 | - throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
108 | + throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
109 | + } |
|
109 | 110 | } |
110 | - } |
|
111 | 111 | } |
@@ -24,33 +24,33 @@ discard block |
||
24 | 24 | * Class OrganizationAwareThemeUploader. |
25 | 25 | */ |
26 | 26 | final class OrganizationAwareThemeUploader implements ThemeUploaderInterface { |
27 | - /** |
|
28 | - * @var TenantContextInterface |
|
29 | - */ |
|
30 | - private $tenantContext; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - private $baseDir; |
|
36 | - |
|
37 | - /** |
|
38 | - * OrganizationAwareThemeUploader constructor. |
|
39 | - * |
|
40 | - * @param TenantContextInterface $tenantContext |
|
41 | - * @param string $baseDir |
|
42 | - */ |
|
43 | - public function __construct(TenantContextInterface $tenantContext, string $baseDir) { |
|
27 | + /** |
|
28 | + * @var TenantContextInterface |
|
29 | + */ |
|
30 | + private $tenantContext; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + private $baseDir; |
|
36 | + |
|
37 | + /** |
|
38 | + * OrganizationAwareThemeUploader constructor. |
|
39 | + * |
|
40 | + * @param TenantContextInterface $tenantContext |
|
41 | + * @param string $baseDir |
|
42 | + */ |
|
43 | + public function __construct(TenantContextInterface $tenantContext, string $baseDir) { |
|
44 | 44 | $this->tenantContext = $tenantContext; |
45 | 45 | $this->baseDir = $baseDir; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function upload(UploadedFile $file) { |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function upload(UploadedFile $file) { |
|
52 | 52 | if (null === $this->tenantContext->getTenant()) { |
53 | - throw new \Exception('Tenant was not found in context!'); |
|
53 | + throw new \Exception('Tenant was not found in context!'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | $destinationFolder = $this->getAvailableThemesPath(); |
@@ -59,48 +59,48 @@ discard block |
||
59 | 59 | |
60 | 60 | $zip = new \ZipArchive(); |
61 | 61 | if (true === $zip->open($filePath)) { |
62 | - if (!$filesystem->exists($destinationFolder)) { |
|
62 | + if (!$filesystem->exists($destinationFolder)) { |
|
63 | 63 | $filesystem->mkdir($destinationFolder); |
64 | - } |
|
65 | - $pathInArray = explode('/', $zip->getNameIndex(0)); |
|
66 | - $themeDirInZip = array_shift($pathInArray); |
|
64 | + } |
|
65 | + $pathInArray = explode('/', $zip->getNameIndex(0)); |
|
66 | + $themeDirInZip = array_shift($pathInArray); |
|
67 | 67 | |
68 | - $themeConfiguration = $zip->getFromName($themeDirInZip . DIRECTORY_SEPARATOR . 'theme.json'); |
|
69 | - if (false === $themeConfiguration) { |
|
68 | + $themeConfiguration = $zip->getFromName($themeDirInZip . DIRECTORY_SEPARATOR . 'theme.json'); |
|
69 | + if (false === $themeConfiguration) { |
|
70 | 70 | throw new \Exception('In ZIP file we expect one directory and theme.json file inside'); |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - $themeConfiguration = \json_decode($themeConfiguration, true); |
|
74 | - if (\JSON_ERROR_NONE !== json_last_error()) { |
|
73 | + $themeConfiguration = \json_decode($themeConfiguration, true); |
|
74 | + if (\JSON_ERROR_NONE !== json_last_error()) { |
|
75 | 75 | throw new \Exception('Theme configuration is not valid. Syntax error in theme.json'); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - $themeName = $themeConfiguration['name']; |
|
79 | - $unpackedThemePath = $destinationFolder . DIRECTORY_SEPARATOR . $themeDirInZip; |
|
78 | + $themeName = $themeConfiguration['name']; |
|
79 | + $unpackedThemePath = $destinationFolder . DIRECTORY_SEPARATOR . $themeDirInZip; |
|
80 | 80 | |
81 | - if ($filesystem->exists($unpackedThemePath)) { |
|
81 | + if ($filesystem->exists($unpackedThemePath)) { |
|
82 | 82 | $filesystem->remove($unpackedThemePath); |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - $zip->extractTo($destinationFolder); |
|
86 | - $zip->close(); |
|
85 | + $zip->extractTo($destinationFolder); |
|
86 | + $zip->close(); |
|
87 | 87 | |
88 | - $finalPath = $destinationFolder . DIRECTORY_SEPARATOR . str_replace('/', '__', $themeName); |
|
89 | - $filesystem->rename($unpackedThemePath, $finalPath, true); |
|
88 | + $finalPath = $destinationFolder . DIRECTORY_SEPARATOR . str_replace('/', '__', $themeName); |
|
89 | + $filesystem->rename($unpackedThemePath, $finalPath, true); |
|
90 | 90 | |
91 | - return $finalPath; |
|
91 | + return $finalPath; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return false; |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getAvailableThemesPath() { |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getAvailableThemesPath() { |
|
101 | 101 | $tenant = $this->tenantContext->getTenant(); |
102 | 102 | $organization = $tenant->getOrganization(); |
103 | 103 | $organizationCode = $organization->getCode(); |
104 | 104 | return sprintf($this->baseDir . DIRECTORY_SEPARATOR . ThemeUploaderInterface::AVAILABLE_THEMES_PATH, $organizationCode); |
105 | - } |
|
105 | + } |
|
106 | 106 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $pathInArray = explode('/', $zip->getNameIndex(0)); |
66 | 66 | $themeDirInZip = array_shift($pathInArray); |
67 | 67 | |
68 | - $themeConfiguration = $zip->getFromName($themeDirInZip . DIRECTORY_SEPARATOR . 'theme.json'); |
|
68 | + $themeConfiguration = $zip->getFromName($themeDirInZip.DIRECTORY_SEPARATOR.'theme.json'); |
|
69 | 69 | if (false === $themeConfiguration) { |
70 | 70 | throw new \Exception('In ZIP file we expect one directory and theme.json file inside'); |
71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | $themeName = $themeConfiguration['name']; |
79 | - $unpackedThemePath = $destinationFolder . DIRECTORY_SEPARATOR . $themeDirInZip; |
|
79 | + $unpackedThemePath = $destinationFolder.DIRECTORY_SEPARATOR.$themeDirInZip; |
|
80 | 80 | |
81 | 81 | if ($filesystem->exists($unpackedThemePath)) { |
82 | 82 | $filesystem->remove($unpackedThemePath); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $zip->extractTo($destinationFolder); |
86 | 86 | $zip->close(); |
87 | 87 | |
88 | - $finalPath = $destinationFolder . DIRECTORY_SEPARATOR . str_replace('/', '__', $themeName); |
|
88 | + $finalPath = $destinationFolder.DIRECTORY_SEPARATOR.str_replace('/', '__', $themeName); |
|
89 | 89 | $filesystem->rename($unpackedThemePath, $finalPath, true); |
90 | 90 | |
91 | 91 | return $finalPath; |
@@ -101,6 +101,6 @@ discard block |
||
101 | 101 | $tenant = $this->tenantContext->getTenant(); |
102 | 102 | $organization = $tenant->getOrganization(); |
103 | 103 | $organizationCode = $organization->getCode(); |
104 | - return sprintf($this->baseDir . DIRECTORY_SEPARATOR . ThemeUploaderInterface::AVAILABLE_THEMES_PATH, $organizationCode); |
|
104 | + return sprintf($this->baseDir.DIRECTORY_SEPARATOR.ThemeUploaderInterface::AVAILABLE_THEMES_PATH, $organizationCode); |
|
105 | 105 | } |
106 | 106 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $this->dispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
51 | 51 | |
52 | 52 | $this->resolvedTenants[self::getCacheKey( |
53 | - $tenant->getSubdomain() ? $tenant->getSubdomain() . '.' . $tenant->getDomainName() : $tenant->getDomainName() |
|
53 | + $tenant->getSubdomain() ? $tenant->getSubdomain().'.'.$tenant->getDomainName() : $tenant->getDomainName() |
|
54 | 54 | )] = $tenant; |
55 | 55 | } |
56 | 56 | |
@@ -60,6 +60,6 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | private static function getCacheKey(string $host): string { |
63 | - return md5('tenant_cache__' . $host); |
|
63 | + return md5('tenant_cache__'.$host); |
|
64 | 64 | } |
65 | 65 | } |
@@ -24,43 +24,43 @@ |
||
24 | 24 | use SWP\Component\MultiTenancy\Model\TenantInterface; |
25 | 25 | |
26 | 26 | class CachedTenantContext extends TenantContext implements CachedTenantContextInterface { |
27 | - private $resolvedTenants = []; |
|
27 | + private $resolvedTenants = []; |
|
28 | 28 | |
29 | - public function getTenant(): ?TenantInterface { |
|
29 | + public function getTenant(): ?TenantInterface { |
|
30 | 30 | $currentRequest = $this->requestStack->getCurrentRequest(); |
31 | 31 | if ($currentRequest && $this->requestStack->getCurrentRequest()->attributes->get('exception') instanceof TenantNotFoundException) { |
32 | - return null; |
|
32 | + return null; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if ($currentRequest === null) { |
36 | - return $this->tenant; |
|
36 | + return $this->tenant; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $cacheKey = self::getCacheKey($currentRequest->getHost()); |
40 | 40 | if (!array_key_exists($cacheKey, $this->resolvedTenants) || $this->resolvedTenants[$cacheKey] instanceof TenantInterface) { |
41 | - $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
41 | + $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
42 | 42 | } else { |
43 | - $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
43 | + $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $this->tenant; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public function setTenant(TenantInterface $tenant): void { |
|
49 | + public function setTenant(TenantInterface $tenant): void { |
|
50 | 50 | parent::setTenant($tenant); |
51 | 51 | $this->dispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
52 | 52 | |
53 | 53 | $this->resolvedTenants[self::getCacheKey( |
54 | 54 | $tenant->getSubdomain() ? $tenant->getSubdomain() . '.' . $tenant->getDomainName() : $tenant->getDomainName() |
55 | 55 | )] = $tenant; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - public function reset(): void { |
|
58 | + public function reset(): void { |
|
59 | 59 | $this->tenant = null; |
60 | 60 | $this->resolvedTenants = []; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - private static function getCacheKey(string $host): string { |
|
63 | + private static function getCacheKey(string $host): string { |
|
64 | 64 | return md5('tenant_cache__' . $host); |
65 | - } |
|
65 | + } |
|
66 | 66 | } |
@@ -22,10 +22,10 @@ |
||
22 | 22 | class ContentController extends AbstractController |
23 | 23 | { |
24 | 24 | |
25 | - public function __construct() { |
|
26 | - } |
|
25 | + public function __construct() { |
|
26 | + } |
|
27 | 27 | |
28 | - public function renderPageAction(string $contentTemplate): Response |
|
28 | + public function renderPageAction(string $contentTemplate): Response |
|
29 | 29 | { |
30 | 30 | $response = new Response(); |
31 | 31 | $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | use FOS\RestBundle\Controller\Annotations\Route; |
27 | 27 | |
28 | 28 | class AuthorSearchController extends AbstractController { |
29 | - private RepositoryManagerInterface $repositoryManager; |
|
30 | - private PaginatorInterface $paginator; |
|
31 | - private string $authorClassName; |
|
29 | + private RepositoryManagerInterface $repositoryManager; |
|
30 | + private PaginatorInterface $paginator; |
|
31 | + private string $authorClassName; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param RepositoryManagerInterface $repositoryManager |
|
35 | - * @param PaginatorInterface $paginator |
|
36 | - * @param string $authorClassName |
|
37 | - */ |
|
38 | - public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator, |
|
39 | - string $authorClassName) { |
|
33 | + /** |
|
34 | + * @param RepositoryManagerInterface $repositoryManager |
|
35 | + * @param PaginatorInterface $paginator |
|
36 | + * @param string $authorClassName |
|
37 | + */ |
|
38 | + public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator, |
|
39 | + string $authorClassName) { |
|
40 | 40 | $this->repositoryManager = $repositoryManager; |
41 | 41 | $this->paginator = $paginator; |
42 | 42 | $this->authorClassName = $authorClassName; |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors") |
|
48 | - */ |
|
49 | - public function searchAction(Request $request): ResourcesListResponse { |
|
46 | + /** |
|
47 | + * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors") |
|
48 | + */ |
|
49 | + public function searchAction(Request $request): ResourcesListResponse { |
|
50 | 50 | $criteria = Criteria::fromQueryParameters( |
51 | 51 | $request->query->get('term', ''), |
52 | 52 | [ |
@@ -87,5 +87,5 @@ discard block |
||
87 | 87 | ); |
88 | 88 | |
89 | 89 | return new ResourcesListResponse($pagination, $responseContext); |
90 | - } |
|
90 | + } |
|
91 | 91 | } |
@@ -29,28 +29,28 @@ discard block |
||
29 | 29 | use FOS\RestBundle\Controller\Annotations\Route; |
30 | 30 | |
31 | 31 | class SlideshowController extends Controller { |
32 | - private ArticleRepositoryInterface $articleRepository; |
|
33 | - private SlideshowRepositoryInterface $slideshowRepository; |
|
34 | - private EventDispatcherInterface $eventDispatcher; |
|
32 | + private ArticleRepositoryInterface $articleRepository; |
|
33 | + private SlideshowRepositoryInterface $slideshowRepository; |
|
34 | + private EventDispatcherInterface $eventDispatcher; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param ArticleRepositoryInterface $articleRepository |
|
38 | - * @param SlideshowRepositoryInterface $slideshowRepository |
|
39 | - * @param EventDispatcherInterface $eventDispatcher |
|
40 | - */ |
|
41 | - public function __construct(ArticleRepositoryInterface $articleRepository, |
|
42 | - SlideshowRepositoryInterface $slideshowRepository, |
|
43 | - EventDispatcherInterface $eventDispatcher) { |
|
36 | + /** |
|
37 | + * @param ArticleRepositoryInterface $articleRepository |
|
38 | + * @param SlideshowRepositoryInterface $slideshowRepository |
|
39 | + * @param EventDispatcherInterface $eventDispatcher |
|
40 | + */ |
|
41 | + public function __construct(ArticleRepositoryInterface $articleRepository, |
|
42 | + SlideshowRepositoryInterface $slideshowRepository, |
|
43 | + EventDispatcherInterface $eventDispatcher) { |
|
44 | 44 | $this->articleRepository = $articleRepository; |
45 | 45 | $this->slideshowRepository = $slideshowRepository; |
46 | 46 | $this->eventDispatcher = $eventDispatcher; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @Route("/api/{version}/content/slideshows/{articleId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_slideshows_list") |
|
52 | - */ |
|
53 | - public function listAction(Request $request, string $articleId): ResourcesListResponseInterface { |
|
50 | + /** |
|
51 | + * @Route("/api/{version}/content/slideshows/{articleId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_slideshows_list") |
|
52 | + */ |
|
53 | + public function listAction(Request $request, string $articleId): ResourcesListResponseInterface { |
|
54 | 54 | $repository = $this->slideshowRepository; |
55 | 55 | |
56 | 56 | $article = $this->findArticleOr404($articleId); |
@@ -60,29 +60,29 @@ discard block |
||
60 | 60 | ]), $request->query->all('sorting'), new PaginationData($request)); |
61 | 61 | |
62 | 62 | return new ResourcesListResponse($slideshows); |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @Route("/api/{version}/content/slideshows/{articleId}/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_get_slideshow", requirements={"id"="\d+"}) |
|
67 | - */ |
|
68 | - public function getAction($id, string $articleId): SingleResourceResponseInterface { |
|
65 | + /** |
|
66 | + * @Route("/api/{version}/content/slideshows/{articleId}/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_get_slideshow", requirements={"id"="\d+"}) |
|
67 | + */ |
|
68 | + public function getAction($id, string $articleId): SingleResourceResponseInterface { |
|
69 | 69 | $article = $this->findArticleOr404($articleId); |
70 | 70 | |
71 | 71 | if (null === $list = $this->slideshowRepository->findOneBy([ |
72 | 72 | 'id' => $id, |
73 | 73 | 'article' => $article, |
74 | 74 | ])) { |
75 | - throw new NotFoundHttpException(sprintf('Slideshow with id "%s" was not found.', $id)); |
|
75 | + throw new NotFoundHttpException(sprintf('Slideshow with id "%s" was not found.', $id)); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return new SingleResourceResponse($list); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - private function findArticleOr404($id) { |
|
81 | + private function findArticleOr404($id) { |
|
82 | 82 | if (null === $article = $this->articleRepository->findOneById($id)) { |
83 | - throw new NotFoundHttpException(sprintf('Article with id "%s" was not found.', $id)); |
|
83 | + throw new NotFoundHttpException(sprintf('Article with id "%s" was not found.', $id)); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return $article; |
87 | - } |
|
87 | + } |
|
88 | 88 | } |