@@ -19,34 +19,34 @@ discard block |
||
19 | 19 | use FOS\RestBundle\Controller\Annotations\Route; |
20 | 20 | |
21 | 21 | class SeoMetadataController extends AbstractController { |
22 | - private FormFactoryInterface $formFactory; |
|
23 | - private FactoryInterface $seoMetadataFactory; |
|
24 | - private RepositoryInterface $seoMetadataRepository; |
|
25 | - private EventDispatcherInterface $eventDispatcher; |
|
22 | + private FormFactoryInterface $formFactory; |
|
23 | + private FactoryInterface $seoMetadataFactory; |
|
24 | + private RepositoryInterface $seoMetadataRepository; |
|
25 | + private EventDispatcherInterface $eventDispatcher; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param FormFactoryInterface $formFactory |
|
29 | - * @param FactoryInterface $seoMetadataFactory |
|
30 | - * @param RepositoryInterface $seoMetadataRepository |
|
31 | - * @param EventDispatcherInterface $eventDispatcher |
|
32 | - */ |
|
33 | - public function __construct(FormFactoryInterface $formFactory, FactoryInterface $seoMetadataFactory, |
|
34 | - RepositoryInterface $seoMetadataRepository, EventDispatcherInterface $eventDispatcher) { |
|
27 | + /** |
|
28 | + * @param FormFactoryInterface $formFactory |
|
29 | + * @param FactoryInterface $seoMetadataFactory |
|
30 | + * @param RepositoryInterface $seoMetadataRepository |
|
31 | + * @param EventDispatcherInterface $eventDispatcher |
|
32 | + */ |
|
33 | + public function __construct(FormFactoryInterface $formFactory, FactoryInterface $seoMetadataFactory, |
|
34 | + RepositoryInterface $seoMetadataRepository, EventDispatcherInterface $eventDispatcher) { |
|
35 | 35 | $this->formFactory = $formFactory; |
36 | 36 | $this->seoMetadataFactory = $seoMetadataFactory; |
37 | 37 | $this->seoMetadataRepository = $seoMetadataRepository; |
38 | 38 | $this->eventDispatcher = $eventDispatcher; |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
43 | - */ |
|
44 | - public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
41 | + /** |
|
42 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
43 | + */ |
|
44 | + public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
45 | 45 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
46 | 46 | |
47 | 47 | $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
48 | 48 | if (null === $seoMetadata) { |
49 | - $seoMetadata = $this->seoMetadataFactory->create(); |
|
49 | + $seoMetadata = $this->seoMetadataFactory->create(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $form = $this->formFactory->createNamed('', SeoMetadataType::class, $seoMetadata, ['method' => $request->getMethod()]); |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | $form->handleRequest($request); |
55 | 55 | |
56 | 56 | if ($form->isSubmitted() && $form->isValid()) { |
57 | - $seoMetadata->setPackageGuid($packageGuid); |
|
58 | - $this->seoMetadataRepository->add($seoMetadata); |
|
57 | + $seoMetadata->setPackageGuid($packageGuid); |
|
58 | + $this->seoMetadataRepository->add($seoMetadata); |
|
59 | 59 | |
60 | - return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
60 | + return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return new SingleResourceResponse($form, new ResponseContext(400)); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
68 | - */ |
|
69 | - public function getAction(string $packageGuid): SingleResourceResponse { |
|
66 | + /** |
|
67 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
68 | + */ |
|
69 | + public function getAction(string $packageGuid): SingleResourceResponse { |
|
70 | 70 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
71 | 71 | |
72 | 72 | $existingSeoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
73 | 73 | if (null === $existingSeoMetadata) { |
74 | - throw new NotFoundHttpException('SEO metadata not found!'); |
|
74 | + throw new NotFoundHttpException('SEO metadata not found!'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return new SingleResourceResponse($existingSeoMetadata, new ResponseContext(200)); |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
@@ -28,35 +28,35 @@ discard block |
||
28 | 28 | |
29 | 29 | class BodyListener |
30 | 30 | { |
31 | - private $decoderProvider; |
|
32 | - private $throwExceptionOnUnsupportedContentType; |
|
33 | - private $defaultFormat; |
|
34 | - private $arrayNormalizer; |
|
35 | - private $normalizeForms; |
|
36 | - |
|
37 | - public function __construct( |
|
38 | - DecoderProviderInterface $decoderProvider, |
|
39 | - bool $throwExceptionOnUnsupportedContentType = false, |
|
40 | - ArrayNormalizerInterface $arrayNormalizer = null, |
|
41 | - bool $normalizeForms = false |
|
42 | - ) { |
|
31 | + private $decoderProvider; |
|
32 | + private $throwExceptionOnUnsupportedContentType; |
|
33 | + private $defaultFormat; |
|
34 | + private $arrayNormalizer; |
|
35 | + private $normalizeForms; |
|
36 | + |
|
37 | + public function __construct( |
|
38 | + DecoderProviderInterface $decoderProvider, |
|
39 | + bool $throwExceptionOnUnsupportedContentType = false, |
|
40 | + ArrayNormalizerInterface $arrayNormalizer = null, |
|
41 | + bool $normalizeForms = false |
|
42 | + ) { |
|
43 | 43 | $this->decoderProvider = $decoderProvider; |
44 | 44 | $this->throwExceptionOnUnsupportedContentType = $throwExceptionOnUnsupportedContentType; |
45 | 45 | $this->arrayNormalizer = $arrayNormalizer; |
46 | 46 | $this->normalizeForms = true; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public function setDefaultFormat(?string $defaultFormat): void |
|
50 | - { |
|
49 | + public function setDefaultFormat(?string $defaultFormat): void |
|
50 | + { |
|
51 | 51 | $this->defaultFormat = $defaultFormat; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - public function onKernelRequest(RequestEvent $event): void |
|
55 | - { |
|
54 | + public function onKernelRequest(RequestEvent $event): void |
|
55 | + { |
|
56 | 56 | $request = $event->getRequest(); |
57 | 57 | |
58 | 58 | if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) { |
59 | - return; |
|
59 | + return; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $method = $request->getMethod(); |
@@ -64,83 +64,83 @@ discard block |
||
64 | 64 | $normalizeRequest = $this->normalizeForms && $this->isFormRequest($request); |
65 | 65 | |
66 | 66 | if ($this->isDecodeable($request)) { |
67 | - $format = null === $contentType |
|
67 | + $format = null === $contentType |
|
68 | 68 | ? $request->getRequestFormat() |
69 | 69 | : $request->getFormat($contentType); |
70 | 70 | |
71 | - $format = $format ?: $this->defaultFormat; |
|
71 | + $format = $format ?: $this->defaultFormat; |
|
72 | 72 | |
73 | - $content = $request->getContent(); |
|
73 | + $content = $request->getContent(); |
|
74 | 74 | |
75 | - if (null === $format || !$this->decoderProvider->supports($format)) { |
|
75 | + if (null === $format || !$this->decoderProvider->supports($format)) { |
|
76 | 76 | if ($this->throwExceptionOnUnsupportedContentType |
77 | 77 | && $this->isNotAnEmptyDeleteRequestWithNoSetContentType($method, $content, $contentType) |
78 | 78 | ) { |
79 | - throw new UnsupportedMediaTypeHttpException("Request body format '$format' not supported"); |
|
79 | + throw new UnsupportedMediaTypeHttpException("Request body format '$format' not supported"); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return; |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - if (!empty($content)) { |
|
85 | + if (!empty($content)) { |
|
86 | 86 | $decoder = $this->decoderProvider->getDecoder($format); |
87 | 87 | $data = $decoder->decode($content); |
88 | 88 | if (is_array($data)) { |
89 | - $request->request = new ParameterBag($data); |
|
90 | - $normalizeRequest = true; |
|
89 | + $request->request = new ParameterBag($data); |
|
90 | + $normalizeRequest = true; |
|
91 | 91 | } else { |
92 | - throw new BadRequestHttpException('Invalid '.$format.' message received'); |
|
92 | + throw new BadRequestHttpException('Invalid '.$format.' message received'); |
|
93 | + } |
|
93 | 94 | } |
94 | - } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | if (null !== $this->arrayNormalizer && $normalizeRequest) { |
98 | - $data = $request->request->all(); |
|
98 | + $data = $request->request->all(); |
|
99 | 99 | |
100 | - try { |
|
100 | + try { |
|
101 | 101 | $data = $this->arrayNormalizer->normalize($data); |
102 | - } catch (NormalizationException $e) { |
|
102 | + } catch (NormalizationException $e) { |
|
103 | 103 | throw new BadRequestHttpException($e->getMessage()); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - $request->request = new ParameterBag($data); |
|
106 | + $request->request = new ParameterBag($data); |
|
107 | 107 | |
108 | - if(!empty($request->files->all())) { |
|
108 | + if(!empty($request->files->all())) { |
|
109 | 109 | $data = $request->files->all(); |
110 | 110 | |
111 | 111 | try { |
112 | - $data = $this->arrayNormalizer->normalize($data); |
|
112 | + $data = $this->arrayNormalizer->normalize($data); |
|
113 | 113 | } catch (NormalizationException $e) { |
114 | - throw new BadRequestHttpException($e->getMessage()); |
|
114 | + throw new BadRequestHttpException($e->getMessage()); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $request->files = new ParameterBag($data); |
118 | - } |
|
118 | + } |
|
119 | + } |
|
119 | 120 | } |
120 | - } |
|
121 | 121 | |
122 | - private function isNotAnEmptyDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool |
|
123 | - { |
|
122 | + private function isNotAnEmptyDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool |
|
123 | + { |
|
124 | 124 | return false === ('DELETE' === $method && empty($content) && empty($contentType)); |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - private function isDecodeable(Request $request): bool |
|
128 | - { |
|
127 | + private function isDecodeable(Request $request): bool |
|
128 | + { |
|
129 | 129 | if (!in_array($request->getMethod(), ['POST', 'PUT', 'PATCH', 'DELETE'])) { |
130 | - return false; |
|
130 | + return false; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | return !$this->isFormRequest($request); |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - private function isFormRequest(Request $request): bool |
|
137 | - { |
|
136 | + private function isFormRequest(Request $request): bool |
|
137 | + { |
|
138 | 138 | $contentTypeParts = explode(';', $request->headers->get('Content-Type', '')); |
139 | 139 | |
140 | 140 | if (isset($contentTypeParts[0])) { |
141 | - return in_array($contentTypeParts[0], ['multipart/form-data', 'application/x-www-form-urlencoded']); |
|
141 | + return in_array($contentTypeParts[0], ['multipart/form-data', 'application/x-www-form-urlencoded']); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return false; |
145 | - } |
|
145 | + } |
|
146 | 146 | } |
@@ -26,46 +26,46 @@ |
||
26 | 26 | |
27 | 27 | final class AmpController extends AbstractController { |
28 | 28 | |
29 | - private Environment $twig; |
|
30 | - private AmpConverterInterface $converter; |
|
31 | - private ThemeLoaderInterface $themeLoader; |
|
32 | - private CacheInterface $cacheService; |
|
29 | + private Environment $twig; |
|
30 | + private AmpConverterInterface $converter; |
|
31 | + private ThemeLoaderInterface $themeLoader; |
|
32 | + private CacheInterface $cacheService; |
|
33 | 33 | |
34 | - public function __construct( |
|
35 | - Environment $twig, |
|
36 | - AmpConverterInterface $ampConverter, |
|
37 | - ThemeLoaderInterface $ampThemeLoader, |
|
38 | - CacheInterface $cacheService |
|
39 | - ) { |
|
34 | + public function __construct( |
|
35 | + Environment $twig, |
|
36 | + AmpConverterInterface $ampConverter, |
|
37 | + ThemeLoaderInterface $ampThemeLoader, |
|
38 | + CacheInterface $cacheService |
|
39 | + ) { |
|
40 | 40 | $this->twig = $twig; |
41 | 41 | $this->converter = $ampConverter; |
42 | 42 | $this->themeLoader = $ampThemeLoader; |
43 | 43 | $this->cacheService = $cacheService; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - public function viewAction(AmpInterface $object): Response { |
|
46 | + public function viewAction(AmpInterface $object): Response { |
|
47 | 47 | return $this->cacheService->get($this->getCacheKey($object), function () use ($object) { |
48 | - $this->themeLoader->load(); |
|
49 | - $content = $this->twig->render(sprintf('@%s/index.html.twig', ThemeLoaderInterface::THEME_NAMESPACE), [ |
|
50 | - 'object' => $object, |
|
51 | - ]); |
|
48 | + $this->themeLoader->load(); |
|
49 | + $content = $this->twig->render(sprintf('@%s/index.html.twig', ThemeLoaderInterface::THEME_NAMESPACE), [ |
|
50 | + 'object' => $object, |
|
51 | + ]); |
|
52 | 52 | |
53 | - $response = new Response(); |
|
54 | - $response->setContent($this->converter->convertToAmp($content)); |
|
55 | - return $response; |
|
53 | + $response = new Response(); |
|
54 | + $response->setContent($this->converter->convertToAmp($content)); |
|
55 | + return $response; |
|
56 | 56 | }); |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | - private function getCacheKey(AmpInterface $object): string { |
|
59 | + private function getCacheKey(AmpInterface $object): string { |
|
60 | 60 | $elements = ['amp_article']; |
61 | 61 | if ($object instanceof PersistableInterface) { |
62 | - $elements[] = $object->getId(); |
|
62 | + $elements[] = $object->getId(); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | if ($object instanceof TimestampableInterface && null !== $object->getUpdatedAt()) { |
66 | - $elements[] = $object->getUpdatedAt()->getTimestamp(); |
|
66 | + $elements[] = $object->getUpdatedAt()->getTimestamp(); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return md5(implode('__', $elements)); |
70 | - } |
|
70 | + } |
|
71 | 71 | } |
@@ -31,12 +31,12 @@ |
||
31 | 31 | */ |
32 | 32 | public function generate($name, $parameters = [], $referenceType = false) |
33 | 33 | { |
34 | - if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name |
|
34 | + if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name |
|
35 | 35 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
36 | - ) { |
|
36 | + ) { |
|
37 | 37 | $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
38 | 38 | unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | if (null === $name && isset($parameters['content_id'])) { |
42 | 42 | $contentId = $this->checkAndRemoveFirstSlash($parameters['content_id']); |
@@ -17,7 +17,7 @@ |
||
17 | 17 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
18 | 18 | |
19 | 19 | class TenantNotFoundException extends NotFoundHttpException { |
20 | - public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { |
|
20 | + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { |
|
21 | 21 | parent::__construct(sprintf('Tenant for host "%s" could not be found! Please check tenants configuration.', $message), $previous, $code, $headers); |
22 | - } |
|
22 | + } |
|
23 | 23 | } |
@@ -24,43 +24,43 @@ discard block |
||
24 | 24 | use Symfony\Component\Routing\Route as SymfonyRoute; |
25 | 25 | |
26 | 26 | class MetaRouter extends DynamicRouter { |
27 | - const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__"; |
|
27 | + const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__"; |
|
28 | 28 | |
29 | - protected $internalRoutesCache = []; |
|
29 | + protected $internalRoutesCache = []; |
|
30 | 30 | |
31 | - public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
31 | + public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
32 | 32 | if (self::OBJECT_BASED_ROUTE_NAME === $name |
33 | 33 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
34 | 34 | ) { |
35 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
36 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
35 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
36 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $cacheKey = $this->getCacheKey($name, $parameters, $referenceType); |
40 | 40 | if (array_key_exists($cacheKey, $this->internalRoutesCache)) { |
41 | - return $this->internalRoutesCache[$cacheKey]; |
|
41 | + return $this->internalRoutesCache[$cacheKey]; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $route = $name; |
45 | 45 | if ($name instanceof Meta) { |
46 | - $object = $name->getValues(); |
|
47 | - if ($object instanceof ArticleInterface) { |
|
46 | + $object = $name->getValues(); |
|
47 | + if ($object instanceof ArticleInterface) { |
|
48 | 48 | $parameters['slug'] = $object->getSlug(); |
49 | 49 | $route = $object->getRoute(); |
50 | 50 | if (null === $route && $name->getContext()->getCurrentPage()) { |
51 | - $parameters['slug'] = null; |
|
52 | - $route = $name->getContext()->getCurrentPage()->getValues(); |
|
51 | + $parameters['slug'] = null; |
|
52 | + $route = $name->getContext()->getCurrentPage()->getValues(); |
|
53 | 53 | } |
54 | - } elseif ($name->getValues() instanceof RouteInterface) { |
|
54 | + } elseif ($name->getValues() instanceof RouteInterface) { |
|
55 | 55 | $route = $name->getValues(); |
56 | - } |
|
56 | + } |
|
57 | 57 | } elseif ($name instanceof ArticleInterface) { |
58 | - $route = $name->getRoute(); |
|
59 | - $parameters['slug'] = $name->getSlug(); |
|
58 | + $route = $name->getRoute(); |
|
59 | + $parameters['slug'] = $name->getSlug(); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | if (null === $route || is_array($route)) { |
63 | - throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); |
|
63 | + throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $result = parent::generate($route, $parameters, $referenceType); |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | unset($route); |
69 | 69 | |
70 | 70 | return $result; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - private function getCacheKey($route, $parameters, $type) { |
|
73 | + private function getCacheKey($route, $parameters, $type) { |
|
74 | 74 | $name = $route; |
75 | 75 | if ($route instanceof Meta) { |
76 | - if ($route->getValues() instanceof ArticleInterface) { |
|
76 | + if ($route->getValues() instanceof ArticleInterface) { |
|
77 | 77 | $name = $route->getValues()->getId(); |
78 | - } elseif ($route->getValues() instanceof RouteInterface) { |
|
78 | + } elseif ($route->getValues() instanceof RouteInterface) { |
|
79 | 79 | $name = $route->getValues()->getName(); |
80 | - } |
|
80 | + } |
|
81 | 81 | } elseif ($route instanceof RouteInterface) { |
82 | - $name = $route->getName(); |
|
82 | + $name = $route->getName(); |
|
83 | 83 | } elseif ($route instanceof ArticleInterface) { |
84 | - $name = $route->getId(); |
|
84 | + $name = $route->getId(); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return md5($name . serialize($parameters) . $type); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * {@inheritdoc} |
|
92 | - */ |
|
93 | - public function supports($name) { |
|
90 | + /** |
|
91 | + * {@inheritdoc} |
|
92 | + */ |
|
93 | + public function supports($name) { |
|
94 | 94 | return |
95 | 95 | ($name instanceof Meta && ( |
96 | 96 | $name->getValues() instanceof ArticleInterface || |
@@ -106,5 +106,5 @@ discard block |
||
106 | 106 | 'swp_media_get' !== $name && |
107 | 107 | false === strpos($name, 'swp_api_') |
108 | 108 | ); |
109 | - } |
|
109 | + } |
|
110 | 110 | } |
@@ -27,53 +27,53 @@ |
||
27 | 27 | |
28 | 28 | class ArticleAuthorMediaRouter extends Router implements VersatileGeneratorInterface { |
29 | 29 | |
30 | - const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__"; |
|
30 | + const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__"; |
|
31 | 31 | |
32 | - protected $authorMediaManager; |
|
32 | + protected $authorMediaManager; |
|
33 | 33 | |
34 | - public function __construct( |
|
35 | - ContainerInterface $container, |
|
36 | - $resource, |
|
37 | - array $options = [], |
|
38 | - RequestContext $context = null, |
|
39 | - ContainerInterface $parameters = null, |
|
40 | - LoggerInterface $logger = null, |
|
41 | - string $defaultLocale = null |
|
42 | - ) { |
|
34 | + public function __construct( |
|
35 | + ContainerInterface $container, |
|
36 | + $resource, |
|
37 | + array $options = [], |
|
38 | + RequestContext $context = null, |
|
39 | + ContainerInterface $parameters = null, |
|
40 | + LoggerInterface $logger = null, |
|
41 | + string $defaultLocale = null |
|
42 | + ) { |
|
43 | 43 | $this->authorMediaManager = $container->get('swp_core_bundle.manager.author_media'); |
44 | 44 | |
45 | 45 | parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale); |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
48 | + public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
49 | 49 | if (self::OBJECT_BASED_ROUTE_NAME === $meta |
50 | 50 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
51 | 51 | ) { |
52 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
53 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
52 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
53 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | if ($meta instanceof Meta && ($meta->getValues() instanceof AuthorMediaInterface)) { |
57 | - return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage()); |
|
57 | + return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return ''; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function supports($name) { |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function supports($name) { |
|
67 | 67 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && ($name->getValues() instanceof AuthorMediaInterface)); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - public function getRouteDebugMessage($name, array $parameters = []) { |
|
70 | + public function getRouteDebugMessage($name, array $parameters = []) { |
|
71 | 71 | if (self::OBJECT_BASED_ROUTE_NAME === $name |
72 | 72 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
73 | 73 | ) { |
74 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
75 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
74 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
75 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
76 | 76 | } |
77 | 77 | return 'Route for article author media ' . $name->getValues()->getId() . ' not found'; |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | |
27 | 27 | class SeoMediaRouter extends Router implements VersatileGeneratorInterface { |
28 | 28 | |
29 | - const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__"; |
|
29 | + const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__"; |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
35 | 35 | if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
36 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
37 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
36 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
37 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $item = $name->getValues()->getImage(); |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | $parameters['extension'] = $item->getFileExtension(); |
44 | 44 | |
45 | 45 | return parent::generate('swp_seo_media_get', $parameters, $referenceType); |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function supports($name): bool { |
|
48 | + public function supports($name): bool { |
|
49 | 49 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && $name->getValues() instanceof ArticleSeoMediaInterface); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - public function getRouteDebugMessage($name, array $parameters = array()): string { |
|
52 | + public function getRouteDebugMessage($name, array $parameters = array()): string { |
|
53 | 53 | if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
54 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
55 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
54 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
55 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return 'Route for media ' . $name->getValues()->getId() . ' not found'; |
59 | - } |
|
59 | + } |
|
60 | 60 | } |
@@ -31,82 +31,82 @@ discard block |
||
31 | 31 | use Symfony\Component\Routing\RequestContext; |
32 | 32 | |
33 | 33 | class MediaRouter extends Router implements VersatileGeneratorInterface { |
34 | - private $mediaManager; |
|
35 | - |
|
36 | - const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__"; |
|
37 | - |
|
38 | - public function __construct( |
|
39 | - ContainerInterface $container, |
|
40 | - $resource, |
|
41 | - array $options = [], |
|
42 | - RequestContext $context = null, |
|
43 | - ContainerInterface $parameters = null, |
|
44 | - LoggerInterface $logger = null, |
|
45 | - string $defaultLocale = null |
|
46 | - ) { |
|
34 | + private $mediaManager; |
|
35 | + |
|
36 | + const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__"; |
|
37 | + |
|
38 | + public function __construct( |
|
39 | + ContainerInterface $container, |
|
40 | + $resource, |
|
41 | + array $options = [], |
|
42 | + RequestContext $context = null, |
|
43 | + ContainerInterface $parameters = null, |
|
44 | + LoggerInterface $logger = null, |
|
45 | + string $defaultLocale = null |
|
46 | + ) { |
|
47 | 47 | $this->mediaManager = $container->get('swp_content_bundle.manager.media'); |
48 | 48 | |
49 | 49 | parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - public function getRouteDebugMessage($meta, array $parameters = array()): string { |
|
52 | + public function getRouteDebugMessage($meta, array $parameters = array()): string { |
|
53 | 53 | if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
54 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
55 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
54 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
55 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
56 | 56 | } |
57 | 57 | return 'Route for media ' . $meta->getValues()->getId() . ' not found'; |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function supports($name): bool { |
|
60 | + public function supports($name): bool { |
|
61 | 61 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || |
62 | 62 | ($name instanceof Meta && ( |
63 | 63 | $name->getValues() instanceof ArticleMediaInterface || |
64 | 64 | $name->getValues() instanceof ImageRenditionInterface)); |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | - public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string { |
|
67 | + public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string { |
|
68 | 68 | if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
69 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
70 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
69 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
70 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | if (!$meta instanceof Meta) { |
74 | - return ''; |
|
74 | + return ''; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $item = $this->getItem($meta); |
78 | 78 | if (null === $item) { |
79 | - return ''; |
|
79 | + return ''; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if ($meta->getValues() instanceof ImageRenditionInterface && null !== ($previewUrl = $meta->getValues()->getPreviewUrl())) { |
83 | - return $previewUrl; |
|
83 | + return $previewUrl; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | if ($item instanceof PreviewUrlAwareInterface && null !== ($previewUrl = $item->getPreviewUrl())) { |
87 | - return $previewUrl; |
|
87 | + return $previewUrl; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return $this->getUrlWithCorrectExtension($item, $parameters); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - private function getItem(Meta $meta): ?FileInterface { |
|
93 | + private function getItem(Meta $meta): ?FileInterface { |
|
94 | 94 | if (($rendition = $meta->getValues()) instanceof ImageRendition) { |
95 | - return $rendition->getImage(); |
|
95 | + return $rendition->getImage(); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if (($image = $meta->getValues()->getImage()) instanceof ImageInterface) { |
99 | - return $image; |
|
99 | + return $image; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | if (($file = $meta->getValues()->getFile()) instanceof FileInterface) { |
103 | - return $file; |
|
103 | + return $file; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return null; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string { |
|
109 | + private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string { |
|
110 | 110 | $url = $this->mediaManager->getMediaPublicUrl($item); |
111 | 111 | |
112 | 112 | if ( |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | true === $parameters['webp'] && |
116 | 116 | $item->hasVariant(ImageInterface::VARIANT_WEBP) |
117 | 117 | ) { |
118 | - return str_replace('.' . $item->getFileExtension(), '.webp', $url); |
|
118 | + return str_replace('.' . $item->getFileExtension(), '.webp', $url); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return $url; |
122 | - } |
|
122 | + } |
|
123 | 123 | } |