@@ -27,54 +27,54 @@ |
||
27 | 27 | |
28 | 28 | class RedirectingController extends AbstractController { |
29 | 29 | |
30 | - private RouterInterface $router; |
|
31 | - private ArticleRepositoryInterface $articleRepository; |
|
30 | + private RouterInterface $router; |
|
31 | + private ArticleRepositoryInterface $articleRepository; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param RouterInterface $router |
|
35 | - * @param ArticleRepositoryInterface $articleRepository |
|
36 | - */ |
|
37 | - public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { |
|
33 | + /** |
|
34 | + * @param RouterInterface $router |
|
35 | + * @param ArticleRepositoryInterface $articleRepository |
|
36 | + */ |
|
37 | + public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { |
|
38 | 38 | $this->router = $router; |
39 | 39 | $this->articleRepository = $articleRepository; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { |
|
43 | + public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { |
|
44 | 44 | try { |
45 | - $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
|
46 | - if (null === $existingArticle) { |
|
45 | + $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
|
46 | + if (null === $existingArticle) { |
|
47 | 47 | $existingArticle = $this->articleRepository->getArticleByPackageExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
48 | - } |
|
48 | + } |
|
49 | 49 | } catch (NonUniqueResultException $e) { |
50 | - $existingArticle = null; |
|
50 | + $existingArticle = null; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
54 | - throw $this->createNotFoundException('Article with provided data was not found.'); |
|
54 | + throw $this->createNotFoundException('Article with provided data was not found.'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { |
|
60 | + public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { |
|
61 | 61 | $existingArticle = $this->articleRepository->findOneBySlug($slug); |
62 | 62 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
63 | - throw $this->createNotFoundException('Article not found.'); |
|
63 | + throw $this->createNotFoundException('Article not found.'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - private function generateArticleUrl(Request $request, ArticleInterface $article): string { |
|
69 | + private function generateArticleUrl(Request $request, ArticleInterface $article): string { |
|
70 | 70 | $parameters = ['slug' => $article->getSlug()]; |
71 | 71 | if ($request->query->has('amp')) { |
72 | - $parameters['amp'] = 1; |
|
72 | + $parameters['amp'] = 1; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $relativeUrl = $this->router->generate($article->getRoute(), $parameters, UrlGeneratorInterface::ABSOLUTE_PATH); |
76 | 76 | $customDomain = 'https://www.brasil247.com'; |
77 | 77 | $absoluteUrl = rtrim($customDomain, '/') . '/' . ltrim($relativeUrl, '/'); |
78 | 78 | return $absoluteUrl; |
79 | - } |
|
79 | + } |
|
80 | 80 | } |
@@ -74,7 +74,7 @@ |
||
74 | 74 | |
75 | 75 | $relativeUrl = $this->router->generate($article->getRoute(), $parameters, UrlGeneratorInterface::ABSOLUTE_PATH); |
76 | 76 | $customDomain = 'https://www.brasil247.com'; |
77 | - $absoluteUrl = rtrim($customDomain, '/') . '/' . ltrim($relativeUrl, '/'); |
|
77 | + $absoluteUrl = rtrim($customDomain, '/').'/'.ltrim($relativeUrl, '/'); |
|
78 | 78 | return $absoluteUrl; |
79 | 79 | } |
80 | 80 | } |