@@ -39,7 +39,7 @@ |
||
39 | 39 | /** |
40 | 40 | * @param Schema $schema |
41 | 41 | */ |
42 | - public function postUp(Schema $schema) : void |
|
42 | + public function postUp(Schema $schema) : void |
|
43 | 43 | { |
44 | 44 | $entityManager = $this->container->get('doctrine.orm.default_entity_manager'); |
45 | 45 | $query = $entityManager |
@@ -25,166 +25,166 @@ |
||
25 | 25 | use SWP\Component\Storage\Model\PersistableInterface; |
26 | 26 | |
27 | 27 | interface ArticleInterface extends TimestampableInterface, TimestampableCancelInterface, RuleSubjectInterface, TranslatableInterface, PersistableInterface, SoftDeletableInterface, MetadataAwareInterface, MediaAwareInterface, AuthorsAwareInterface, KeywordAwareInterface, RelatedArticlesAwareInterface, SeoMetadataAwareInterface { |
28 | - const STATUS_NEW = 'new'; |
|
29 | - |
|
30 | - const STATUS_PUBLISHED = 'published'; |
|
31 | - |
|
32 | - const STATUS_UNPUBLISHED = 'unpublished'; |
|
33 | - |
|
34 | - const STATUS_CANCELED = 'canceled'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function getId(); |
|
40 | - |
|
41 | - /** |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function getBody(); |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $body |
|
48 | - */ |
|
49 | - public function setBody($body); |
|
28 | + const STATUS_NEW = 'new'; |
|
29 | + |
|
30 | + const STATUS_PUBLISHED = 'published'; |
|
31 | + |
|
32 | + const STATUS_UNPUBLISHED = 'unpublished'; |
|
33 | + |
|
34 | + const STATUS_CANCELED = 'canceled'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function getId(); |
|
40 | + |
|
41 | + /** |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function getBody(); |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $body |
|
48 | + */ |
|
49 | + public function setBody($body); |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getTitle(); |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getTitle(); |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $title |
|
58 | - */ |
|
59 | - public function setTitle($title); |
|
56 | + /** |
|
57 | + * @param string $title |
|
58 | + */ |
|
59 | + public function setTitle($title); |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function getSlug(); |
|
61 | + /** |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function getSlug(); |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $slug |
|
68 | - */ |
|
69 | - public function setSlug($slug); |
|
66 | + /** |
|
67 | + * @param string $slug |
|
68 | + */ |
|
69 | + public function setSlug($slug); |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return \DateTime |
|
73 | - */ |
|
74 | - public function getPublishedAt(); |
|
71 | + /** |
|
72 | + * @return \DateTime |
|
73 | + */ |
|
74 | + public function getPublishedAt(); |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param string $publishedAt |
|
78 | - * |
|
79 | - * @return \DateTime |
|
80 | - */ |
|
81 | - public function setPublishedAt(\DateTime $publishedAt); |
|
76 | + /** |
|
77 | + * @param string $publishedAt |
|
78 | + * |
|
79 | + * @return \DateTime |
|
80 | + */ |
|
81 | + public function setPublishedAt(\DateTime $publishedAt); |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - public function isPublished(); |
|
83 | + /** |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + public function isPublished(); |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param string $status |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function setStatus($status); |
|
88 | + /** |
|
89 | + * @param string $status |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function setStatus($status); |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getStatus(); |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getStatus(); |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getTemplateName(); |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getTemplateName(); |
|
104 | 104 | |
105 | - /** |
|
106 | - * @param string $templateName |
|
107 | - */ |
|
108 | - public function setTemplateName($templateName); |
|
105 | + /** |
|
106 | + * @param string $templateName |
|
107 | + */ |
|
108 | + public function setTemplateName($templateName); |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param RouteInterface|void $route |
|
112 | - */ |
|
113 | - public function setRoute(RouteInterface $route = null); |
|
110 | + /** |
|
111 | + * @param RouteInterface|void $route |
|
112 | + */ |
|
113 | + public function setRoute(RouteInterface $route = null); |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return RouteInterface |
|
117 | - */ |
|
118 | - public function getRoute(); |
|
115 | + /** |
|
116 | + * @return RouteInterface |
|
117 | + */ |
|
118 | + public function getRoute(); |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getLead(); |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getLead(); |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $lead |
|
127 | - */ |
|
128 | - public function setLead($lead); |
|
125 | + /** |
|
126 | + * @param string $lead |
|
127 | + */ |
|
128 | + public function setLead($lead); |
|
129 | 129 | |
130 | - public function getCode(): string; |
|
130 | + public function getCode(): string; |
|
131 | 131 | |
132 | - public function setCode(string $code); |
|
132 | + public function setCode(string $code); |
|
133 | 133 | |
134 | - public function addSourceReference(ArticleSourceReferenceInterface $source); |
|
134 | + public function addSourceReference(ArticleSourceReferenceInterface $source); |
|
135 | 135 | |
136 | - public function removeSourceReference(ArticleSourceReferenceInterface $source); |
|
136 | + public function removeSourceReference(ArticleSourceReferenceInterface $source); |
|
137 | 137 | |
138 | - public function hasSourceReference(ArticleSourceReferenceInterface $source): bool; |
|
138 | + public function hasSourceReference(ArticleSourceReferenceInterface $source): bool; |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return Collection|ArticleSourceReferenceInterface[] |
|
142 | - */ |
|
143 | - public function getSources(): Collection; |
|
140 | + /** |
|
141 | + * @return Collection|ArticleSourceReferenceInterface[] |
|
142 | + */ |
|
143 | + public function getSources(): Collection; |
|
144 | 144 | |
145 | - public function getExtra(): array; |
|
145 | + public function getExtra(): array; |
|
146 | 146 | |
147 | - public function setExtra(?array $extra): void; |
|
147 | + public function setExtra(?array $extra): void; |
|
148 | 148 | |
149 | - public function getSlideshows(): Collection; |
|
149 | + public function getSlideshows(): Collection; |
|
150 | 150 | |
151 | - public function hasSlideshow(SlideshowInterface $slideshow): bool; |
|
151 | + public function hasSlideshow(SlideshowInterface $slideshow): bool; |
|
152 | 152 | |
153 | - public function addSlideshow(SlideshowInterface $slideshow): void; |
|
153 | + public function addSlideshow(SlideshowInterface $slideshow): void; |
|
154 | 154 | |
155 | - public function removeSlideshow(SlideshowInterface $slideshow): void; |
|
155 | + public function removeSlideshow(SlideshowInterface $slideshow): void; |
|
156 | 156 | |
157 | - public function getPreviousRelativeUrl(): Collection; |
|
157 | + public function getPreviousRelativeUrl(): Collection; |
|
158 | 158 | |
159 | - public function hasPreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): bool; |
|
159 | + public function hasPreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): bool; |
|
160 | 160 | |
161 | - public function addPreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): void; |
|
161 | + public function addPreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): void; |
|
162 | 162 | |
163 | - public function removePreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): void; |
|
163 | + public function removePreviousRelativeUrl(ArticlePreviousRelativeUrlInterface $previousRelativeUrl): void; |
|
164 | 164 | |
165 | - public function getData(): ?MetadataInterface; |
|
165 | + public function getData(): ?MetadataInterface; |
|
166 | 166 | |
167 | - public function setData(?MetadataInterface $metadata): void; |
|
167 | + public function setData(?MetadataInterface $metadata): void; |
|
168 | 168 | |
169 | - public function getExtraTextFields(): Collection; |
|
169 | + public function getExtraTextFields(): Collection; |
|
170 | 170 | |
171 | - public function getExtraEmbedFields(): Collection; |
|
171 | + public function getExtraEmbedFields(): Collection; |
|
172 | 172 | |
173 | - public function setExtraFields(array $extra): void; |
|
173 | + public function setExtraFields(array $extra): void; |
|
174 | 174 | |
175 | - public function getExtraByKey(string $key): ?ArticleExtraFieldInterface; |
|
175 | + public function getExtraByKey(string $key): ?ArticleExtraFieldInterface; |
|
176 | 176 | |
177 | - public function getExtraArray(): array; |
|
177 | + public function getExtraArray(): array; |
|
178 | 178 | |
179 | - public function isPublishable(): bool; |
|
179 | + public function isPublishable(): bool; |
|
180 | 180 | |
181 | - public function setPublishable(bool $boolean): void; |
|
181 | + public function setPublishable(bool $boolean): void; |
|
182 | 182 | |
183 | - public function setPublishStartDate(\DateTime $startDate = null); |
|
183 | + public function setPublishStartDate(\DateTime $startDate = null); |
|
184 | 184 | |
185 | - public function getPublishStartDate(); |
|
185 | + public function getPublishStartDate(); |
|
186 | 186 | |
187 | - public function setPublishEndDate(\DateTime $endDate = null); |
|
187 | + public function setPublishEndDate(\DateTime $endDate = null); |
|
188 | 188 | |
189 | - public function getPublishEndDate(); |
|
189 | + public function getPublishEndDate(); |
|
190 | 190 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | /** |
40 | 40 | * @param Schema $schema |
41 | 41 | */ |
42 | - public function postUp(Schema $schema) : void |
|
42 | + public function postUp(Schema $schema) : void |
|
43 | 43 | { |
44 | 44 | $entityManager = $this->container->get('doctrine.orm.default_entity_manager'); |
45 | 45 | $query = $entityManager |
@@ -39,7 +39,7 @@ |
||
39 | 39 | /** |
40 | 40 | * @param Schema $schema |
41 | 41 | */ |
42 | - public function postUp(Schema $schema) : void |
|
42 | + public function postUp(Schema $schema) : void |
|
43 | 43 | { |
44 | 44 | $entityManager = $this->container->get('doctrine.orm.default_entity_manager'); |
45 | 45 | $query = $entityManager |
@@ -32,27 +32,27 @@ discard block |
||
32 | 32 | |
33 | 33 | class PackageSearchController extends AbstractController { |
34 | 34 | |
35 | - private PaginatorInterface $paginator; |
|
36 | - private EventDispatcherInterface $eventDispatcher; |
|
37 | - private CachedTenantContext $cachedTenantContext; |
|
35 | + private PaginatorInterface $paginator; |
|
36 | + private EventDispatcherInterface $eventDispatcher; |
|
37 | + private CachedTenantContext $cachedTenantContext; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param PaginatorInterface $paginator |
|
41 | - * @param EventDispatcherInterface $eventDispatcher |
|
42 | - * @param CachedTenantContext $cachedTenantContext |
|
43 | - */ |
|
44 | - public function __construct(PaginatorInterface $paginator, EventDispatcherInterface $eventDispatcher, |
|
45 | - CachedTenantContext $cachedTenantContext) { |
|
39 | + /** |
|
40 | + * @param PaginatorInterface $paginator |
|
41 | + * @param EventDispatcherInterface $eventDispatcher |
|
42 | + * @param CachedTenantContext $cachedTenantContext |
|
43 | + */ |
|
44 | + public function __construct(PaginatorInterface $paginator, EventDispatcherInterface $eventDispatcher, |
|
45 | + CachedTenantContext $cachedTenantContext) { |
|
46 | 46 | $this->paginator = $paginator; |
47 | 47 | $this->eventDispatcher = $eventDispatcher; |
48 | 48 | $this->cachedTenantContext = $cachedTenantContext; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages") |
|
54 | - */ |
|
55 | - public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
52 | + /** |
|
53 | + * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages") |
|
54 | + */ |
|
55 | + public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
56 | 56 | $this->eventDispatcher->dispatch( new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
57 | 57 | $currentTenant = $this->cachedTenantContext->getTenant(); |
58 | 58 | |
@@ -106,5 +106,5 @@ discard block |
||
106 | 106 | ); |
107 | 107 | |
108 | 108 | return new ResourcesListResponse($pagination, $responseContext); |
109 | - } |
|
109 | + } |
|
110 | 110 | } |
@@ -28,24 +28,24 @@ discard block |
||
28 | 28 | |
29 | 29 | class SubscriptionController extends Controller { |
30 | 30 | |
31 | - private SubscriptionsProviderInterface $subscriptionsProvider; |
|
32 | - private RepositoryInterface $userRepository; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param SubscriptionsProviderInterface $subscriptionsProvider |
|
36 | - * @param RepositoryInterface $userRepository |
|
37 | - */ |
|
38 | - public function __construct(SubscriptionsProviderInterface $subscriptionsProvider, |
|
39 | - RepositoryInterface $userRepository) { |
|
31 | + private SubscriptionsProviderInterface $subscriptionsProvider; |
|
32 | + private RepositoryInterface $userRepository; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param SubscriptionsProviderInterface $subscriptionsProvider |
|
36 | + * @param RepositoryInterface $userRepository |
|
37 | + */ |
|
38 | + public function __construct(SubscriptionsProviderInterface $subscriptionsProvider, |
|
39 | + RepositoryInterface $userRepository) { |
|
40 | 40 | $this->subscriptionsProvider = $subscriptionsProvider; |
41 | 41 | $this->userRepository = $userRepository; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"}) |
|
47 | - */ |
|
48 | - public function getAction(Request $request, int $userId) { |
|
45 | + /** |
|
46 | + * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"}) |
|
47 | + */ |
|
48 | + public function getAction(Request $request, int $userId) { |
|
49 | 49 | $subscriptionsProvider = $this->subscriptionsProvider; |
50 | 50 | |
51 | 51 | $filters = [ |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | $subscriptions = $subscriptionsProvider->getSubscriptions($user, $filters); |
59 | 59 | |
60 | 60 | return new SingleResourceResponse($subscriptions); |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - private function findOr404(int $id) { |
|
63 | + private function findOr404(int $id) { |
|
64 | 64 | $user = $this->userRepository->findOneById($id); |
65 | 65 | |
66 | 66 | if (!$user instanceof UserInterface) { |
67 | - throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id)); |
|
67 | + throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id)); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | return $user; |
71 | - } |
|
71 | + } |
|
72 | 72 | } |
@@ -29,40 +29,40 @@ discard block |
||
29 | 29 | |
30 | 30 | class ExternalDataController extends AbstractController { |
31 | 31 | |
32 | - private PackageRepositoryInterface $packageRepository; |
|
33 | - private FactoryInterface $factory; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param PackageRepositoryInterface $packageRepository |
|
37 | - * @param FactoryInterface $factory |
|
38 | - */ |
|
39 | - public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) { |
|
32 | + private PackageRepositoryInterface $packageRepository; |
|
33 | + private FactoryInterface $factory; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param PackageRepositoryInterface $packageRepository |
|
37 | + * @param FactoryInterface $factory |
|
38 | + */ |
|
39 | + public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) { |
|
40 | 40 | $this->packageRepository = $packageRepository; |
41 | 41 | $this->factory = $factory; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data") |
|
46 | - */ |
|
47 | - public function setAction(Request $request, string $slug): SingleResourceResponseInterface { |
|
44 | + /** |
|
45 | + * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data") |
|
46 | + */ |
|
47 | + public function setAction(Request $request, string $slug): SingleResourceResponseInterface { |
|
48 | 48 | $packageRepository = $this->packageRepository; |
49 | 49 | $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]); |
50 | 50 | if (null === $existingPackage) { |
51 | - throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug)); |
|
51 | + throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $externalData = $existingPackage->getExternalData(); |
55 | 55 | if (null === $externalData) { |
56 | - foreach ($externalData as $data) { |
|
56 | + foreach ($externalData as $data) { |
|
57 | 57 | $packageRepository->remove($data); |
58 | - } |
|
59 | - $packageRepository->flush(); |
|
58 | + } |
|
59 | + $packageRepository->flush(); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | if (null !== $request->getContent()) { |
63 | - $validJson = self::getArrayFromJson($request->getContent()); |
|
64 | - $responseData = []; |
|
65 | - foreach ($validJson as $key => $value) { |
|
63 | + $validJson = self::getArrayFromJson($request->getContent()); |
|
64 | + $responseData = []; |
|
65 | + foreach ($validJson as $key => $value) { |
|
66 | 66 | /** @var ExternalDataInterface $externalData */ |
67 | 67 | $externalData = $this->factory->create(); |
68 | 68 | $externalData->setKey($key); |
@@ -70,45 +70,45 @@ discard block |
||
70 | 70 | $externalData->setPackage($existingPackage); |
71 | 71 | $packageRepository->persist($externalData); |
72 | 72 | $responseData[$externalData->getKey()] = $externalData->getValue(); |
73 | - } |
|
74 | - $packageRepository->flush(); |
|
73 | + } |
|
74 | + $packageRepository->flush(); |
|
75 | 75 | |
76 | - return new SingleResourceResponse($responseData, new ResponseContext(200)); |
|
76 | + return new SingleResourceResponse($responseData, new ResponseContext(200)); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return new SingleResourceResponse(['Provided request content is not valid JSON'], new ResponseContext(400)); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data") |
|
84 | - */ |
|
85 | - public function getAction(string $slug): SingleResourceResponseInterface { |
|
82 | + /** |
|
83 | + * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data") |
|
84 | + */ |
|
85 | + public function getAction(string $slug): SingleResourceResponseInterface { |
|
86 | 86 | $packageRepository = $this->packageRepository; |
87 | 87 | $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]); |
88 | 88 | if (null === $existingPackage) { |
89 | - throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug)); |
|
89 | + throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug)); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $externalData = $existingPackage->getExternalData(); |
93 | 93 | if (null === $externalData) { |
94 | - return new SingleResourceResponse([], new ResponseContext(200)); |
|
94 | + return new SingleResourceResponse([], new ResponseContext(200)); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $responseData = []; |
98 | 98 | /** @var ExternalDataInterface $data */ |
99 | 99 | foreach ($externalData as $data) { |
100 | - $responseData[$data->getKey()] = $data->getValue(); |
|
100 | + $responseData[$data->getKey()] = $data->getValue(); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | return new SingleResourceResponse($responseData, new ResponseContext(200)); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - private static function getArrayFromJson($jsonString) { |
|
106 | + private static function getArrayFromJson($jsonString) { |
|
107 | 107 | $jsonArray = json_decode($jsonString, true); |
108 | 108 | if (null === $jsonArray || JSON_ERROR_NONE !== json_last_error()) { |
109 | - throw new \UnexpectedValueException('Provided request content is not valid JSON'); |
|
109 | + throw new \UnexpectedValueException('Provided request content is not valid JSON'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return $jsonArray; |
113 | - } |
|
113 | + } |
|
114 | 114 | } |
@@ -37,45 +37,45 @@ discard block |
||
37 | 37 | |
38 | 38 | class RedirectRouteController extends AbstractController { |
39 | 39 | |
40 | - private FormFactoryInterface $formFactory; |
|
41 | - private RepositoryInterface $redirectRouteRepository; |
|
42 | - private EntityManagerInterface $entityManager; |
|
43 | - private FactoryInterface $redirectRouteFactory; |
|
44 | - private EventDispatcherInterface $eventDispatcher; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param FormFactoryInterface $formFactory |
|
48 | - * @param RepositoryInterface $redirectRouteRepository |
|
49 | - * @param EntityManagerInterface $entityManager |
|
50 | - * @param FactoryInterface $redirectRouteFactory |
|
51 | - * @param EventDispatcherInterface $eventDispatcher |
|
52 | - */ |
|
53 | - public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $redirectRouteRepository, |
|
54 | - EntityManagerInterface $entityManager, FactoryInterface $redirectRouteFactory, |
|
55 | - EventDispatcherInterface $eventDispatcher) { |
|
40 | + private FormFactoryInterface $formFactory; |
|
41 | + private RepositoryInterface $redirectRouteRepository; |
|
42 | + private EntityManagerInterface $entityManager; |
|
43 | + private FactoryInterface $redirectRouteFactory; |
|
44 | + private EventDispatcherInterface $eventDispatcher; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param FormFactoryInterface $formFactory |
|
48 | + * @param RepositoryInterface $redirectRouteRepository |
|
49 | + * @param EntityManagerInterface $entityManager |
|
50 | + * @param FactoryInterface $redirectRouteFactory |
|
51 | + * @param EventDispatcherInterface $eventDispatcher |
|
52 | + */ |
|
53 | + public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $redirectRouteRepository, |
|
54 | + EntityManagerInterface $entityManager, FactoryInterface $redirectRouteFactory, |
|
55 | + EventDispatcherInterface $eventDispatcher) { |
|
56 | 56 | $this->formFactory = $formFactory; |
57 | 57 | $this->redirectRouteRepository = $redirectRouteRepository; |
58 | 58 | $this->entityManager = $entityManager; |
59 | 59 | $this->redirectRouteFactory = $redirectRouteFactory; |
60 | 60 | $this->eventDispatcher = $eventDispatcher; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * @Route("/api/{version}/redirects/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_redirect_routes") |
|
66 | - */ |
|
67 | - public function listAction(Request $request) { |
|
64 | + /** |
|
65 | + * @Route("/api/{version}/redirects/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_redirect_routes") |
|
66 | + */ |
|
67 | + public function listAction(Request $request) { |
|
68 | 68 | $redirectRouteRepository = $this->redirectRouteRepository; |
69 | 69 | |
70 | 70 | $redirectRoutes = $redirectRouteRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
71 | 71 | |
72 | 72 | return new ResourcesListResponse($redirectRoutes); |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @Route("/api/{version}/redirects/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_redirect_route", requirements={"id"="\d+"}) |
|
77 | - */ |
|
78 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
75 | + /** |
|
76 | + * @Route("/api/{version}/redirects/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_redirect_route", requirements={"id"="\d+"}) |
|
77 | + */ |
|
78 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
79 | 79 | $objectManager = $this->entityManager; |
80 | 80 | $redirectRoute = $this->findOr404($id); |
81 | 81 | |
@@ -83,69 +83,69 @@ discard block |
||
83 | 83 | $objectManager->flush(); |
84 | 84 | |
85 | 85 | return new SingleResourceResponse(null, new ResponseContext(204)); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @Route("/api/{version}/redirects/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_create_redirect_route") |
|
90 | - */ |
|
91 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
88 | + /** |
|
89 | + * @Route("/api/{version}/redirects/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_create_redirect_route") |
|
90 | + */ |
|
91 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
92 | 92 | $redirectRoute = $this->redirectRouteFactory->create(); |
93 | 93 | $form = $this->formFactory->createNamed('', RedirectRouteType::class, $redirectRoute, ['method' => $request->getMethod()]); |
94 | 94 | |
95 | 95 | $form->handleRequest($request); |
96 | 96 | |
97 | 97 | if ($this->checkIfSourceRouteExists($redirectRoute)) { |
98 | - $this->ensureRedirectRouteExists($redirectRoute->getRouteName()); |
|
98 | + $this->ensureRedirectRouteExists($redirectRoute->getRouteName()); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if ($form->isSubmitted() && $form->isValid()) { |
102 | - if ($this->checkIfSourceRouteExists($redirectRoute)) { |
|
102 | + if ($this->checkIfSourceRouteExists($redirectRoute)) { |
|
103 | 103 | $redirectRoute->setStaticPrefix($redirectRoute->getRouteName()); |
104 | - } else { |
|
104 | + } else { |
|
105 | 105 | $redirectRoute->setStaticPrefix($redirectRoute->getRouteSource()->getStaticPrefix()); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - $this->redirectRouteRepository->add($redirectRoute); |
|
108 | + $this->redirectRouteRepository->add($redirectRoute); |
|
109 | 109 | |
110 | - return new SingleResourceResponse($redirectRoute, new ResponseContext(201)); |
|
110 | + return new SingleResourceResponse($redirectRoute, new ResponseContext(201)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return new SingleResourceResponse($form, new ResponseContext(400)); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @Route("/api/{version}/redirects/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_update_redirect_route", requirements={"id"="\d+"}) |
|
118 | - */ |
|
119 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
116 | + /** |
|
117 | + * @Route("/api/{version}/redirects/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_update_redirect_route", requirements={"id"="\d+"}) |
|
118 | + */ |
|
119 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
120 | 120 | $objectManager = $this->entityManager; |
121 | 121 | $redirectRoute = $this->findOr404($id); |
122 | 122 | $form = $this->formFactory->createNamed('', RedirectRouteType::class, $redirectRoute, ['method' => $request->getMethod()]); |
123 | 123 | $form->handleRequest($request); |
124 | 124 | |
125 | 125 | if ($form->isSubmitted() && $form->isValid()) { |
126 | - $objectManager->flush(); |
|
126 | + $objectManager->flush(); |
|
127 | 127 | |
128 | - return new SingleResourceResponse($redirectRoute, new ResponseContext(200)); |
|
128 | + return new SingleResourceResponse($redirectRoute, new ResponseContext(200)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return new SingleResourceResponse($form, new ResponseContext(400)); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - private function findOr404(int $id): RedirectRouteInterface { |
|
134 | + private function findOr404(int $id): RedirectRouteInterface { |
|
135 | 135 | if (null === $redirectRoute = $this->redirectRouteRepository->findOneById($id)) { |
136 | - throw new NotFoundHttpException('Redirect route was not found.'); |
|
136 | + throw new NotFoundHttpException('Redirect route was not found.'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $redirectRoute; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - private function ensureRedirectRouteExists(?string $name): void { |
|
142 | + private function ensureRedirectRouteExists(?string $name): void { |
|
143 | 143 | if (null !== $this->redirectRouteRepository->findOneBy(['routeName' => $name])) { |
144 | - throw new ConflictHttpException(sprintf('Redirect route "%s" already exists!', $name)); |
|
144 | + throw new ConflictHttpException(sprintf('Redirect route "%s" already exists!', $name)); |
|
145 | + } |
|
145 | 146 | } |
146 | - } |
|
147 | 147 | |
148 | - private function checkIfSourceRouteExists(RedirectRouteInterface $redirectRoute): bool { |
|
148 | + private function checkIfSourceRouteExists(RedirectRouteInterface $redirectRoute): bool { |
|
149 | 149 | return null === $redirectRoute->getRouteSource(); |
150 | - } |
|
150 | + } |
|
151 | 151 | } |
@@ -28,22 +28,22 @@ discard block |
||
28 | 28 | |
29 | 29 | class ArticleSourceController extends AbstractController { |
30 | 30 | |
31 | - private EntityRepository $entityRepository; |
|
32 | - private EventDispatcherInterface $eventDispatcher; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param EntityRepository $entityRepository |
|
36 | - * @param EventDispatcherInterface $eventDispatcher |
|
37 | - */ |
|
38 | - public function __construct(EntityRepository $entityRepository, EventDispatcherInterface $eventDispatcher) { |
|
31 | + private EntityRepository $entityRepository; |
|
32 | + private EventDispatcherInterface $eventDispatcher; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param EntityRepository $entityRepository |
|
36 | + * @param EventDispatcherInterface $eventDispatcher |
|
37 | + */ |
|
38 | + public function __construct(EntityRepository $entityRepository, EventDispatcherInterface $eventDispatcher) { |
|
39 | 39 | $this->entityRepository = $entityRepository; |
40 | 40 | $this->eventDispatcher = $eventDispatcher; |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @Route("/api/{version}/content/sources/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_article_sources") |
|
45 | - */ |
|
46 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
43 | + /** |
|
44 | + * @Route("/api/{version}/content/sources/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_article_sources") |
|
45 | + */ |
|
46 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
47 | 47 | $sorting = $request->query->all('sorting'); |
48 | 48 | $lists = $this->entityRepository->getPaginatedByCriteria( |
49 | 49 | $this->eventDispatcher, |
@@ -52,5 +52,5 @@ discard block |
||
52 | 52 | new PaginationData($request)); |
53 | 53 | |
54 | 54 | return new ResourcesListResponse($lists); |
55 | - } |
|
55 | + } |
|
56 | 56 | } |