@@ -65,7 +65,7 @@ |
||
| 65 | 65 | public function registerPeriodicTimer(Topic $topic): void |
| 66 | 66 | { |
| 67 | 67 | $n = 1; |
| 68 | - $this->periodicTimer->addPeriodicTimer($this, 'ping', 5, function () use ($topic, &$n) { |
|
| 68 | + $this->periodicTimer->addPeriodicTimer($this, 'ping', 5, function() use ($topic, &$n) { |
|
| 69 | 69 | $topic->broadcast(['ping' => $n]); |
| 70 | 70 | |
| 71 | 71 | ++$n; |
@@ -162,6 +162,6 @@ |
||
| 162 | 162 | */ |
| 163 | 163 | private function dispatchRouteEvent($eventName, RouteInterface $route) |
| 164 | 164 | { |
| 165 | - $this->eventDispatcher->dispatch(new RouteEvent($route, $eventName), $eventName); |
|
| 165 | + $this->eventDispatcher->dispatch(new RouteEvent($route, $eventName), $eventName); |
|
| 166 | 166 | } |
| 167 | 167 | } |
@@ -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 |
@@ -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 | { |