@@ -28,32 +28,32 @@ discard block |
||
28 | 28 | use FOS\RestBundle\Controller\Annotations\Route; |
29 | 29 | |
30 | 30 | class SlideshowItemController extends Controller { |
31 | - private ArticleRepositoryInterface $articleRepository; |
|
32 | - private SlideshowRepositoryInterface $slideshowRepository; |
|
33 | - private SlideshowItemRepositoryInterface $slideshowItemRepository; |
|
34 | - private EventDispatcherInterface $eventDispatcher; |
|
31 | + private ArticleRepositoryInterface $articleRepository; |
|
32 | + private SlideshowRepositoryInterface $slideshowRepository; |
|
33 | + private SlideshowItemRepositoryInterface $slideshowItemRepository; |
|
34 | + private EventDispatcherInterface $eventDispatcher; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param ArticleRepositoryInterface $articleRepository |
|
38 | - * @param SlideshowRepositoryInterface $slideshowRepository |
|
39 | - * @param SlideshowItemRepositoryInterface $slideshowItemRepository |
|
40 | - * @param EventDispatcherInterface $eventDispatcher |
|
41 | - */ |
|
42 | - public function __construct(ArticleRepositoryInterface $articleRepository, |
|
43 | - SlideshowRepositoryInterface $slideshowRepository, |
|
44 | - SlideshowItemRepositoryInterface $slideshowItemRepository, |
|
45 | - EventDispatcherInterface $eventDispatcher) { |
|
36 | + /** |
|
37 | + * @param ArticleRepositoryInterface $articleRepository |
|
38 | + * @param SlideshowRepositoryInterface $slideshowRepository |
|
39 | + * @param SlideshowItemRepositoryInterface $slideshowItemRepository |
|
40 | + * @param EventDispatcherInterface $eventDispatcher |
|
41 | + */ |
|
42 | + public function __construct(ArticleRepositoryInterface $articleRepository, |
|
43 | + SlideshowRepositoryInterface $slideshowRepository, |
|
44 | + SlideshowItemRepositoryInterface $slideshowItemRepository, |
|
45 | + EventDispatcherInterface $eventDispatcher) { |
|
46 | 46 | $this->articleRepository = $articleRepository; |
47 | 47 | $this->slideshowRepository = $slideshowRepository; |
48 | 48 | $this->slideshowItemRepository = $slideshowItemRepository; |
49 | 49 | $this->eventDispatcher = $eventDispatcher; |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @Route("/api/{version}/content/slideshows/{articleId}/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_slideshow_items", requirements={"id"="\d+"}) |
|
55 | - */ |
|
56 | - public function listAction(Request $request, string $articleId, string $id) { |
|
53 | + /** |
|
54 | + * @Route("/api/{version}/content/slideshows/{articleId}/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_slideshow_items", requirements={"id"="\d+"}) |
|
55 | + */ |
|
56 | + public function listAction(Request $request, string $articleId, string $id) { |
|
57 | 57 | $article = $this->findArticleOr404($articleId); |
58 | 58 | $repository = $this->slideshowItemRepository; |
59 | 59 | |
@@ -68,21 +68,21 @@ discard block |
||
68 | 68 | ); |
69 | 69 | |
70 | 70 | return new ResourcesListResponse($items); |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - private function findOr404($id): ?SlideshowInterface { |
|
73 | + private function findOr404($id): ?SlideshowInterface { |
|
74 | 74 | if (null === $slideshow = $this->slideshowRepository->findOneById($id)) { |
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 $slideshow; |
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 | } |
@@ -35,102 +35,102 @@ |
||
35 | 35 | use FOS\RestBundle\Controller\Annotations\Route; |
36 | 36 | |
37 | 37 | class RelatedArticleOrganizationController extends Controller { |
38 | - private EventDispatcherInterface $eventDispatcher; |
|
39 | - private DataTransformerInterface $dataTransformer; |
|
40 | - private CachedTenantContextInterface $cachedTenantContext; |
|
41 | - private PackageRepositoryInterface $packageRepository; |
|
42 | - private ArticleRepositoryInterface $articleRepository; |
|
43 | - private TenantRepositoryInterface $tenantRepository; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param EventDispatcherInterface $eventDispatcher |
|
47 | - * @param DataTransformerInterface $dataTransformer |
|
48 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | - * @param PackageRepositoryInterface $packageRepository |
|
50 | - * @param ArticleRepositoryInterface $articleRepository |
|
51 | - * @param TenantRepositoryInterface $tenantRepository |
|
52 | - */ |
|
53 | - public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | - DataTransformerInterface $dataTransformer, |
|
55 | - CachedTenantContextInterface $cachedTenantContext, |
|
56 | - PackageRepositoryInterface $packageRepository, |
|
57 | - ArticleRepositoryInterface $articleRepository, |
|
58 | - TenantRepositoryInterface $tenantRepository) { |
|
38 | + private EventDispatcherInterface $eventDispatcher; |
|
39 | + private DataTransformerInterface $dataTransformer; |
|
40 | + private CachedTenantContextInterface $cachedTenantContext; |
|
41 | + private PackageRepositoryInterface $packageRepository; |
|
42 | + private ArticleRepositoryInterface $articleRepository; |
|
43 | + private TenantRepositoryInterface $tenantRepository; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param EventDispatcherInterface $eventDispatcher |
|
47 | + * @param DataTransformerInterface $dataTransformer |
|
48 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | + * @param PackageRepositoryInterface $packageRepository |
|
50 | + * @param ArticleRepositoryInterface $articleRepository |
|
51 | + * @param TenantRepositoryInterface $tenantRepository |
|
52 | + */ |
|
53 | + public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | + DataTransformerInterface $dataTransformer, |
|
55 | + CachedTenantContextInterface $cachedTenantContext, |
|
56 | + PackageRepositoryInterface $packageRepository, |
|
57 | + ArticleRepositoryInterface $articleRepository, |
|
58 | + TenantRepositoryInterface $tenantRepository) { |
|
59 | 59 | $this->eventDispatcher = $eventDispatcher; |
60 | 60 | $this->dataTransformer = $dataTransformer; |
61 | 61 | $this->cachedTenantContext = $cachedTenantContext; |
62 | 62 | $this->packageRepository = $packageRepository; |
63 | 63 | $this->articleRepository = $articleRepository; |
64 | 64 | $this->tenantRepository = $tenantRepository; |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | - */ |
|
71 | - public function postAction(Request $request) { |
|
68 | + /** |
|
69 | + * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | + */ |
|
71 | + public function postAction(Request $request) { |
|
72 | 72 | $content = $request->getContent(); |
73 | 73 | $package = $this->dataTransformer->transform($content); |
74 | 74 | $relatedArticlesList = $this->getRelated($package); |
75 | 75 | |
76 | 76 | return new SingleResourceResponse($relatedArticlesList); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | - */ |
|
82 | - public function getRelatedAction(string $id) { |
|
79 | + /** |
|
80 | + * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | + */ |
|
82 | + public function getRelatedAction(string $id) { |
|
83 | 83 | $package = $this->findOr404((int)$id); |
84 | 84 | |
85 | 85 | $relatedArticlesList = $this->getRelated($package); |
86 | 86 | |
87 | 87 | return new SingleResourceResponse($relatedArticlesList); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - private function getRelated(PackageInterface $package): RelatedArticleList { |
|
90 | + private function getRelated(PackageInterface $package): RelatedArticleList { |
|
91 | 91 | $relatedItemsGroups = $package->getItems()->filter(static function ($group) { |
92 | - return ItemInterface::TYPE_TEXT === $group->getType(); |
|
92 | + return ItemInterface::TYPE_TEXT === $group->getType(); |
|
93 | 93 | }); |
94 | 94 | |
95 | 95 | $relatedArticlesList = new RelatedArticleList(); |
96 | 96 | |
97 | 97 | if (null === $package || (null !== $package && 0 === \count($relatedItemsGroups))) { |
98 | - return $relatedArticlesList; |
|
98 | + return $relatedArticlesList; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
102 | 102 | $articleRepository = $this->articleRepository; |
103 | 103 | |
104 | 104 | foreach ($relatedItemsGroups as $item) { |
105 | - if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
105 | + if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
106 | 106 | continue; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - $tenants = []; |
|
110 | - foreach ($existingArticles as $existingArticle) { |
|
109 | + $tenants = []; |
|
110 | + foreach ($existingArticles as $existingArticle) { |
|
111 | 111 | $tenantCode = $existingArticle->getTenantCode(); |
112 | 112 | $tenant = $this->tenantRepository->findOneByCode($tenantCode); |
113 | 113 | |
114 | 114 | $tenants[] = $tenant; |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | - $relatedArticleListItem->setTenants($tenants); |
|
119 | - $relatedArticleListItem->setTitle($item->getHeadline()); |
|
117 | + $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | + $relatedArticleListItem->setTenants($tenants); |
|
119 | + $relatedArticleListItem->setTitle($item->getHeadline()); |
|
120 | 120 | |
121 | - $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
121 | + $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $relatedArticlesList; |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - private function findOr404(int $id): PackageInterface { |
|
127 | + private function findOr404(int $id): PackageInterface { |
|
128 | 128 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
129 | 129 | $tenantContext = $this->cachedTenantContext; |
130 | 130 | if (null === $package = $this->packageRepository->findOneBy(['id' => $id, 'organization' => $tenantContext->getTenant()->getOrganization()])) { |
131 | - throw new NotFoundHttpException('Package was not found.'); |
|
131 | + throw new NotFoundHttpException('Package was not found.'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $package; |
135 | - } |
|
135 | + } |
|
136 | 136 | } |
@@ -37,75 +37,75 @@ |
||
37 | 37 | use FOS\RestBundle\Controller\Annotations\Route as FOSRoute; |
38 | 38 | |
39 | 39 | class SeoMediaController extends AbstractMediaController { |
40 | - private FactoryInterface $seoMetadataFactory; |
|
41 | - private ArticleProviderInterface $articleProvider; |
|
42 | - private EntityManagerInterface $seoObjectManager; |
|
43 | - private FormFactoryInterface $formFactory; |
|
44 | - |
|
45 | - public function __construct( |
|
46 | - FactoryInterface $seoMetadataFactory, |
|
47 | - ArticleProviderInterface $articleProvider, |
|
48 | - FormFactoryInterface $formFactory, |
|
49 | - EntityManagerInterface $seoObjectManager, |
|
50 | - MediaManagerInterface $seoMediaManager, |
|
51 | - CacheInterface $cacheProvider, |
|
52 | - FileProviderInterface $fileProvider, |
|
53 | - FileExtensionCheckerInterface $fileExtensionChecker |
|
54 | - ) { |
|
40 | + private FactoryInterface $seoMetadataFactory; |
|
41 | + private ArticleProviderInterface $articleProvider; |
|
42 | + private EntityManagerInterface $seoObjectManager; |
|
43 | + private FormFactoryInterface $formFactory; |
|
44 | + |
|
45 | + public function __construct( |
|
46 | + FactoryInterface $seoMetadataFactory, |
|
47 | + ArticleProviderInterface $articleProvider, |
|
48 | + FormFactoryInterface $formFactory, |
|
49 | + EntityManagerInterface $seoObjectManager, |
|
50 | + MediaManagerInterface $seoMediaManager, |
|
51 | + CacheInterface $cacheProvider, |
|
52 | + FileProviderInterface $fileProvider, |
|
53 | + FileExtensionCheckerInterface $fileExtensionChecker |
|
54 | + ) { |
|
55 | 55 | $this->seoMetadataFactory = $seoMetadataFactory; |
56 | 56 | $this->formFactory = $formFactory; |
57 | 57 | $this->articleProvider = $articleProvider; |
58 | 58 | $this->seoObjectManager = $seoObjectManager; |
59 | 59 | |
60 | 60 | parent::__construct($seoMediaManager, $cacheProvider, $fileProvider, $fileExtensionChecker); |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @Route("/seo/media/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_seo_media_get") |
|
65 | - */ |
|
66 | - public function getAction(string $mediaId, string $extension): Response { |
|
63 | + /** |
|
64 | + * @Route("/seo/media/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_seo_media_get") |
|
65 | + */ |
|
66 | + public function getAction(string $mediaId, string $extension): Response { |
|
67 | 67 | return $this->getMedia($mediaId, $extension); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @FOSRoute("/api/{version}/upload/seo_image/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_seo_image") |
|
72 | - */ |
|
73 | - public function uploadSeoImageAction(Request $request, string $id, |
|
74 | - SeoImageUploaderInterface $seoImageUploader): SingleResourceResponse { |
|
70 | + /** |
|
71 | + * @FOSRoute("/api/{version}/upload/seo_image/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_seo_image") |
|
72 | + */ |
|
73 | + public function uploadSeoImageAction(Request $request, string $id, |
|
74 | + SeoImageUploaderInterface $seoImageUploader): SingleResourceResponse { |
|
75 | 75 | $article = $this->findOr404($id); |
76 | 76 | $seoMetadata = $article->getSeoMetadata(); |
77 | 77 | |
78 | 78 | if (null === $seoMetadata) { |
79 | - $seoMetadata = $this->seoMetadataFactory->create(); |
|
79 | + $seoMetadata = $this->seoMetadataFactory->create(); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $form = $this->formFactory->createNamed('', SeoImageType::class, $seoMetadata); |
83 | 83 | $form->handleRequest($request); |
84 | 84 | |
85 | 85 | if ($form->isSubmitted() && $form->isValid()) { |
86 | - try { |
|
86 | + try { |
|
87 | 87 | $seoImageUploader->handleUpload($seoMetadata); |
88 | 88 | |
89 | 89 | if (null === $article->getSeoMetadata()) { |
90 | - $article->setSeoMetadata($seoMetadata); |
|
90 | + $article->setSeoMetadata($seoMetadata); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->seoObjectManager->flush(); |
94 | - } catch (\Exception $e) { |
|
94 | + } catch (\Exception $e) { |
|
95 | 95 | return new SingleResourceResponse(['message' => 'Could not upload an image.'], new ResponseContext(400)); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - return new SingleResourceResponse($seoMetadata, new ResponseContext(201)); |
|
98 | + return new SingleResourceResponse($seoMetadata, new ResponseContext(201)); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return new SingleResourceResponse($form, new ResponseContext(400)); |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - private function findOr404(string $id): ArticleInterface { |
|
104 | + private function findOr404(string $id): ArticleInterface { |
|
105 | 105 | if (null === $article = $this->articleProvider->getOneById($id)) { |
106 | - throw new NotFoundHttpException('Article was not found.'); |
|
106 | + throw new NotFoundHttpException('Article was not found.'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return $article; |
110 | - } |
|
110 | + } |
|
111 | 111 | } |
@@ -23,12 +23,12 @@ |
||
23 | 23 | use FOS\RestBundle\Controller\Annotations\Route; |
24 | 24 | |
25 | 25 | class FailedQueueController extends AbstractController { |
26 | - /** |
|
27 | - * @Route("/api/{version}/failed_queue/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_failed_queue") |
|
28 | - */ |
|
29 | - public function listAction(Request $request, FailedEntriesProvider $failedEntriesProvider) { |
|
26 | + /** |
|
27 | + * @Route("/api/{version}/failed_queue/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_failed_queue") |
|
28 | + */ |
|
29 | + public function listAction(Request $request, FailedEntriesProvider $failedEntriesProvider) { |
|
30 | 30 | $max = $request->query->getInt('limit', 50); |
31 | 31 | |
32 | 32 | return new SingleResourceResponse($failedEntriesProvider->getFailedEntries($max)); |
33 | - } |
|
33 | + } |
|
34 | 34 | } |
@@ -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 | } |