@@ -26,15 +26,15 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | class SeoMediaRouter extends Router implements VersatileGeneratorInterface { |
| 28 | 28 | |
| 29 | - const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__"; |
|
| 29 | + const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__"; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * {@inheritdoc} |
|
| 33 | - */ |
|
| 34 | - public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
| 31 | + /** |
|
| 32 | + * {@inheritdoc} |
|
| 33 | + */ |
|
| 34 | + public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
| 35 | 35 | if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
| 36 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 37 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 36 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 37 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $item = $name->getValues()->getImage(); |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | $parameters['extension'] = $item->getFileExtension(); |
| 44 | 44 | |
| 45 | 45 | return parent::generate('swp_seo_media_get', $parameters, $referenceType); |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function supports($name): bool { |
|
| 48 | + public function supports($name): bool { |
|
| 49 | 49 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && $name->getValues() instanceof ArticleSeoMediaInterface); |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function getRouteDebugMessage($name, array $parameters = array()): string { |
|
| 52 | + public function getRouteDebugMessage($name, array $parameters = array()): string { |
|
| 53 | 53 | if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
| 54 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 55 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 54 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 55 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | return 'Route for media ' . $name->getValues()->getId() . ' not found'; |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -31,82 +31,82 @@ discard block |
||
| 31 | 31 | use Symfony\Component\Routing\RequestContext; |
| 32 | 32 | |
| 33 | 33 | class MediaRouter extends Router implements VersatileGeneratorInterface { |
| 34 | - private $mediaManager; |
|
| 35 | - |
|
| 36 | - const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__"; |
|
| 37 | - |
|
| 38 | - public function __construct( |
|
| 39 | - ContainerInterface $container, |
|
| 40 | - $resource, |
|
| 41 | - array $options = [], |
|
| 42 | - RequestContext $context = null, |
|
| 43 | - ContainerInterface $parameters = null, |
|
| 44 | - LoggerInterface $logger = null, |
|
| 45 | - string $defaultLocale = null |
|
| 46 | - ) { |
|
| 34 | + private $mediaManager; |
|
| 35 | + |
|
| 36 | + const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__"; |
|
| 37 | + |
|
| 38 | + public function __construct( |
|
| 39 | + ContainerInterface $container, |
|
| 40 | + $resource, |
|
| 41 | + array $options = [], |
|
| 42 | + RequestContext $context = null, |
|
| 43 | + ContainerInterface $parameters = null, |
|
| 44 | + LoggerInterface $logger = null, |
|
| 45 | + string $defaultLocale = null |
|
| 46 | + ) { |
|
| 47 | 47 | $this->mediaManager = $container->get('swp_content_bundle.manager.media'); |
| 48 | 48 | |
| 49 | 49 | parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale); |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function getRouteDebugMessage($meta, array $parameters = array()): string { |
|
| 52 | + public function getRouteDebugMessage($meta, array $parameters = array()): string { |
|
| 53 | 53 | if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
| 54 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 55 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 54 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 55 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 56 | 56 | } |
| 57 | 57 | return 'Route for media ' . $meta->getValues()->getId() . ' not found'; |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function supports($name): bool { |
|
| 60 | + public function supports($name): bool { |
|
| 61 | 61 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || |
| 62 | 62 | ($name instanceof Meta && ( |
| 63 | 63 | $name->getValues() instanceof ArticleMediaInterface || |
| 64 | 64 | $name->getValues() instanceof ImageRenditionInterface)); |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string { |
|
| 67 | + public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string { |
|
| 68 | 68 | if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) { |
| 69 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 70 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 69 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
| 70 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | if (!$meta instanceof Meta) { |
| 74 | - return ''; |
|
| 74 | + return ''; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $item = $this->getItem($meta); |
| 78 | 78 | if (null === $item) { |
| 79 | - return ''; |
|
| 79 | + return ''; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if ($meta->getValues() instanceof ImageRenditionInterface && null !== ($previewUrl = $meta->getValues()->getPreviewUrl())) { |
| 83 | - return $previewUrl; |
|
| 83 | + return $previewUrl; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | if ($item instanceof PreviewUrlAwareInterface && null !== ($previewUrl = $item->getPreviewUrl())) { |
| 87 | - return $previewUrl; |
|
| 87 | + return $previewUrl; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return $this->getUrlWithCorrectExtension($item, $parameters); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - private function getItem(Meta $meta): ?FileInterface { |
|
| 93 | + private function getItem(Meta $meta): ?FileInterface { |
|
| 94 | 94 | if (($rendition = $meta->getValues()) instanceof ImageRendition) { |
| 95 | - return $rendition->getImage(); |
|
| 95 | + return $rendition->getImage(); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | if (($image = $meta->getValues()->getImage()) instanceof ImageInterface) { |
| 99 | - return $image; |
|
| 99 | + return $image; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | if (($file = $meta->getValues()->getFile()) instanceof FileInterface) { |
| 103 | - return $file; |
|
| 103 | + return $file; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | return null; |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string { |
|
| 109 | + private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string { |
|
| 110 | 110 | $url = $this->mediaManager->getMediaPublicUrl($item); |
| 111 | 111 | |
| 112 | 112 | if ( |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | true === $parameters['webp'] && |
| 116 | 116 | $item->hasVariant(ImageInterface::VARIANT_WEBP) |
| 117 | 117 | ) { |
| 118 | - return str_replace('.' . $item->getFileExtension(), '.webp', $url); |
|
| 118 | + return str_replace('.' . $item->getFileExtension(), '.webp', $url); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | return $url; |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -47,36 +47,36 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | class PackagePreviewController extends Controller { |
| 49 | 49 | |
| 50 | - private EventDispatcherInterface $eventDispatcher; |
|
| 51 | - private DataTransformerInterface $dataTransformer; |
|
| 52 | - private PackageRepositoryInterface $packageRepository; |
|
| 53 | - private RouteRepositoryInterface $routeRepository; |
|
| 54 | - private RepositoryInterface $packagePreviewTokenRepository; |
|
| 55 | - private PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory; |
|
| 56 | - private TemplateNameResolverInterface $templateNameResolver; |
|
| 57 | - private ArticlePreviewerInterface $articlePreviewer; |
|
| 58 | - private ArticlePreviewContextInterface $articlePreviewContext; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 62 | - * @param DataTransformerInterface $dataTransformer |
|
| 63 | - * @param PackageRepositoryInterface $packageRepository |
|
| 64 | - * @param RouteRepositoryInterface $routeRepository |
|
| 65 | - * @param RepositoryInterface $packagePreviewTokenRepository |
|
| 66 | - * @param PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory |
|
| 67 | - * @param TemplateNameResolverInterface $templateNameResolver |
|
| 68 | - * @param ArticlePreviewerInterface $articlePreviewer |
|
| 69 | - * @param ArticlePreviewContextInterface $articlePreviewContext |
|
| 70 | - */ |
|
| 71 | - public function __construct(EventDispatcherInterface $eventDispatcher, |
|
| 72 | - DataTransformerInterface $dataTransformer, |
|
| 73 | - PackageRepositoryInterface $packageRepository, |
|
| 74 | - RouteRepositoryInterface $routeRepository, |
|
| 75 | - RepositoryInterface $packagePreviewTokenRepository, |
|
| 76 | - PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory, |
|
| 77 | - TemplateNameResolverInterface $templateNameResolver, |
|
| 78 | - ArticlePreviewerInterface $articlePreviewer, |
|
| 79 | - ArticlePreviewContextInterface $articlePreviewContext) { |
|
| 50 | + private EventDispatcherInterface $eventDispatcher; |
|
| 51 | + private DataTransformerInterface $dataTransformer; |
|
| 52 | + private PackageRepositoryInterface $packageRepository; |
|
| 53 | + private RouteRepositoryInterface $routeRepository; |
|
| 54 | + private RepositoryInterface $packagePreviewTokenRepository; |
|
| 55 | + private PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory; |
|
| 56 | + private TemplateNameResolverInterface $templateNameResolver; |
|
| 57 | + private ArticlePreviewerInterface $articlePreviewer; |
|
| 58 | + private ArticlePreviewContextInterface $articlePreviewContext; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 62 | + * @param DataTransformerInterface $dataTransformer |
|
| 63 | + * @param PackageRepositoryInterface $packageRepository |
|
| 64 | + * @param RouteRepositoryInterface $routeRepository |
|
| 65 | + * @param RepositoryInterface $packagePreviewTokenRepository |
|
| 66 | + * @param PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory |
|
| 67 | + * @param TemplateNameResolverInterface $templateNameResolver |
|
| 68 | + * @param ArticlePreviewerInterface $articlePreviewer |
|
| 69 | + * @param ArticlePreviewContextInterface $articlePreviewContext |
|
| 70 | + */ |
|
| 71 | + public function __construct(EventDispatcherInterface $eventDispatcher, |
|
| 72 | + DataTransformerInterface $dataTransformer, |
|
| 73 | + PackageRepositoryInterface $packageRepository, |
|
| 74 | + RouteRepositoryInterface $routeRepository, |
|
| 75 | + RepositoryInterface $packagePreviewTokenRepository, |
|
| 76 | + PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory, |
|
| 77 | + TemplateNameResolverInterface $templateNameResolver, |
|
| 78 | + ArticlePreviewerInterface $articlePreviewer, |
|
| 79 | + ArticlePreviewContextInterface $articlePreviewContext) { |
|
| 80 | 80 | $this->eventDispatcher = $eventDispatcher; |
| 81 | 81 | $this->dataTransformer = $dataTransformer; |
| 82 | 82 | $this->packageRepository = $packageRepository; |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | $this->templateNameResolver = $templateNameResolver; |
| 87 | 87 | $this->articlePreviewer = $articlePreviewer; |
| 88 | 88 | $this->articlePreviewContext = $articlePreviewContext; |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @Route("/preview/package/{routeId}/{id}", options={"expose"=true}, requirements={"id"="\d+", "routeId"="\d+", "token"=".+"}, methods={"GET"}, name="swp_package_preview") |
|
| 94 | - */ |
|
| 95 | - public function previewAction(int $routeId, $id) { |
|
| 92 | + /** |
|
| 93 | + * @Route("/preview/package/{routeId}/{id}", options={"expose"=true}, requirements={"id"="\d+", "routeId"="\d+", "token"=".+"}, methods={"GET"}, name="swp_package_preview") |
|
| 94 | + */ |
|
| 95 | + public function previewAction(int $routeId, $id) { |
|
| 96 | 96 | /** @var RouteInterface $route */ |
| 97 | 97 | $route = $this->findRouteOr404($routeId); |
| 98 | 98 | /** @var PackageInterface $package */ |
@@ -106,22 +106,22 @@ discard block |
||
| 106 | 106 | $this->eventDispatcher->dispatch(new GenericEvent($articlePreview), ArticleEvents::PREVIEW); |
| 107 | 107 | |
| 108 | 108 | if (null !== ($url = $articlePreview->getPreviewUrl())) { |
| 109 | - return new RedirectResponse($url); |
|
| 109 | + return new RedirectResponse($url); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $route = $this->ensureRouteTemplateExists($route, $article); |
| 113 | 113 | |
| 114 | 114 | try { |
| 115 | - return $this->render($route->getArticlesTemplateName()); |
|
| 115 | + return $this->render($route->getArticlesTemplateName()); |
|
| 116 | 116 | } catch (\Exception $e) { |
| 117 | - throw $this->createNotFoundException(sprintf('Template for route with id "%d" (%s) not found!', $route->getId(), $route->getName())); |
|
| 117 | + throw $this->createNotFoundException(sprintf('Template for route with id "%d" (%s) not found!', $route->getId(), $route->getName())); |
|
| 118 | + } |
|
| 118 | 119 | } |
| 119 | - } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @FOSRoute("/api/{version}/preview/package/generate_token/{routeId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_preview_package_token", requirements={"routeId"="\d+"}) |
|
| 123 | - */ |
|
| 124 | - public function generateTokenAction(Request $request, int $routeId): SingleResourceResponseInterface { |
|
| 121 | + /** |
|
| 122 | + * @FOSRoute("/api/{version}/preview/package/generate_token/{routeId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_preview_package_token", requirements={"routeId"="\d+"}) |
|
| 123 | + */ |
|
| 124 | + public function generateTokenAction(Request $request, int $routeId): SingleResourceResponseInterface { |
|
| 125 | 125 | $route = $this->findRouteOr404($routeId); |
| 126 | 126 | |
| 127 | 127 | /** @var string $content */ |
@@ -134,27 +134,27 @@ discard block |
||
| 134 | 134 | $existingPreviewToken = $tokenRepository->findOneBy(['route' => $route]); |
| 135 | 135 | |
| 136 | 136 | if (null === $existingPreviewToken) { |
| 137 | - $packagePreviewToken = $this->packagePreviewTokenFactory->createTokenizedWith($route, $content); |
|
| 137 | + $packagePreviewToken = $this->packagePreviewTokenFactory->createTokenizedWith($route, $content); |
|
| 138 | 138 | |
| 139 | - $tokenRepository->persist($packagePreviewToken); |
|
| 140 | - $tokenRepository->flush(); |
|
| 139 | + $tokenRepository->persist($packagePreviewToken); |
|
| 140 | + $tokenRepository->flush(); |
|
| 141 | 141 | |
| 142 | - return $this->returnResponseWithPreviewUrl($packagePreviewToken); |
|
| 142 | + return $this->returnResponseWithPreviewUrl($packagePreviewToken); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $this->updatePackagePreviewTokenBody($content, $existingPreviewToken); |
| 146 | 146 | |
| 147 | 147 | return $this->returnResponseWithPreviewUrl($existingPreviewToken); |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * @Route("/preview/publish/package/{token}", options={"expose"=true}, requirements={"token"=".+"}, methods={"GET"}, name="swp_package_preview_publish") |
|
| 152 | - */ |
|
| 153 | - public function publishPreviewAction(string $token) { |
|
| 150 | + /** |
|
| 151 | + * @Route("/preview/publish/package/{token}", options={"expose"=true}, requirements={"token"=".+"}, methods={"GET"}, name="swp_package_preview_publish") |
|
| 152 | + */ |
|
| 153 | + public function publishPreviewAction(string $token) { |
|
| 154 | 154 | $existingPreviewToken = $this->packagePreviewTokenRepository->findOneBy(['token' => $token]); |
| 155 | 155 | |
| 156 | 156 | if (null === $existingPreviewToken) { |
| 157 | - throw $this->createNotFoundException(sprintf('Token %s is not valid.', $token)); |
|
| 157 | + throw $this->createNotFoundException(sprintf('Token %s is not valid.', $token)); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $article = $this->getArticleForPreview($existingPreviewToken); |
@@ -162,17 +162,17 @@ discard block |
||
| 162 | 162 | $route = $this->ensureRouteTemplateExists($route, $article); |
| 163 | 163 | |
| 164 | 164 | return $this->renderTemplateOr404($route); |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - private function updatePackagePreviewTokenBody(string $content, PackagePreviewTokenInterface $packagePreviewToken) { |
|
| 167 | + private function updatePackagePreviewTokenBody(string $content, PackagePreviewTokenInterface $packagePreviewToken) { |
|
| 168 | 168 | if (md5($content) !== md5($packagePreviewToken->getBody())) { |
| 169 | - $packagePreviewToken->setBody($content); |
|
| 169 | + $packagePreviewToken->setBody($content); |
|
| 170 | 170 | |
| 171 | - $this->packagePreviewTokenRepository->flush(); |
|
| 171 | + $this->packagePreviewTokenRepository->flush(); |
|
| 172 | + } |
|
| 172 | 173 | } |
| 173 | - } |
|
| 174 | 174 | |
| 175 | - private function returnResponseWithPreviewUrl(PackagePreviewTokenInterface $packagePreviewToken): SingleResourceResponseInterface { |
|
| 175 | + private function returnResponseWithPreviewUrl(PackagePreviewTokenInterface $packagePreviewToken): SingleResourceResponseInterface { |
|
| 176 | 176 | $article = $this->getArticleForPreview($packagePreviewToken); |
| 177 | 177 | $articlePreview = new ArticlePreview(); |
| 178 | 178 | $articlePreview->setArticle($article); |
@@ -182,19 +182,19 @@ discard block |
||
| 182 | 182 | $url = $articlePreview->getPreviewUrl(); |
| 183 | 183 | |
| 184 | 184 | if (null === $url) { |
| 185 | - $url = $this->generateUrl( |
|
| 186 | - 'swp_package_preview_publish', |
|
| 187 | - ['token' => $packagePreviewToken->getToken()], |
|
| 188 | - UrlGeneratorInterface::ABSOLUTE_URL |
|
| 189 | - ); |
|
| 185 | + $url = $this->generateUrl( |
|
| 186 | + 'swp_package_preview_publish', |
|
| 187 | + ['token' => $packagePreviewToken->getToken()], |
|
| 188 | + UrlGeneratorInterface::ABSOLUTE_URL |
|
| 189 | + ); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | return new SingleResourceResponse([ |
| 193 | 193 | 'preview_url' => $url, |
| 194 | 194 | ]); |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - private function getArticleForPreview(PackagePreviewTokenInterface $packagePreviewToken): ArticleInterface { |
|
| 197 | + private function getArticleForPreview(PackagePreviewTokenInterface $packagePreviewToken): ArticleInterface { |
|
| 198 | 198 | $dispatcher = $this->eventDispatcher; |
| 199 | 199 | $package = $this->dataTransformer->transform($packagePreviewToken->getBody()); |
| 200 | 200 | $dispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
@@ -205,40 +205,40 @@ discard block |
||
| 205 | 205 | $articlePreviewContext->setIsPreview(true); |
| 206 | 206 | |
| 207 | 207 | return $articlePreviewer->preview($package, $packagePreviewToken->getRoute()); |
| 208 | - } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - private function renderTemplateOr404(RouteInterface $route): Response { |
|
| 210 | + private function renderTemplateOr404(RouteInterface $route): Response { |
|
| 211 | 211 | try { |
| 212 | - return $this->render($templateName = $route->getArticlesTemplateName()); |
|
| 212 | + return $this->render($templateName = $route->getArticlesTemplateName()); |
|
| 213 | 213 | } catch (\InvalidArgumentException | LoaderError $e) { |
| 214 | - throw $this->createNotFoundException(sprintf('Template %s for route with id "%d" (%s) not found!', $templateName, $route->getId(), $route->getName())); |
|
| 214 | + throw $this->createNotFoundException(sprintf('Template %s for route with id "%d" (%s) not found!', $templateName, $route->getId(), $route->getName())); |
|
| 215 | + } |
|
| 215 | 216 | } |
| 216 | - } |
|
| 217 | 217 | |
| 218 | - private function ensureRouteTemplateExists(RouteInterface $route, ArticleInterface $article): RouteInterface { |
|
| 218 | + private function ensureRouteTemplateExists(RouteInterface $route, ArticleInterface $article): RouteInterface { |
|
| 219 | 219 | if (null === $route->getArticlesTemplateName()) { |
| 220 | - $templateNameResolver = $this->templateNameResolver; |
|
| 221 | - $route->setArticlesTemplateName($templateNameResolver->resolve($article)); |
|
| 220 | + $templateNameResolver = $this->templateNameResolver; |
|
| 221 | + $route->setArticlesTemplateName($templateNameResolver->resolve($article)); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | return $route; |
| 225 | - } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - private function findRouteOr404(int $id): RouteInterface { |
|
| 227 | + private function findRouteOr404(int $id): RouteInterface { |
|
| 228 | 228 | /** @var RouteInterface $route */ |
| 229 | 229 | if (null === ($route = $this->routeRepository->findOneBy(['id' => $id]))) { |
| 230 | - throw $this->createNotFoundException(sprintf('Route with id: "%s" not found!', $id)); |
|
| 230 | + throw $this->createNotFoundException(sprintf('Route with id: "%s" not found!', $id)); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return $route; |
| 234 | - } |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - private function findPackageOr404(string $id): PackageInterface { |
|
| 236 | + private function findPackageOr404(string $id): PackageInterface { |
|
| 237 | 237 | /** @var PackageInterface $package */ |
| 238 | 238 | if (null === ($package = $this->packageRepository->findOneBy(['id' => $id]))) { |
| 239 | - throw $this->createNotFoundException(sprintf('Package with id: "%s" not found!', $id)); |
|
| 239 | + throw $this->createNotFoundException(sprintf('Package with id: "%s" not found!', $id)); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $package; |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -34,87 +34,87 @@ discard block |
||
| 34 | 34 | use SWP\Component\Common\Exception\UnexpectedTypeException; |
| 35 | 35 | |
| 36 | 36 | final class DownloadArticleAuthorAvatarListener { |
| 37 | - /** |
|
| 38 | - * @var MediaManagerInterface |
|
| 39 | - */ |
|
| 40 | - private $authorMediaManager; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var EntityManagerInterface |
|
| 44 | - */ |
|
| 45 | - private $entityManager; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - private $cacheDirectory; |
|
| 51 | - |
|
| 52 | - public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) { |
|
| 37 | + /** |
|
| 38 | + * @var MediaManagerInterface |
|
| 39 | + */ |
|
| 40 | + private $authorMediaManager; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var EntityManagerInterface |
|
| 44 | + */ |
|
| 45 | + private $entityManager; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + private $cacheDirectory; |
|
| 51 | + |
|
| 52 | + public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) { |
|
| 53 | 53 | $this->entityManager = $entityManager; |
| 54 | 54 | $this->cacheDirectory = $cacheDirectory; |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param MediaManagerInterface $authorMediaManager |
|
| 59 | - */ |
|
| 60 | - public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) { |
|
| 57 | + /** |
|
| 58 | + * @param MediaManagerInterface $authorMediaManager |
|
| 59 | + */ |
|
| 60 | + public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) { |
|
| 61 | 61 | $this->authorMediaManager = $authorMediaManager; |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param GenericEvent $event |
|
| 66 | - */ |
|
| 67 | - public function processAuthors(GenericEvent $event): void { |
|
| 64 | + /** |
|
| 65 | + * @param GenericEvent $event |
|
| 66 | + */ |
|
| 67 | + public function processAuthors(GenericEvent $event): void { |
|
| 68 | 68 | $package = $event->getSubject(); |
| 69 | 69 | |
| 70 | 70 | if (!$package instanceof PackageInterface) { |
| 71 | - throw new UnexpectedTypeException($package, PackageInterface::class); |
|
| 71 | + throw new UnexpectedTypeException($package, PackageInterface::class); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $authors = []; |
| 75 | 75 | /** @var ArticleAuthorInterface $packageAuthor */ |
| 76 | 76 | foreach ($package->getAuthors() as $packageAuthor) { |
| 77 | - $authors[] = $this->handle($packageAuthor); |
|
| 77 | + $authors[] = $this->handle($packageAuthor); |
|
| 78 | 78 | } |
| 79 | 79 | $package->setAuthors(new ArrayCollection($authors)); |
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param ArticleAuthorInterface $object |
|
| 84 | - * |
|
| 85 | - * @return ArticleAuthorInterface |
|
| 86 | - */ |
|
| 87 | - private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface { |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param ArticleAuthorInterface $object |
|
| 84 | + * |
|
| 85 | + * @return ArticleAuthorInterface |
|
| 86 | + */ |
|
| 87 | + private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface { |
|
| 88 | 88 | if (null !== $object->getAvatarUrl()) { |
| 89 | - $filesystem = new Filesystem(); |
|
| 90 | - $pathParts = \pathinfo($object->getAvatarUrl()); |
|
| 91 | - $assetId = \sha1($pathParts['filename']); |
|
| 92 | - if (null !== $object->getSlug()) { |
|
| 89 | + $filesystem = new Filesystem(); |
|
| 90 | + $pathParts = \pathinfo($object->getAvatarUrl()); |
|
| 91 | + $assetId = \sha1($pathParts['filename']); |
|
| 92 | + if (null !== $object->getSlug()) { |
|
| 93 | 93 | $assetId = $object->getSlug() . '_' . $assetId; |
| 94 | - } |
|
| 95 | - $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]); |
|
| 96 | - if (\count($existingAvatar) > 0) { |
|
| 94 | + } |
|
| 95 | + $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]); |
|
| 96 | + if (\count($existingAvatar) > 0) { |
|
| 97 | 97 | $object->setAvatarUrl((string)\reset($existingAvatar)); |
| 98 | 98 | |
| 99 | 99 | return $object; |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - try { |
|
| 102 | + try { |
|
| 103 | 103 | $tempDirectory = $this->cacheDirectory . \DIRECTORY_SEPARATOR . 'downloaded_avatars'; |
| 104 | 104 | $tempLocation = $tempDirectory . \DIRECTORY_SEPARATOR . \sha1($assetId . date('his')); |
| 105 | 105 | if (!$filesystem->exists($tempDirectory)) { |
| 106 | - $filesystem->mkdir($tempDirectory); |
|
| 106 | + $filesystem->mkdir($tempDirectory); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $avatarUrl = $object->getAvatarUrl(); |
| 110 | 110 | if (strpos($avatarUrl, "http://") === 0 || strpos($avatarUrl, "https://") === 0) { |
| 111 | - self::downloadFile($avatarUrl, $tempLocation); |
|
| 111 | + self::downloadFile($avatarUrl, $tempLocation); |
|
| 112 | 112 | } else { |
| 113 | - $file = \file_get_contents($avatarUrl); |
|
| 114 | - if (false === $file) { |
|
| 113 | + $file = \file_get_contents($avatarUrl); |
|
| 114 | + if (false === $file) { |
|
| 115 | 115 | throw new \Exception('File can\'t be downloaded'); |
| 116 | - } |
|
| 117 | - $filesystem->dumpFile($tempLocation, $file); |
|
| 116 | + } |
|
| 117 | + $filesystem->dumpFile($tempLocation, $file); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $uploadedFile = new UploadedFile($tempLocation, |
@@ -123,29 +123,29 @@ discard block |
||
| 123 | 123 | \filesize($tempLocation), |
| 124 | 124 | true |
| 125 | 125 | ); |
| 126 | - } catch (\Exception $e) { |
|
| 126 | + } catch (\Exception $e) { |
|
| 127 | 127 | return $object; |
| 128 | - } |
|
| 129 | - /** @var Image $image */ |
|
| 130 | - $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId); |
|
| 131 | - $avatar = $this->createAuthorMedia($object, $image); |
|
| 132 | - $this->entityManager->persist($avatar); |
|
| 133 | - $this->entityManager->persist($image); |
|
| 134 | - |
|
| 135 | - $object->setAvatar($avatar); |
|
| 136 | - $object->setAvatarUrl((string)$image); |
|
| 128 | + } |
|
| 129 | + /** @var Image $image */ |
|
| 130 | + $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId); |
|
| 131 | + $avatar = $this->createAuthorMedia($object, $image); |
|
| 132 | + $this->entityManager->persist($avatar); |
|
| 133 | + $this->entityManager->persist($image); |
|
| 134 | + |
|
| 135 | + $object->setAvatar($avatar); |
|
| 136 | + $object->setAvatarUrl((string)$image); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $object; |
| 140 | - } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface { |
|
| 142 | + private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface { |
|
| 143 | 143 | return new AuthorMedia('avatar', $articleAuthor, $image); |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - private static function downloadFile($url, $location) { |
|
| 146 | + private static function downloadFile($url, $location) { |
|
| 147 | 147 | $handlerStack = HandlerStack::create(new CurlHandler()); |
| 148 | 148 | $client = new Client(['handler' => $handlerStack]); |
| 149 | 149 | $client->request('GET', $url, ['sink' => $location]); |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -36,88 +36,88 @@ discard block |
||
| 36 | 36 | * @Route("/reset-password") |
| 37 | 37 | */ |
| 38 | 38 | class ResetPasswordController extends AbstractController { |
| 39 | - use ResetPasswordControllerTrait; |
|
| 39 | + use ResetPasswordControllerTrait; |
|
| 40 | 40 | |
| 41 | - private ResetPasswordHelperInterface $resetPasswordHelper; |
|
| 42 | - private EntityManagerInterface $entityManager; |
|
| 41 | + private ResetPasswordHelperInterface $resetPasswordHelper; |
|
| 42 | + private EntityManagerInterface $entityManager; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param ResetPasswordHelperInterface $resetPasswordHelper |
|
| 46 | - * @param EntityManagerInterface $entityManager |
|
| 47 | - */ |
|
| 48 | - public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, |
|
| 49 | - EntityManagerInterface $entityManager) { |
|
| 44 | + /** |
|
| 45 | + * @param ResetPasswordHelperInterface $resetPasswordHelper |
|
| 46 | + * @param EntityManagerInterface $entityManager |
|
| 47 | + */ |
|
| 48 | + public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, |
|
| 49 | + EntityManagerInterface $entityManager) { |
|
| 50 | 50 | $this->resetPasswordHelper = $resetPasswordHelper; |
| 51 | 51 | $this->entityManager = $entityManager; |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Display & process form to request a password reset. |
|
| 57 | - * |
|
| 58 | - * @Route("", name="swp_user_forgot_password_request") |
|
| 59 | - */ |
|
| 60 | - public function request(Request $request, MailerInterface $mailer): Response { |
|
| 55 | + /** |
|
| 56 | + * Display & process form to request a password reset. |
|
| 57 | + * |
|
| 58 | + * @Route("", name="swp_user_forgot_password_request") |
|
| 59 | + */ |
|
| 60 | + public function request(Request $request, MailerInterface $mailer): Response { |
|
| 61 | 61 | $form = $this->createForm(ResetPasswordRequestFormType::class); |
| 62 | 62 | $form->handleRequest($request); |
| 63 | 63 | |
| 64 | 64 | if ($form->isSubmitted() && $form->isValid()) { |
| 65 | - return $this->processSendingPasswordResetEmail( |
|
| 66 | - $form->get('email')->getData(), |
|
| 67 | - $mailer |
|
| 68 | - ); |
|
| 65 | + return $this->processSendingPasswordResetEmail( |
|
| 66 | + $form->get('email')->getData(), |
|
| 67 | + $mailer |
|
| 68 | + ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return $this->render('@SWPUser/reset_password/request.html.twig', [ |
| 72 | 72 | 'requestForm' => $form->createView(), |
| 73 | 73 | ]); |
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Confirmation page after a user has requested a password reset. |
|
| 78 | - * |
|
| 79 | - * @Route("/check-email", name="swp_user_check_email") |
|
| 80 | - */ |
|
| 81 | - public function checkEmail(): Response { |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Confirmation page after a user has requested a password reset. |
|
| 78 | + * |
|
| 79 | + * @Route("/check-email", name="swp_user_check_email") |
|
| 80 | + */ |
|
| 81 | + public function checkEmail(): Response { |
|
| 82 | 82 | // We prevent users from directly accessing this page |
| 83 | 83 | if (!$this->canCheckEmail()) { |
| 84 | - return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
| 84 | + return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | return $this->render('@SWPUser/reset_password/check_email.html.twig', [ |
| 88 | 88 | 'tokenLifetime' => $this->resetPasswordHelper->getTokenLifetime(), |
| 89 | 89 | ]); |
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Validates and process the reset URL that the user clicked in their email. |
|
| 94 | - * |
|
| 95 | - * @Route("/reset/{token}", name="swp_user_reset_password") |
|
| 96 | - */ |
|
| 97 | - public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Validates and process the reset URL that the user clicked in their email. |
|
| 94 | + * |
|
| 95 | + * @Route("/reset/{token}", name="swp_user_reset_password") |
|
| 96 | + */ |
|
| 97 | + public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, |
|
| 98 | 98 | string $token = null): Response { |
| 99 | 99 | if ($token) { |
| 100 | - // We store the token in session and remove it from the URL, to avoid the URL being |
|
| 101 | - // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
|
| 102 | - $this->storeTokenInSession($token); |
|
| 100 | + // We store the token in session and remove it from the URL, to avoid the URL being |
|
| 101 | + // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
|
| 102 | + $this->storeTokenInSession($token); |
|
| 103 | 103 | |
| 104 | - return $this->redirectToRoute('swp_user_reset_password'); |
|
| 104 | + return $this->redirectToRoute('swp_user_reset_password'); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $token = $this->getTokenFromSession(); |
| 108 | 108 | if (null === $token) { |
| 109 | - throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
|
| 109 | + throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | try { |
| 113 | - $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
|
| 113 | + $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
|
| 114 | 114 | } catch (ResetPasswordExceptionInterface $e) { |
| 115 | - $this->addFlash('reset_password_error', sprintf( |
|
| 116 | - 'There was a problem validating your reset request - %s', |
|
| 117 | - $e->getReason() |
|
| 118 | - )); |
|
| 115 | + $this->addFlash('reset_password_error', sprintf( |
|
| 116 | + 'There was a problem validating your reset request - %s', |
|
| 117 | + $e->getReason() |
|
| 118 | + )); |
|
| 119 | 119 | |
| 120 | - return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
| 120 | + return $this->redirectToRoute('swp_user_forgot_password_request'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // The token is valid; allow the user to change their password. |
@@ -125,30 +125,30 @@ discard block |
||
| 125 | 125 | $form->handleRequest($request); |
| 126 | 126 | |
| 127 | 127 | if ($form->isSubmitted() && $form->isValid()) { |
| 128 | - // A password reset token should be used only once, remove it. |
|
| 129 | - $this->resetPasswordHelper->removeResetRequest($token); |
|
| 128 | + // A password reset token should be used only once, remove it. |
|
| 129 | + $this->resetPasswordHelper->removeResetRequest($token); |
|
| 130 | 130 | |
| 131 | - // Encode the plain password, and set it. |
|
| 132 | - $encodedPassword = $passwordEncoder->encodePassword( |
|
| 133 | - $user, |
|
| 134 | - $form->get('plainPassword')->getData() |
|
| 135 | - ); |
|
| 131 | + // Encode the plain password, and set it. |
|
| 132 | + $encodedPassword = $passwordEncoder->encodePassword( |
|
| 133 | + $user, |
|
| 134 | + $form->get('plainPassword')->getData() |
|
| 135 | + ); |
|
| 136 | 136 | |
| 137 | - $user->setPassword($encodedPassword); |
|
| 138 | - $this->entityManager->flush(); |
|
| 137 | + $user->setPassword($encodedPassword); |
|
| 138 | + $this->entityManager->flush(); |
|
| 139 | 139 | |
| 140 | - // The session is cleaned up after the password has been changed. |
|
| 141 | - $this->cleanSessionAfterReset(); |
|
| 140 | + // The session is cleaned up after the password has been changed. |
|
| 141 | + $this->cleanSessionAfterReset(); |
|
| 142 | 142 | |
| 143 | - return $this->redirectToRoute('homepage'); |
|
| 143 | + return $this->redirectToRoute('homepage'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | return $this->render('@SWPUser/reset_password/reset.html.twig', [ |
| 147 | 147 | 'resetForm' => $form->createView(), |
| 148 | 148 | ]); |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse { |
|
| 151 | + private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse { |
|
| 152 | 152 | $user = $this->entityManager->getRepository(User::class)->findOneBy([ |
| 153 | 153 | 'email' => $emailFormData, |
| 154 | 154 | ]); |
@@ -158,22 +158,22 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // Do not reveal whether a user account was found or not. |
| 160 | 160 | if (!$user) { |
| 161 | - return $this->redirectToRoute('swp_user_check_email'); |
|
| 161 | + return $this->redirectToRoute('swp_user_check_email'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | try { |
| 165 | - $resetToken = $this->resetPasswordHelper->generateResetToken($user); |
|
| 165 | + $resetToken = $this->resetPasswordHelper->generateResetToken($user); |
|
| 166 | 166 | } catch (ResetPasswordExceptionInterface $e) { |
| 167 | - $this->addFlash('reset_password_error', sprintf( |
|
| 168 | - 'There was a problem handling your password reset request - %s', |
|
| 169 | - $e->getReason() |
|
| 170 | - )); |
|
| 167 | + $this->addFlash('reset_password_error', sprintf( |
|
| 168 | + 'There was a problem handling your password reset request - %s', |
|
| 169 | + $e->getReason() |
|
| 170 | + )); |
|
| 171 | 171 | |
| 172 | - return $this->redirectToRoute('swp_user_check_email'); |
|
| 172 | + return $this->redirectToRoute('swp_user_check_email'); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $mailer->sendResetPasswordEmail($user, $resetToken); |
| 176 | 176 | |
| 177 | 177 | return $this->redirectToRoute('swp_user_check_email'); |
| 178 | - } |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -24,43 +24,43 @@ |
||
| 24 | 24 | use SWP\Component\MultiTenancy\Model\TenantInterface; |
| 25 | 25 | |
| 26 | 26 | class CachedTenantContext extends TenantContext implements CachedTenantContextInterface { |
| 27 | - private $resolvedTenants = []; |
|
| 27 | + private $resolvedTenants = []; |
|
| 28 | 28 | |
| 29 | - public function getTenant(): ?TenantInterface { |
|
| 29 | + public function getTenant(): ?TenantInterface { |
|
| 30 | 30 | $currentRequest = $this->requestStack->getCurrentRequest(); |
| 31 | 31 | if ($currentRequest && $this->requestStack->getCurrentRequest()->attributes->get('exception') instanceof TenantNotFoundException) { |
| 32 | - return null; |
|
| 32 | + return null; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | if ($currentRequest === null) { |
| 36 | - return $this->tenant; |
|
| 36 | + return $this->tenant; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $cacheKey = self::getCacheKey($currentRequest->getHost()); |
| 40 | 40 | if (!array_key_exists($cacheKey, $this->resolvedTenants) || $this->resolvedTenants[$cacheKey] instanceof TenantInterface) { |
| 41 | - $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
| 41 | + $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
| 42 | 42 | } else { |
| 43 | - $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
| 43 | + $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | return $this->tenant; |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function setTenant(TenantInterface $tenant): void { |
|
| 49 | + public function setTenant(TenantInterface $tenant): void { |
|
| 50 | 50 | parent::setTenant($tenant); |
| 51 | 51 | $this->dispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
| 52 | 52 | |
| 53 | 53 | $this->resolvedTenants[self::getCacheKey( |
| 54 | 54 | $tenant->getSubdomain() ? $tenant->getSubdomain() . '.' . $tenant->getDomainName() : $tenant->getDomainName() |
| 55 | 55 | )] = $tenant; |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function reset(): void { |
|
| 58 | + public function reset(): void { |
|
| 59 | 59 | $this->tenant = null; |
| 60 | 60 | $this->resolvedTenants = []; |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - private static function getCacheKey(string $host): string { |
|
| 63 | + private static function getCacheKey(string $host): string { |
|
| 64 | 64 | return md5('tenant_cache__' . $host); |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -28,62 +28,62 @@ |
||
| 28 | 28 | * Class TenantContext. |
| 29 | 29 | */ |
| 30 | 30 | class TenantContext implements TenantContextInterface { |
| 31 | - /** |
|
| 32 | - * @var TenantInterface |
|
| 33 | - */ |
|
| 34 | - protected $tenant; |
|
| 31 | + /** |
|
| 32 | + * @var TenantInterface |
|
| 33 | + */ |
|
| 34 | + protected $tenant; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var TenantResolverInterface |
|
| 38 | - */ |
|
| 39 | - protected $tenantResolver; |
|
| 36 | + /** |
|
| 37 | + * @var TenantResolverInterface |
|
| 38 | + */ |
|
| 39 | + protected $tenantResolver; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var RequestStack |
|
| 43 | - */ |
|
| 44 | - protected $requestStack; |
|
| 41 | + /** |
|
| 42 | + * @var RequestStack |
|
| 43 | + */ |
|
| 44 | + protected $requestStack; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var EventDispatcherInterface |
|
| 48 | - */ |
|
| 49 | - protected $dispatcher; |
|
| 46 | + /** |
|
| 47 | + * @var EventDispatcherInterface |
|
| 48 | + */ |
|
| 49 | + protected $dispatcher; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * TenantContext constructor. |
|
| 53 | - */ |
|
| 54 | - public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
| 55 | - EventDispatcherInterface $dispatcher) { |
|
| 51 | + /** |
|
| 52 | + * TenantContext constructor. |
|
| 53 | + */ |
|
| 54 | + public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
| 55 | + EventDispatcherInterface $dispatcher) { |
|
| 56 | 56 | $this->tenantResolver = $tenantResolver; |
| 57 | 57 | $this->requestStack = $requestStack; |
| 58 | 58 | $this->dispatcher = $dispatcher; |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritdoc} |
|
| 63 | - */ |
|
| 64 | - public function getTenant() { |
|
| 61 | + /** |
|
| 62 | + * {@inheritdoc} |
|
| 63 | + */ |
|
| 64 | + public function getTenant() { |
|
| 65 | 65 | if ($this->tenant !== null) |
| 66 | - return $this->tenant; |
|
| 66 | + return $this->tenant; |
|
| 67 | 67 | |
| 68 | 68 | $currentRequest = $this->requestStack->getCurrentRequest(); |
| 69 | 69 | if (null !== $currentRequest && false !== strpos($currentRequest->getRequestUri(), '_profiler')) { |
| 70 | - $profilerTenant = new Tenant(); |
|
| 71 | - $profilerTenant->setDomainName($currentRequest->getHost()); |
|
| 72 | - $this->setTenant($profilerTenant); |
|
| 73 | - return $profilerTenant; |
|
| 70 | + $profilerTenant = new Tenant(); |
|
| 71 | + $profilerTenant->setDomainName($currentRequest->getHost()); |
|
| 72 | + $this->setTenant($profilerTenant); |
|
| 73 | + return $profilerTenant; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $newTenant = $this->tenantResolver->resolve($currentRequest ? $currentRequest->getHost() : null); |
| 77 | 77 | $this->setTenant($newTenant); |
| 78 | 78 | return $newTenant; |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * {@inheritdoc} |
|
| 83 | - */ |
|
| 84 | - public function setTenant(TenantInterface $tenant) { |
|
| 81 | + /** |
|
| 82 | + * {@inheritdoc} |
|
| 83 | + */ |
|
| 84 | + public function setTenant(TenantInterface $tenant) { |
|
| 85 | 85 | $this->tenant = $tenant; |
| 86 | 86 | |
| 87 | 87 | $this->dispatcher->dispatch(new GenericEvent($tenant), MultiTenancyEvents::TENANT_SET); |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | return $paginator->paginate( |
| 79 | 79 | $queryBuilder, |
| 80 | 80 | (int)$criteria->get('firstResult', 0), |
| 81 | - (int)$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
| 81 | + (int)$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | |
| 37 | 37 | private function getPaths() : array |
| 38 | 38 | { |
| 39 | - return [$this->themeUploader->getAvailableThemesPath()]; |
|
| 39 | + return [$this->themeUploader->getAvailableThemesPath()]; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |