@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function getSortedItems(Criteria $criteria, array $sorting = [], array $groupValues = []): QueryBuilder; |
32 | 32 | |
33 | - public function getPaginatedByCriteria(EventDispatcherInterface $eventDispatcher,Criteria $criteria, array $sorting = [], PaginationData $paginationData = null); |
|
33 | + public function getPaginatedByCriteria(EventDispatcherInterface $eventDispatcher, Criteria $criteria, array $sorting = [], PaginationData $paginationData = null); |
|
34 | 34 | |
35 | 35 | public function getCountByCriteria(Criteria $criteria): int; |
36 | 36 |
@@ -106,15 +106,15 @@ |
||
106 | 106 | |
107 | 107 | protected function createAdditionalCriteria(Request $request): array { |
108 | 108 | return [ |
109 | - 'routes' => array_filter((array)$request->query->get('route', [])), |
|
110 | - 'statuses' => array_filter((array)$request->query->get('status', [])), |
|
111 | - 'authors' => array_filter((array)$request->query->get('author', [])), |
|
109 | + 'routes' => array_filter((array) $request->query->get('route', [])), |
|
110 | + 'statuses' => array_filter((array) $request->query->get('status', [])), |
|
111 | + 'authors' => array_filter((array) $request->query->get('author', [])), |
|
112 | 112 | 'publishedBefore' => $request->query->has('published_before') ? new \DateTime($request->query->get('published_before')) : null, |
113 | 113 | 'publishedAfter' => $request->query->has('published_after') ? new \DateTime($request->query->get('published_after')) : null, |
114 | 114 | 'publishedAt' => $request->query->get('published_at'), |
115 | - 'sources' => array_filter((array)$request->query->get('source', [])), |
|
116 | - 'metadata' => array_filter((array)$request->query->get('metadata', [])), |
|
117 | - 'keywords' => array_filter((array)$request->query->get('keywords', [])), |
|
115 | + 'sources' => array_filter((array) $request->query->get('source', [])), |
|
116 | + 'metadata' => array_filter((array) $request->query->get('metadata', [])), |
|
117 | + 'keywords' => array_filter((array) $request->query->get('keywords', [])), |
|
118 | 118 | ]; |
119 | 119 | } |
120 | 120 | } |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | use FOS\RestBundle\Controller\Annotations\Route; |
29 | 29 | |
30 | 30 | class ArticleSearchController extends AbstractController { |
31 | - private $extraFields; // |
|
32 | - private CachedTenantContext $cachedTenantContext; // swp_multi_tenancy.tenant_context |
|
33 | - private PaginatorInterface $paginator; // knp_paginator |
|
34 | - |
|
35 | - /** |
|
36 | - * @param $extraFields |
|
37 | - * @param CachedTenantContext $cachedTenantContext |
|
38 | - * @param PaginatorInterface $paginator |
|
39 | - */ |
|
40 | - public function __construct($extraFields, CachedTenantContext $cachedTenantContext, PaginatorInterface $paginator) { |
|
31 | + private $extraFields; // |
|
32 | + private CachedTenantContext $cachedTenantContext; // swp_multi_tenancy.tenant_context |
|
33 | + private PaginatorInterface $paginator; // knp_paginator |
|
34 | + |
|
35 | + /** |
|
36 | + * @param $extraFields |
|
37 | + * @param CachedTenantContext $cachedTenantContext |
|
38 | + * @param PaginatorInterface $paginator |
|
39 | + */ |
|
40 | + public function __construct($extraFields, CachedTenantContext $cachedTenantContext, PaginatorInterface $paginator) { |
|
41 | 41 | $this->extraFields = $extraFields; |
42 | 42 | $this->cachedTenantContext = $cachedTenantContext; |
43 | 43 | $this->paginator = $paginator; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
48 | - */ |
|
49 | - public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
46 | + /** |
|
47 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
48 | + */ |
|
49 | + public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
|
50 | 50 | $criteria = $this->createCriteriaFrom($request); |
51 | 51 | $extraFields = $this->extraFields; |
52 | 52 | |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | $responseContext->setSerializationGroups($this->getSerializationGroups()); |
70 | 70 | |
71 | 71 | return new ResourcesListResponse($pagination, $responseContext); |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - private function createCriteriaFrom(Request $request): Criteria { |
|
74 | + private function createCriteriaFrom(Request $request): Criteria { |
|
75 | 75 | return Criteria::fromQueryParameters( |
76 | 76 | $request->query->get('term', ''), |
77 | 77 | array_merge($this->createDefaultCriteria($request), $this->createAdditionalCriteria($request) |
78 | 78 | )); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - private function createDefaultCriteria(Request $request): array { |
|
81 | + private function createDefaultCriteria(Request $request): array { |
|
82 | 82 | $currentTenant = $this->cachedTenantContext->getTenant(); |
83 | 83 | |
84 | 84 | return [ |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | 'limit' => $request->query->get('limit', 10), |
88 | 88 | 'tenantCode' => $currentTenant->getCode(), |
89 | 89 | ]; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - protected function getSerializationGroups(): array { |
|
92 | + protected function getSerializationGroups(): array { |
|
93 | 93 | return [ |
94 | 94 | 'Default', |
95 | 95 | 'api_articles_list', |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | 'api_tenant_list', |
103 | 103 | 'api_articles_statistics_list', |
104 | 104 | ]; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - protected function createAdditionalCriteria(Request $request): array { |
|
107 | + protected function createAdditionalCriteria(Request $request): array { |
|
108 | 108 | return [ |
109 | 109 | 'routes' => array_filter((array)$request->query->get('route', [])), |
110 | 110 | 'statuses' => array_filter((array)$request->query->get('status', [])), |
@@ -116,5 +116,5 @@ discard block |
||
116 | 116 | 'metadata' => array_filter((array)$request->query->get('metadata', [])), |
117 | 117 | 'keywords' => array_filter((array)$request->query->get('keywords', [])), |
118 | 118 | ]; |
119 | - } |
|
119 | + } |
|
120 | 120 | } |
@@ -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 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages") |
54 | 54 | */ |
55 | 55 | public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) { |
56 | - $this->eventDispatcher->dispatch( new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
|
56 | + $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
|
57 | 57 | $currentTenant = $this->cachedTenantContext->getTenant(); |
58 | 58 | |
59 | 59 | $criteria = Criteria::fromQueryParameters( |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | 'page' => $request->query->get('page'), |
63 | 63 | 'sort' => $request->query->get('sorting'), |
64 | 64 | 'limit' => $request->query->get('limit', 10), |
65 | - 'authors' => array_filter((array)$request->query->get('author', [])), |
|
65 | + 'authors' => array_filter((array) $request->query->get('author', [])), |
|
66 | 66 | 'publishedBefore' => $request->query->get('published_before'), |
67 | 67 | 'publishedAfter' => $request->query->get('published_after'), |
68 | 68 | 'organization' => $currentTenant->getOrganization()->getId(), |
69 | - 'sources' => array_filter((array)$request->query->get('source', [])), |
|
70 | - 'tenants' => array_filter((array)$request->query->get('tenant', [])), |
|
71 | - 'routes' => array_filter((array)$request->query->get('route', [])), |
|
72 | - 'statuses' => array_filter((array)$request->query->get('status', [])), |
|
69 | + 'sources' => array_filter((array) $request->query->get('source', [])), |
|
70 | + 'tenants' => array_filter((array) $request->query->get('tenant', [])), |
|
71 | + 'routes' => array_filter((array) $request->query->get('route', [])), |
|
72 | + 'statuses' => array_filter((array) $request->query->get('status', [])), |
|
73 | 73 | 'language' => $request->query->get('language', ''), |
74 | 74 | ] |
75 | 75 | ); |
@@ -105,7 +105,7 @@ |
||
105 | 105 | |
106 | 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 { |
@@ -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 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | use SWP\Bundle\CoreBundle\Model\OrganizationInterface; |
21 | 21 | use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
22 | 22 | use Symfony\Component\HttpFoundation\Response; |
23 | -use Symfony\Component\HttpKernel\Event\RequestEvent ; |
|
23 | +use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
24 | 24 | |
25 | 25 | class SecuredContentPushListener |
26 | 26 | { |
@@ -15,7 +15,7 @@ |
||
15 | 15 | namespace SWP\Bundle\CoreBundle\EventListener; |
16 | 16 | |
17 | 17 | use SWP\Bundle\CoreBundle\Detection\DeviceDetectionInterface; |
18 | -use Symfony\Component\HttpKernel\Event\RequestEvent ; |
|
18 | +use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
19 | 19 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
20 | 20 | |
21 | 21 | class CurrentDeviceListener |
@@ -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 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $currentlyLoggedInUser = $this->getUser(); |
100 | 100 | |
101 | 101 | $now = PublisherDateTime::getCurrentDateTime(); |
102 | - $fileName = 'analytics-' . $now->format('Y-m-d-H:i:s') . '.csv'; |
|
102 | + $fileName = 'analytics-'.$now->format('Y-m-d-H:i:s').'.csv'; |
|
103 | 103 | |
104 | 104 | $form = $this->formFactory->createNamed('', ExportAnalyticsType::class, null, ['method' => $request->getMethod()]); |
105 | 105 | $form->handleRequest($request); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function downloadFile(string $fileName): Response { |
163 | 163 | $cacheKey = md5(serialize(['analytics_report', $fileName])); |
164 | 164 | |
165 | - $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) { |
|
165 | + $analyticsReport = $this->cacheProvider->get($cacheKey, function() use ($fileName) { |
|
166 | 166 | /* @var AnalyticsReportInterface|null $analyticsReport */ |
167 | 167 | return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
168 | 168 | }); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $response->setMaxAge(63072000); |
185 | 185 | $response->setSharedMaxAge(63072000); |
186 | 186 | $response->setLastModified($analyticsReport->getUpdatedAt() ?: $analyticsReport->getCreatedAt()); |
187 | - $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId())); |
|
187 | + $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath().'/'.$analyticsReport->getAssetId())); |
|
188 | 188 | |
189 | 189 | return $response; |
190 | 190 | } |
@@ -51,33 +51,33 @@ discard block |
||
51 | 51 | |
52 | 52 | class AnalyticsExportController extends AbstractController { |
53 | 53 | |
54 | - protected CacheInterface $cacheProvider; |
|
55 | - protected RepositoryInterface $analyticsReportRepository; |
|
56 | - protected Filesystem $filesystem; |
|
57 | - protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | - protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | - protected RouteRepositoryInterface $routeRepository; |
|
60 | - private MessageBusInterface $messageBus; |
|
61 | - private FormFactoryInterface $formFactory; |
|
62 | - private EventDispatcherInterface $eventDispatcher; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param CacheInterface $cacheProvider |
|
66 | - * @param RepositoryInterface $analyticsReportRepository |
|
67 | - * @param Filesystem $filesystem |
|
68 | - * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | - * @param RouteRepositoryInterface $routeRepository |
|
71 | - * @param MessageBusInterface $messageBus |
|
72 | - * @param FormFactoryInterface $formFactory |
|
73 | - * @param EventDispatcherInterface $eventDispatcher |
|
74 | - */ |
|
75 | - public function __construct(CacheInterface $cacheProvider, |
|
76 | - RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | - CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | - CachedTenantContextInterface $cachedTenantContext, |
|
79 | - RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | - FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
54 | + protected CacheInterface $cacheProvider; |
|
55 | + protected RepositoryInterface $analyticsReportRepository; |
|
56 | + protected Filesystem $filesystem; |
|
57 | + protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | + protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | + protected RouteRepositoryInterface $routeRepository; |
|
60 | + private MessageBusInterface $messageBus; |
|
61 | + private FormFactoryInterface $formFactory; |
|
62 | + private EventDispatcherInterface $eventDispatcher; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param CacheInterface $cacheProvider |
|
66 | + * @param RepositoryInterface $analyticsReportRepository |
|
67 | + * @param Filesystem $filesystem |
|
68 | + * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | + * @param RouteRepositoryInterface $routeRepository |
|
71 | + * @param MessageBusInterface $messageBus |
|
72 | + * @param FormFactoryInterface $formFactory |
|
73 | + * @param EventDispatcherInterface $eventDispatcher |
|
74 | + */ |
|
75 | + public function __construct(CacheInterface $cacheProvider, |
|
76 | + RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | + CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | + CachedTenantContextInterface $cachedTenantContext, |
|
79 | + RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | + FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
81 | 81 | $this->cacheProvider = $cacheProvider; |
82 | 82 | $this->analyticsReportRepository = $analyticsReportRepository; |
83 | 83 | $this->filesystem = $filesystem; |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | $this->messageBus = $messageBus; |
88 | 88 | $this->formFactory = $formFactory; |
89 | 89 | $this->eventDispatcher = $eventDispatcher; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | - * |
|
96 | - * @throws \Exception |
|
97 | - */ |
|
98 | - public function post(Request $request): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | + * |
|
96 | + * @throws \Exception |
|
97 | + */ |
|
98 | + public function post(Request $request): SingleResourceResponseInterface { |
|
99 | 99 | /** @var UserInterface $currentlyLoggedInUser */ |
100 | 100 | $currentlyLoggedInUser = $this->getUser(); |
101 | 101 | |
@@ -106,46 +106,46 @@ discard block |
||
106 | 106 | $form->handleRequest($request); |
107 | 107 | |
108 | 108 | if ($form->isSubmitted() && $form->isValid()) { |
109 | - $data = $form->getData(); |
|
109 | + $data = $form->getData(); |
|
110 | 110 | |
111 | - $analyticsReport = new AnalyticsReport(); |
|
112 | - $analyticsReport->setAssetId($fileName); |
|
113 | - $analyticsReport->setFileExtension('csv'); |
|
114 | - $analyticsReport->setUser($currentlyLoggedInUser); |
|
111 | + $analyticsReport = new AnalyticsReport(); |
|
112 | + $analyticsReport->setAssetId($fileName); |
|
113 | + $analyticsReport->setFileExtension('csv'); |
|
114 | + $analyticsReport->setUser($currentlyLoggedInUser); |
|
115 | 115 | |
116 | - $exportAnalytics = new ExportAnalytics( |
|
117 | - $data['start'], |
|
118 | - $data['end'], |
|
119 | - $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | - $fileName, |
|
121 | - $currentlyLoggedInUser->getEmail(), |
|
122 | - !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | - !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | - $data['term'] ?? '' |
|
125 | - ); |
|
116 | + $exportAnalytics = new ExportAnalytics( |
|
117 | + $data['start'], |
|
118 | + $data['end'], |
|
119 | + $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | + $fileName, |
|
121 | + $currentlyLoggedInUser->getEmail(), |
|
122 | + !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | + !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | + $data['term'] ?? '' |
|
125 | + ); |
|
126 | 126 | |
127 | - $filters = $this->processFilters( |
|
128 | - $exportAnalytics->getFilters(), |
|
129 | - !empty($data['routes']) ? $data['routes'] : [], |
|
130 | - !empty($data['authors']) ? $data['authors'] : [] |
|
131 | - ); |
|
127 | + $filters = $this->processFilters( |
|
128 | + $exportAnalytics->getFilters(), |
|
129 | + !empty($data['routes']) ? $data['routes'] : [], |
|
130 | + !empty($data['authors']) ? $data['authors'] : [] |
|
131 | + ); |
|
132 | 132 | |
133 | - $analyticsReport->setFilters($filters); |
|
133 | + $analyticsReport->setFilters($filters); |
|
134 | 134 | |
135 | - $this->analyticsReportRepository->add($analyticsReport); |
|
135 | + $this->analyticsReportRepository->add($analyticsReport); |
|
136 | 136 | |
137 | - $this->messageBus->dispatch($exportAnalytics); |
|
137 | + $this->messageBus->dispatch($exportAnalytics); |
|
138 | 138 | |
139 | - return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
139 | + return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return new SingleResourceResponse($form, new ResponseContext(400)); |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | - */ |
|
148 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
145 | + /** |
|
146 | + * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | + */ |
|
148 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
149 | 149 | $sorting = $request->query->all('sorting'); |
150 | 150 | $reports = $this->analyticsReportRepository->getPaginatedByCriteria( |
151 | 151 | $this->eventDispatcher, |
@@ -155,21 +155,21 @@ discard block |
||
155 | 155 | ); |
156 | 156 | |
157 | 157 | return new ResourcesListResponse($reports); |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | - */ |
|
163 | - public function downloadFile(string $fileName): Response { |
|
160 | + /** |
|
161 | + * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | + */ |
|
163 | + public function downloadFile(string $fileName): Response { |
|
164 | 164 | $cacheKey = md5(serialize(['analytics_report', $fileName])); |
165 | 165 | |
166 | 166 | $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) { |
167 | - /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | - return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
167 | + /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | + return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
169 | 169 | }); |
170 | 170 | |
171 | 171 | if (null === $analyticsReport) { |
172 | - throw new NotFoundHttpException('Report file was not found.'); |
|
172 | + throw new NotFoundHttpException('Report file was not found.'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $response = new Response(); |
@@ -188,30 +188,30 @@ discard block |
||
188 | 188 | $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId())); |
189 | 189 | |
190 | 190 | return $response; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - private function toIds(array $items): array { |
|
193 | + private function toIds(array $items): array { |
|
194 | 194 | $ids = []; |
195 | 195 | foreach ($items as $item) { |
196 | - foreach ($item as $entity) { |
|
196 | + foreach ($item as $entity) { |
|
197 | 197 | if (!$entity instanceof PersistableInterface) { |
198 | - continue; |
|
198 | + continue; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $ids[] = $entity->getId(); |
202 | - } |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $ids; |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - private function processFilters(array $filters, array $routes, array $authors): array { |
|
208 | + private function processFilters(array $filters, array $routes, array $authors): array { |
|
209 | 209 | $routeNames = []; |
210 | 210 | |
211 | 211 | foreach ($routes as $route) { |
212 | - foreach ($route as $entity) { |
|
212 | + foreach ($route as $entity) { |
|
213 | 213 | $routeNames[] = $entity->getName(); |
214 | - } |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $filters['routes'] = $routeNames; |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $authorNames = []; |
220 | 220 | /** @var ArticleAuthorInterface $author */ |
221 | 221 | foreach ($authors as $author) { |
222 | - foreach ($author as $entity) { |
|
222 | + foreach ($author as $entity) { |
|
223 | 223 | $authorNames[] = $entity->getName(); |
224 | - } |
|
224 | + } |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $filters['authors'] = $authorNames; |
228 | 228 | |
229 | 229 | return $filters; |
230 | - } |
|
230 | + } |
|
231 | 231 | } |