@@ -34,87 +34,87 @@ discard block |
||
34 | 34 | use SWP\Component\Common\Exception\UnexpectedTypeException; |
35 | 35 | |
36 | 36 | final class DownloadArticleAuthorAvatarListener { |
37 | - /** |
|
38 | - * @var MediaManagerInterface |
|
39 | - */ |
|
40 | - private $authorMediaManager; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EntityManagerInterface |
|
44 | - */ |
|
45 | - private $entityManager; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $cacheDirectory; |
|
51 | - |
|
52 | - public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) { |
|
37 | + /** |
|
38 | + * @var MediaManagerInterface |
|
39 | + */ |
|
40 | + private $authorMediaManager; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EntityManagerInterface |
|
44 | + */ |
|
45 | + private $entityManager; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $cacheDirectory; |
|
51 | + |
|
52 | + public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) { |
|
53 | 53 | $this->entityManager = $entityManager; |
54 | 54 | $this->cacheDirectory = $cacheDirectory; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param MediaManagerInterface $authorMediaManager |
|
59 | - */ |
|
60 | - public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) { |
|
57 | + /** |
|
58 | + * @param MediaManagerInterface $authorMediaManager |
|
59 | + */ |
|
60 | + public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) { |
|
61 | 61 | $this->authorMediaManager = $authorMediaManager; |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param GenericEvent $event |
|
66 | - */ |
|
67 | - public function processAuthors(GenericEvent $event): void { |
|
64 | + /** |
|
65 | + * @param GenericEvent $event |
|
66 | + */ |
|
67 | + public function processAuthors(GenericEvent $event): void { |
|
68 | 68 | $package = $event->getSubject(); |
69 | 69 | |
70 | 70 | if (!$package instanceof PackageInterface) { |
71 | - throw new UnexpectedTypeException($package, PackageInterface::class); |
|
71 | + throw new UnexpectedTypeException($package, PackageInterface::class); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $authors = []; |
75 | 75 | /** @var ArticleAuthorInterface $packageAuthor */ |
76 | 76 | foreach ($package->getAuthors() as $packageAuthor) { |
77 | - $authors[] = $this->handle($packageAuthor); |
|
77 | + $authors[] = $this->handle($packageAuthor); |
|
78 | 78 | } |
79 | 79 | $package->setAuthors(new ArrayCollection($authors)); |
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param ArticleAuthorInterface $object |
|
84 | - * |
|
85 | - * @return ArticleAuthorInterface |
|
86 | - */ |
|
87 | - private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface { |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param ArticleAuthorInterface $object |
|
84 | + * |
|
85 | + * @return ArticleAuthorInterface |
|
86 | + */ |
|
87 | + private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface { |
|
88 | 88 | if (null !== $object->getAvatarUrl()) { |
89 | - $filesystem = new Filesystem(); |
|
90 | - $pathParts = \pathinfo($object->getAvatarUrl()); |
|
91 | - $assetId = \sha1($pathParts['filename']); |
|
92 | - if (null !== $object->getSlug()) { |
|
89 | + $filesystem = new Filesystem(); |
|
90 | + $pathParts = \pathinfo($object->getAvatarUrl()); |
|
91 | + $assetId = \sha1($pathParts['filename']); |
|
92 | + if (null !== $object->getSlug()) { |
|
93 | 93 | $assetId = $object->getSlug() . '_' . $assetId; |
94 | - } |
|
95 | - $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]); |
|
96 | - if (\count($existingAvatar) > 0) { |
|
94 | + } |
|
95 | + $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]); |
|
96 | + if (\count($existingAvatar) > 0) { |
|
97 | 97 | $object->setAvatarUrl((string)\reset($existingAvatar)); |
98 | 98 | |
99 | 99 | return $object; |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - try { |
|
102 | + try { |
|
103 | 103 | $tempDirectory = $this->cacheDirectory . \DIRECTORY_SEPARATOR . 'downloaded_avatars'; |
104 | 104 | $tempLocation = $tempDirectory . \DIRECTORY_SEPARATOR . \sha1($assetId . date('his')); |
105 | 105 | if (!$filesystem->exists($tempDirectory)) { |
106 | - $filesystem->mkdir($tempDirectory); |
|
106 | + $filesystem->mkdir($tempDirectory); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $avatarUrl = $object->getAvatarUrl(); |
110 | 110 | if (strpos($avatarUrl, "http://") === 0 || strpos($avatarUrl, "https://") === 0) { |
111 | - self::downloadFile($avatarUrl, $tempLocation); |
|
111 | + self::downloadFile($avatarUrl, $tempLocation); |
|
112 | 112 | } else { |
113 | - $file = \file_get_contents($avatarUrl); |
|
114 | - if (false === $file) { |
|
113 | + $file = \file_get_contents($avatarUrl); |
|
114 | + if (false === $file) { |
|
115 | 115 | throw new \Exception('File can\'t be downloaded'); |
116 | - } |
|
117 | - $filesystem->dumpFile($tempLocation, $file); |
|
116 | + } |
|
117 | + $filesystem->dumpFile($tempLocation, $file); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $uploadedFile = new UploadedFile($tempLocation, |
@@ -123,29 +123,29 @@ discard block |
||
123 | 123 | \filesize($tempLocation), |
124 | 124 | true |
125 | 125 | ); |
126 | - } catch (\Exception $e) { |
|
126 | + } catch (\Exception $e) { |
|
127 | 127 | return $object; |
128 | - } |
|
129 | - /** @var Image $image */ |
|
130 | - $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId); |
|
131 | - $avatar = $this->createAuthorMedia($object, $image); |
|
132 | - $this->entityManager->persist($avatar); |
|
133 | - $this->entityManager->persist($image); |
|
134 | - |
|
135 | - $object->setAvatar($avatar); |
|
136 | - $object->setAvatarUrl((string)$image); |
|
128 | + } |
|
129 | + /** @var Image $image */ |
|
130 | + $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId); |
|
131 | + $avatar = $this->createAuthorMedia($object, $image); |
|
132 | + $this->entityManager->persist($avatar); |
|
133 | + $this->entityManager->persist($image); |
|
134 | + |
|
135 | + $object->setAvatar($avatar); |
|
136 | + $object->setAvatarUrl((string)$image); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $object; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface { |
|
142 | + private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface { |
|
143 | 143 | return new AuthorMedia('avatar', $articleAuthor, $image); |
144 | - } |
|
144 | + } |
|
145 | 145 | |
146 | - private static function downloadFile($url, $location) { |
|
146 | + private static function downloadFile($url, $location) { |
|
147 | 147 | $handlerStack = HandlerStack::create(new CurlHandler()); |
148 | 148 | $client = new Client(['handler' => $handlerStack]); |
149 | 149 | $client->request('GET', $url, ['sink' => $location]); |
150 | - } |
|
150 | + } |
|
151 | 151 | } |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | $pathParts = \pathinfo($object->getAvatarUrl()); |
91 | 91 | $assetId = \sha1($pathParts['filename']); |
92 | 92 | if (null !== $object->getSlug()) { |
93 | - $assetId = $object->getSlug() . '_' . $assetId; |
|
93 | + $assetId = $object->getSlug().'_'.$assetId; |
|
94 | 94 | } |
95 | 95 | $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]); |
96 | 96 | if (\count($existingAvatar) > 0) { |
97 | - $object->setAvatarUrl((string)\reset($existingAvatar)); |
|
97 | + $object->setAvatarUrl((string) \reset($existingAvatar)); |
|
98 | 98 | |
99 | 99 | return $object; |
100 | 100 | } |
101 | 101 | |
102 | 102 | try { |
103 | - $tempDirectory = $this->cacheDirectory . \DIRECTORY_SEPARATOR . 'downloaded_avatars'; |
|
104 | - $tempLocation = $tempDirectory . \DIRECTORY_SEPARATOR . \sha1($assetId . date('his')); |
|
103 | + $tempDirectory = $this->cacheDirectory.\DIRECTORY_SEPARATOR.'downloaded_avatars'; |
|
104 | + $tempLocation = $tempDirectory.\DIRECTORY_SEPARATOR.\sha1($assetId.date('his')); |
|
105 | 105 | if (!$filesystem->exists($tempDirectory)) { |
106 | 106 | $filesystem->mkdir($tempDirectory); |
107 | 107 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $this->entityManager->persist($image); |
134 | 134 | |
135 | 135 | $object->setAvatar($avatar); |
136 | - $object->setAvatarUrl((string)$image); |
|
136 | + $object->setAvatarUrl((string) $image); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $object; |
@@ -36,88 +36,88 @@ discard block |
||
36 | 36 | * @Route("/reset-password") |
37 | 37 | */ |
38 | 38 | class ResetPasswordController extends AbstractController { |
39 | - use ResetPasswordControllerTrait; |
|
39 | + use ResetPasswordControllerTrait; |
|
40 | 40 | |
41 | - private ResetPasswordHelperInterface $resetPasswordHelper; |
|
42 | - private EntityManagerInterface $entityManager; |
|
41 | + private ResetPasswordHelperInterface $resetPasswordHelper; |
|
42 | + private EntityManagerInterface $entityManager; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param ResetPasswordHelperInterface $resetPasswordHelper |
|
46 | - * @param EntityManagerInterface $entityManager |
|
47 | - */ |
|
48 | - public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, |
|
49 | - EntityManagerInterface $entityManager) { |
|
44 | + /** |
|
45 | + * @param ResetPasswordHelperInterface $resetPasswordHelper |
|
46 | + * @param EntityManagerInterface $entityManager |
|
47 | + */ |
|
48 | + public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, |
|
49 | + EntityManagerInterface $entityManager) { |
|
50 | 50 | $this->resetPasswordHelper = $resetPasswordHelper; |
51 | 51 | $this->entityManager = $entityManager; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Display & process form to request a password reset. |
|
57 | - * |
|
58 | - * @Route("", name="swp_user_forgot_password_request") |
|
59 | - */ |
|
60 | - public function request(Request $request, MailerInterface $mailer): Response { |
|
55 | + /** |
|
56 | + * Display & process form to request a password reset. |
|
57 | + * |
|
58 | + * @Route("", name="swp_user_forgot_password_request") |
|
59 | + */ |
|
60 | + public function request(Request $request, MailerInterface $mailer): Response { |
|
61 | 61 | $form = $this->createForm(ResetPasswordRequestFormType::class); |
62 | 62 | $form->handleRequest($request); |
63 | 63 | |
64 | 64 | if ($form->isSubmitted() && $form->isValid()) { |
65 | - return $this->processSendingPasswordResetEmail( |
|
66 | - $form->get('email')->getData(), |
|
67 | - $mailer |
|
68 | - ); |
|
65 | + return $this->processSendingPasswordResetEmail( |
|
66 | + $form->get('email')->getData(), |
|
67 | + $mailer |
|
68 | + ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | return $this->render('@SWPUser/reset_password/request.html.twig', [ |
72 | 72 | 'requestForm' => $form->createView(), |
73 | 73 | ]); |
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Confirmation page after a user has requested a password reset. |
|
78 | - * |
|
79 | - * @Route("/check-email", name="swp_user_check_email") |
|
80 | - */ |
|
81 | - public function checkEmail(): Response { |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Confirmation page after a user has requested a password reset. |
|
78 | + * |
|
79 | + * @Route("/check-email", name="swp_user_check_email") |
|
80 | + */ |
|
81 | + public function checkEmail(): Response { |
|
82 | 82 | // We prevent users from directly accessing this page |
83 | 83 | if (!$this->canCheckEmail()) { |
84 | - return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
84 | + return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $this->render('@SWPUser/reset_password/check_email.html.twig', [ |
88 | 88 | 'tokenLifetime' => $this->resetPasswordHelper->getTokenLifetime(), |
89 | 89 | ]); |
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Validates and process the reset URL that the user clicked in their email. |
|
94 | - * |
|
95 | - * @Route("/reset/{token}", name="swp_user_reset_password") |
|
96 | - */ |
|
97 | - public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Validates and process the reset URL that the user clicked in their email. |
|
94 | + * |
|
95 | + * @Route("/reset/{token}", name="swp_user_reset_password") |
|
96 | + */ |
|
97 | + public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, |
|
98 | 98 | string $token = null): Response { |
99 | 99 | if ($token) { |
100 | - // We store the token in session and remove it from the URL, to avoid the URL being |
|
101 | - // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
|
102 | - $this->storeTokenInSession($token); |
|
100 | + // We store the token in session and remove it from the URL, to avoid the URL being |
|
101 | + // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
|
102 | + $this->storeTokenInSession($token); |
|
103 | 103 | |
104 | - return $this->redirectToRoute('swp_user_reset_password'); |
|
104 | + return $this->redirectToRoute('swp_user_reset_password'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $token = $this->getTokenFromSession(); |
108 | 108 | if (null === $token) { |
109 | - throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
|
109 | + throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | try { |
113 | - $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
|
113 | + $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
|
114 | 114 | } catch (ResetPasswordExceptionInterface $e) { |
115 | - $this->addFlash('reset_password_error', sprintf( |
|
116 | - 'There was a problem validating your reset request - %s', |
|
117 | - $e->getReason() |
|
118 | - )); |
|
115 | + $this->addFlash('reset_password_error', sprintf( |
|
116 | + 'There was a problem validating your reset request - %s', |
|
117 | + $e->getReason() |
|
118 | + )); |
|
119 | 119 | |
120 | - return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
120 | + return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | // The token is valid; allow the user to change their password. |
@@ -125,30 +125,30 @@ discard block |
||
125 | 125 | $form->handleRequest($request); |
126 | 126 | |
127 | 127 | if ($form->isSubmitted() && $form->isValid()) { |
128 | - // A password reset token should be used only once, remove it. |
|
129 | - $this->resetPasswordHelper->removeResetRequest($token); |
|
128 | + // A password reset token should be used only once, remove it. |
|
129 | + $this->resetPasswordHelper->removeResetRequest($token); |
|
130 | 130 | |
131 | - // Encode the plain password, and set it. |
|
132 | - $encodedPassword = $passwordEncoder->encodePassword( |
|
133 | - $user, |
|
134 | - $form->get('plainPassword')->getData() |
|
135 | - ); |
|
131 | + // Encode the plain password, and set it. |
|
132 | + $encodedPassword = $passwordEncoder->encodePassword( |
|
133 | + $user, |
|
134 | + $form->get('plainPassword')->getData() |
|
135 | + ); |
|
136 | 136 | |
137 | - $user->setPassword($encodedPassword); |
|
138 | - $this->entityManager->flush(); |
|
137 | + $user->setPassword($encodedPassword); |
|
138 | + $this->entityManager->flush(); |
|
139 | 139 | |
140 | - // The session is cleaned up after the password has been changed. |
|
141 | - $this->cleanSessionAfterReset(); |
|
140 | + // The session is cleaned up after the password has been changed. |
|
141 | + $this->cleanSessionAfterReset(); |
|
142 | 142 | |
143 | - return $this->redirectToRoute('homepage'); |
|
143 | + return $this->redirectToRoute('homepage'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return $this->render('@SWPUser/reset_password/reset.html.twig', [ |
147 | 147 | 'resetForm' => $form->createView(), |
148 | 148 | ]); |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | - private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse { |
|
151 | + private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse { |
|
152 | 152 | $user = $this->entityManager->getRepository(User::class)->findOneBy([ |
153 | 153 | 'email' => $emailFormData, |
154 | 154 | ]); |
@@ -158,22 +158,22 @@ discard block |
||
158 | 158 | |
159 | 159 | // Do not reveal whether a user account was found or not. |
160 | 160 | if (!$user) { |
161 | - return $this->redirectToRoute('swp_user_check_email'); |
|
161 | + return $this->redirectToRoute('swp_user_check_email'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | try { |
165 | - $resetToken = $this->resetPasswordHelper->generateResetToken($user); |
|
165 | + $resetToken = $this->resetPasswordHelper->generateResetToken($user); |
|
166 | 166 | } catch (ResetPasswordExceptionInterface $e) { |
167 | - $this->addFlash('reset_password_error', sprintf( |
|
168 | - 'There was a problem handling your password reset request - %s', |
|
169 | - $e->getReason() |
|
170 | - )); |
|
167 | + $this->addFlash('reset_password_error', sprintf( |
|
168 | + 'There was a problem handling your password reset request - %s', |
|
169 | + $e->getReason() |
|
170 | + )); |
|
171 | 171 | |
172 | - return $this->redirectToRoute('swp_user_check_email'); |
|
172 | + return $this->redirectToRoute('swp_user_check_email'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $mailer->sendResetPasswordEmail($user, $resetToken); |
176 | 176 | |
177 | 177 | return $this->redirectToRoute('swp_user_check_email'); |
178 | - } |
|
178 | + } |
|
179 | 179 | } |
@@ -86,7 +86,7 @@ |
||
86 | 86 | unset($server['HTTP_Authorization']); |
87 | 87 | } |
88 | 88 | |
89 | - if(!array_key_exists("HTTP_HOST", $server)) { |
|
89 | + if (!array_key_exists("HTTP_HOST", $server)) { |
|
90 | 90 | $server['HTTP_HOST'] = 'localhost'; |
91 | 91 | } |
92 | 92 |
@@ -23,71 +23,71 @@ discard block |
||
23 | 23 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
24 | 24 | |
25 | 25 | class WebTestCase extends BaseWebTestCase { |
26 | - protected ?AbstractDatabaseTool $databaseTool; |
|
27 | - private static ?KernelBrowser $client = null; |
|
26 | + protected ?AbstractDatabaseTool $databaseTool; |
|
27 | + private static ?KernelBrowser $client = null; |
|
28 | 28 | |
29 | - public function setUp(): void { |
|
29 | + public function setUp(): void { |
|
30 | 30 | if (self::$client == null) { |
31 | - self::$client = parent::createClient(); |
|
31 | + self::$client = parent::createClient(); |
|
32 | 32 | } |
33 | 33 | $this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get(); |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initializes database. |
|
38 | - */ |
|
39 | - protected function initDatabase() { |
|
36 | + /** |
|
37 | + * Initializes database. |
|
38 | + */ |
|
39 | + protected function initDatabase() { |
|
40 | 40 | $this->clearMetadataCache(); |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Clears metadata cache of the various cache drivers. |
|
45 | - */ |
|
46 | - private function clearMetadataCache() { |
|
43 | + /** |
|
44 | + * Clears metadata cache of the various cache drivers. |
|
45 | + */ |
|
46 | + private function clearMetadataCache() { |
|
47 | 47 | $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
48 | 48 | |
49 | 49 | $cacheDriver = $entityManager->getConfiguration()->getMetadataCacheImpl(); |
50 | 50 | |
51 | 51 | if (!$cacheDriver instanceof ArrayAdapter) { |
52 | - $cacheDriver->deleteAll(); |
|
52 | + $cacheDriver->deleteAll(); |
|
53 | + } |
|
53 | 54 | } |
54 | - } |
|
55 | 55 | |
56 | - protected function tearDown(): void { |
|
56 | + protected function tearDown(): void { |
|
57 | 57 | unset($this->databaseTool); |
58 | 58 | $reflection = new \ReflectionObject($this); |
59 | 59 | foreach ($reflection->getProperties() as $prop) { |
60 | - if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { |
|
60 | + if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { |
|
61 | 61 | $prop->setAccessible(true); |
62 | 62 | if ($prop->name == 'databaseTool') { |
63 | - continue; |
|
63 | + continue; |
|
64 | 64 | } |
65 | 65 | $prop->setValue($this, null); |
66 | - } |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | parent::tearDown(); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - protected function loadCustomFixtures(array $fixtures) { |
|
71 | + protected function loadCustomFixtures(array $fixtures) { |
|
72 | 72 | $env = $this->getContainer()->getParameter('test_env'); |
73 | 73 | |
74 | 74 | $registry = new FixtureRegistry(); |
75 | 75 | $registry->setEnvironment($env); |
76 | 76 | |
77 | 77 | return $this->databaseTool->loadFixtures($registry->getFixtures($fixtures))->getReferenceRepository(); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - public static function createClient(array $options = [], array $server = []) { |
|
80 | + public static function createClient(array $options = [], array $server = []) { |
|
81 | 81 | if (!array_key_exists('HTTP_Authorization', $server)) { |
82 | - $server['HTTP_Authorization'] = base64_encode('test_token:'); |
|
82 | + $server['HTTP_Authorization'] = base64_encode('test_token:'); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | if (null === $server['HTTP_Authorization']) { |
86 | - unset($server['HTTP_Authorization']); |
|
86 | + unset($server['HTTP_Authorization']); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | if(!array_key_exists("HTTP_HOST", $server)) { |
90 | - $server['HTTP_HOST'] = 'localhost'; |
|
90 | + $server['HTTP_HOST'] = 'localhost'; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $newClient = clone self::$client; |
@@ -95,5 +95,5 @@ discard block |
||
95 | 95 | $newClient->getKernel()->shutdown(); |
96 | 96 | $newClient->getKernel()->boot(); |
97 | 97 | return $newClient; |
98 | - } |
|
98 | + } |
|
99 | 99 | } |
@@ -28,62 +28,62 @@ |
||
28 | 28 | * Class TenantContext. |
29 | 29 | */ |
30 | 30 | class TenantContext implements TenantContextInterface { |
31 | - /** |
|
32 | - * @var TenantInterface |
|
33 | - */ |
|
34 | - protected $tenant; |
|
31 | + /** |
|
32 | + * @var TenantInterface |
|
33 | + */ |
|
34 | + protected $tenant; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var TenantResolverInterface |
|
38 | - */ |
|
39 | - protected $tenantResolver; |
|
36 | + /** |
|
37 | + * @var TenantResolverInterface |
|
38 | + */ |
|
39 | + protected $tenantResolver; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var RequestStack |
|
43 | - */ |
|
44 | - protected $requestStack; |
|
41 | + /** |
|
42 | + * @var RequestStack |
|
43 | + */ |
|
44 | + protected $requestStack; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var EventDispatcherInterface |
|
48 | - */ |
|
49 | - protected $dispatcher; |
|
46 | + /** |
|
47 | + * @var EventDispatcherInterface |
|
48 | + */ |
|
49 | + protected $dispatcher; |
|
50 | 50 | |
51 | - /** |
|
52 | - * TenantContext constructor. |
|
53 | - */ |
|
54 | - public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
55 | - EventDispatcherInterface $dispatcher) { |
|
51 | + /** |
|
52 | + * TenantContext constructor. |
|
53 | + */ |
|
54 | + public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
55 | + EventDispatcherInterface $dispatcher) { |
|
56 | 56 | $this->tenantResolver = $tenantResolver; |
57 | 57 | $this->requestStack = $requestStack; |
58 | 58 | $this->dispatcher = $dispatcher; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * {@inheritdoc} |
|
63 | - */ |
|
64 | - public function getTenant() { |
|
61 | + /** |
|
62 | + * {@inheritdoc} |
|
63 | + */ |
|
64 | + public function getTenant() { |
|
65 | 65 | if ($this->tenant !== null) |
66 | - return $this->tenant; |
|
66 | + return $this->tenant; |
|
67 | 67 | |
68 | 68 | $currentRequest = $this->requestStack->getCurrentRequest(); |
69 | 69 | if (null !== $currentRequest && false !== strpos($currentRequest->getRequestUri(), '_profiler')) { |
70 | - $profilerTenant = new Tenant(); |
|
71 | - $profilerTenant->setDomainName($currentRequest->getHost()); |
|
72 | - $this->setTenant($profilerTenant); |
|
73 | - return $profilerTenant; |
|
70 | + $profilerTenant = new Tenant(); |
|
71 | + $profilerTenant->setDomainName($currentRequest->getHost()); |
|
72 | + $this->setTenant($profilerTenant); |
|
73 | + return $profilerTenant; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $newTenant = $this->tenantResolver->resolve($currentRequest ? $currentRequest->getHost() : null); |
77 | 77 | $this->setTenant($newTenant); |
78 | 78 | return $newTenant; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function setTenant(TenantInterface $tenant) { |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function setTenant(TenantInterface $tenant) { |
|
85 | 85 | $this->tenant = $tenant; |
86 | 86 | |
87 | 87 | $this->dispatcher->dispatch(new GenericEvent($tenant), MultiTenancyEvents::TENANT_SET); |
88 | - } |
|
88 | + } |
|
89 | 89 | } |
@@ -62,8 +62,9 @@ |
||
62 | 62 | * {@inheritdoc} |
63 | 63 | */ |
64 | 64 | public function getTenant() { |
65 | - if ($this->tenant !== null) |
|
66 | - return $this->tenant; |
|
65 | + if ($this->tenant !== null) { |
|
66 | + return $this->tenant; |
|
67 | + } |
|
67 | 68 | |
68 | 69 | $currentRequest = $this->requestStack->getCurrentRequest(); |
69 | 70 | if (null !== $currentRequest && false !== strpos($currentRequest->getRequestUri(), '_profiler')) { |
@@ -78,7 +78,7 @@ |
||
78 | 78 | return $paginator->paginate( |
79 | 79 | $queryBuilder, |
80 | 80 | (int)$criteria->get('firstResult', 0), |
81 | - (int)$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
81 | + (int)$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
82 | 82 | ); |
83 | 83 | } |
84 | 84 |
@@ -77,12 +77,12 @@ |
||
77 | 77 | $paginator = new Paginator($eventDispatcher); |
78 | 78 | return $paginator->paginate( |
79 | 79 | $queryBuilder, |
80 | - (int)$criteria->get('firstResult', 0), |
|
81 | - (int)$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
80 | + (int) $criteria->get('firstResult', 0), |
|
81 | + (int) $criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
82 | 82 | ); |
83 | 83 | } |
84 | 84 | |
85 | - return $this->getPaginator( $eventDispatcher,$queryBuilder, $paginationData); |
|
85 | + return $this->getPaginator($eventDispatcher, $queryBuilder, $paginationData); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | public function getCountByCriteria(Criteria $criteria): int |
@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | private function getPaths() : array |
38 | 38 | { |
39 | - return [$this->themeUploader->getAvailableThemesPath()]; |
|
39 | + return [$this->themeUploader->getAvailableThemesPath()]; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -25,62 +25,62 @@ discard block |
||
25 | 25 | use Symfony\Component\HttpFoundation\RequestStack; |
26 | 26 | |
27 | 27 | class Paginator implements PaginatorInterface { |
28 | - private EventDispatcherInterface $eventDispatcher; |
|
29 | - private ?RequestStack $requestStack; |
|
30 | - |
|
31 | - private array $defaultOptions = [ |
|
32 | - self::PAGE_PARAMETER_NAME => 'page', |
|
33 | - self::SORT_FIELD_PARAMETER_NAME => 'sort', |
|
34 | - self::SORT_DIRECTION_PARAMETER_NAME => 'direction', |
|
35 | - self::FILTER_FIELD_PARAMETER_NAME => 'filterParam', |
|
36 | - self::FILTER_VALUE_PARAMETER_NAME => 'filterValue', |
|
37 | - self::DISTINCT => true, |
|
38 | - self::PAGE_OUT_OF_RANGE => self::PAGE_OUT_OF_RANGE_IGNORE, |
|
39 | - self::DEFAULT_LIMIT => self::DEFAULT_LIMIT_VALUE, |
|
40 | - ]; |
|
41 | - |
|
42 | - |
|
43 | - public function __construct(EventDispatcherInterface $eventDispatcher, ?RequestStack $requestStack = null) { |
|
28 | + private EventDispatcherInterface $eventDispatcher; |
|
29 | + private ?RequestStack $requestStack; |
|
30 | + |
|
31 | + private array $defaultOptions = [ |
|
32 | + self::PAGE_PARAMETER_NAME => 'page', |
|
33 | + self::SORT_FIELD_PARAMETER_NAME => 'sort', |
|
34 | + self::SORT_DIRECTION_PARAMETER_NAME => 'direction', |
|
35 | + self::FILTER_FIELD_PARAMETER_NAME => 'filterParam', |
|
36 | + self::FILTER_VALUE_PARAMETER_NAME => 'filterValue', |
|
37 | + self::DISTINCT => true, |
|
38 | + self::PAGE_OUT_OF_RANGE => self::PAGE_OUT_OF_RANGE_IGNORE, |
|
39 | + self::DEFAULT_LIMIT => self::DEFAULT_LIMIT_VALUE, |
|
40 | + ]; |
|
41 | + |
|
42 | + |
|
43 | + public function __construct(EventDispatcherInterface $eventDispatcher, ?RequestStack $requestStack = null) { |
|
44 | 44 | $this->eventDispatcher = $eventDispatcher; |
45 | 45 | $this->requestStack = $requestStack; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function setDefaultPaginatorOptions(array $options): void { |
|
48 | + public function setDefaultPaginatorOptions(array $options): void { |
|
49 | 49 | $this->defaultOptions = \array_merge($this->defaultOptions, $options); |
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritdoc} |
|
54 | - * |
|
55 | - * IMPORTANT: This method expects OFFSET value instead PAGE |
|
56 | - */ |
|
57 | - public function paginate($target, int $offset = 1, $limit = 10, array $options = array()) : PaginationInterface { |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritdoc} |
|
54 | + * |
|
55 | + * IMPORTANT: This method expects OFFSET value instead PAGE |
|
56 | + */ |
|
57 | + public function paginate($target, int $offset = 1, $limit = 10, array $options = array()) : PaginationInterface { |
|
58 | 58 | $limit = intval(abs($limit)); |
59 | 59 | if (!$limit) { |
60 | - throw new \LogicException('Invalid item per page number, must be a positive number'); |
|
60 | + throw new \LogicException('Invalid item per page number, must be a positive number'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $page = intval(round($offset / $limit), 10); |
64 | 64 | if ($page < 1) { |
65 | - $page = 1; |
|
65 | + $page = 1; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $options = \array_merge($this->defaultOptions, $options); |
69 | 69 | |
70 | 70 | // normalize default sort field |
71 | 71 | if (isset($options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME]) && is_array($options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME])) { |
72 | - $options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME] = implode('+', $options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME]); |
|
72 | + $options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME] = implode('+', $options[PaginatorInterface::DEFAULT_SORT_FIELD_NAME]); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $request = null === $this->requestStack ? Request::createFromGlobals() : $this->requestStack->getCurrentRequest(); |
76 | 76 | |
77 | 77 | // default sort field and direction are set based on options (if available) |
78 | 78 | if (isset($options[self::DEFAULT_SORT_FIELD_NAME]) && !$request->query->has($options[self::SORT_FIELD_PARAMETER_NAME])) { |
79 | - $request->query->set($options[self::SORT_FIELD_PARAMETER_NAME], $options[self::DEFAULT_SORT_FIELD_NAME]); |
|
79 | + $request->query->set($options[self::SORT_FIELD_PARAMETER_NAME], $options[self::DEFAULT_SORT_FIELD_NAME]); |
|
80 | 80 | |
81 | - if (!$request->query->has($options[PaginatorInterface::SORT_DIRECTION_PARAMETER_NAME])) { |
|
81 | + if (!$request->query->has($options[PaginatorInterface::SORT_DIRECTION_PARAMETER_NAME])) { |
|
82 | 82 | $request->query->set($options[PaginatorInterface::SORT_DIRECTION_PARAMETER_NAME], $options[PaginatorInterface::DEFAULT_SORT_DIRECTION] ?? 'asc'); |
83 | - } |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | // before pagination start |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | $itemsEvent->target = &$target; |
93 | 93 | $this->eventDispatcher->dispatch($itemsEvent, 'knp_pager.items'); |
94 | 94 | if (!$itemsEvent->isPropagationStopped()) { |
95 | - throw new \RuntimeException('One of listeners must count and slice given target'); |
|
95 | + throw new \RuntimeException('One of listeners must count and slice given target'); |
|
96 | 96 | } |
97 | 97 | if ($page > ceil($itemsEvent->count / $limit)) { |
98 | - $pageOutOfRangeOption = $options[PaginatorInterface::PAGE_OUT_OF_RANGE] ?? $this->defaultOptions[PaginatorInterface::PAGE_OUT_OF_RANGE]; |
|
99 | - if ($pageOutOfRangeOption === PaginatorInterface::PAGE_OUT_OF_RANGE_FIX && $itemsEvent->count > 0) { |
|
98 | + $pageOutOfRangeOption = $options[PaginatorInterface::PAGE_OUT_OF_RANGE] ?? $this->defaultOptions[PaginatorInterface::PAGE_OUT_OF_RANGE]; |
|
99 | + if ($pageOutOfRangeOption === PaginatorInterface::PAGE_OUT_OF_RANGE_FIX && $itemsEvent->count > 0) { |
|
100 | 100 | // replace page number out of range with max page |
101 | 101 | return $this->paginate($target, (int) ceil($itemsEvent->count / $limit), $limit, $options); |
102 | - } |
|
103 | - if ($pageOutOfRangeOption === self::PAGE_OUT_OF_RANGE_THROW_EXCEPTION && $page > 1) { |
|
102 | + } |
|
103 | + if ($pageOutOfRangeOption === self::PAGE_OUT_OF_RANGE_THROW_EXCEPTION && $page > 1) { |
|
104 | 104 | throw new PageNumberOutOfRangeException( |
105 | 105 | sprintf('Page number: %d is out of range.', $page), |
106 | 106 | (int) ceil($itemsEvent->count / $limit) |
107 | 107 | ); |
108 | - } |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // pagination initialization event |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $paginationEvent->options = &$options; |
115 | 115 | $this->eventDispatcher->dispatch($paginationEvent, 'knp_pager.pagination'); |
116 | 116 | if (!$paginationEvent->isPropagationStopped()) { |
117 | - throw new \RuntimeException('One of listeners must create pagination view'); |
|
117 | + throw new \RuntimeException('One of listeners must create pagination view'); |
|
118 | 118 | } |
119 | 119 | // pagination class can be different, with different rendering methods |
120 | 120 | $paginationView = $paginationEvent->getPagination(); |
@@ -130,5 +130,5 @@ discard block |
||
130 | 130 | $this->eventDispatcher->dispatch($afterEvent, 'knp_pager.after'); |
131 | 131 | |
132 | 132 | return $paginationView; |
133 | - } |
|
133 | + } |
|
134 | 134 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | $name = ""; |
130 | 130 | $params = ['slug' => $article->getSlug()]; |
131 | 131 | DecoratingRoutingExtension::setupParams($article->getRoute(), $name, $params); |
132 | - $url = $this->urlGenerator->generate($name, $params , UrlGeneratorInterface::ABSOLUTE_URL); |
|
132 | + $url = $this->urlGenerator->generate($name, $params, UrlGeneratorInterface::ABSOLUTE_URL); |
|
133 | 133 | |
134 | 134 | return $this->getClient($feed)->removeArticle($url); |
135 | 135 | } |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | final class BypassFinalHook implements BeforeTestHook |
8 | 8 | { |
9 | - public function executeBeforeTest(string $test): void |
|
10 | - { |
|
9 | + public function executeBeforeTest(string $test): void |
|
10 | + { |
|
11 | 11 | BypassFinals::enable(); |
12 | - } |
|
12 | + } |
|
13 | 13 | } |