@@ -31,12 +31,12 @@ |
||
31 | 31 | */ |
32 | 32 | public function generate($name, $parameters = [], $referenceType = false) |
33 | 33 | { |
34 | - if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name |
|
34 | + if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name |
|
35 | 35 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
36 | - ) { |
|
36 | + ) { |
|
37 | 37 | $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
38 | 38 | unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | if (null === $name && isset($parameters['content_id'])) { |
42 | 42 | $contentId = $this->checkAndRemoveFirstSlash($parameters['content_id']); |
@@ -17,7 +17,7 @@ |
||
17 | 17 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
18 | 18 | |
19 | 19 | class TenantNotFoundException extends NotFoundHttpException { |
20 | - public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { |
|
20 | + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { |
|
21 | 21 | parent::__construct(sprintf('Tenant for host "%s" could not be found! Please check tenants configuration.', $message), $previous, $code, $headers); |
22 | - } |
|
22 | + } |
|
23 | 23 | } |
@@ -24,43 +24,43 @@ discard block |
||
24 | 24 | use Symfony\Component\Routing\Route as SymfonyRoute; |
25 | 25 | |
26 | 26 | class MetaRouter extends DynamicRouter { |
27 | - const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__"; |
|
27 | + const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__"; |
|
28 | 28 | |
29 | - protected $internalRoutesCache = []; |
|
29 | + protected $internalRoutesCache = []; |
|
30 | 30 | |
31 | - public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
31 | + public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
32 | 32 | if (self::OBJECT_BASED_ROUTE_NAME === $name |
33 | 33 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
34 | 34 | ) { |
35 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
36 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
35 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
36 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $cacheKey = $this->getCacheKey($name, $parameters, $referenceType); |
40 | 40 | if (array_key_exists($cacheKey, $this->internalRoutesCache)) { |
41 | - return $this->internalRoutesCache[$cacheKey]; |
|
41 | + return $this->internalRoutesCache[$cacheKey]; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $route = $name; |
45 | 45 | if ($name instanceof Meta) { |
46 | - $object = $name->getValues(); |
|
47 | - if ($object instanceof ArticleInterface) { |
|
46 | + $object = $name->getValues(); |
|
47 | + if ($object instanceof ArticleInterface) { |
|
48 | 48 | $parameters['slug'] = $object->getSlug(); |
49 | 49 | $route = $object->getRoute(); |
50 | 50 | if (null === $route && $name->getContext()->getCurrentPage()) { |
51 | - $parameters['slug'] = null; |
|
52 | - $route = $name->getContext()->getCurrentPage()->getValues(); |
|
51 | + $parameters['slug'] = null; |
|
52 | + $route = $name->getContext()->getCurrentPage()->getValues(); |
|
53 | 53 | } |
54 | - } elseif ($name->getValues() instanceof RouteInterface) { |
|
54 | + } elseif ($name->getValues() instanceof RouteInterface) { |
|
55 | 55 | $route = $name->getValues(); |
56 | - } |
|
56 | + } |
|
57 | 57 | } elseif ($name instanceof ArticleInterface) { |
58 | - $route = $name->getRoute(); |
|
59 | - $parameters['slug'] = $name->getSlug(); |
|
58 | + $route = $name->getRoute(); |
|
59 | + $parameters['slug'] = $name->getSlug(); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | if (null === $route || is_array($route)) { |
63 | - throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); |
|
63 | + throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $result = parent::generate($route, $parameters, $referenceType); |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | unset($route); |
69 | 69 | |
70 | 70 | return $result; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - private function getCacheKey($route, $parameters, $type) { |
|
73 | + private function getCacheKey($route, $parameters, $type) { |
|
74 | 74 | $name = $route; |
75 | 75 | if ($route instanceof Meta) { |
76 | - if ($route->getValues() instanceof ArticleInterface) { |
|
76 | + if ($route->getValues() instanceof ArticleInterface) { |
|
77 | 77 | $name = $route->getValues()->getId(); |
78 | - } elseif ($route->getValues() instanceof RouteInterface) { |
|
78 | + } elseif ($route->getValues() instanceof RouteInterface) { |
|
79 | 79 | $name = $route->getValues()->getName(); |
80 | - } |
|
80 | + } |
|
81 | 81 | } elseif ($route instanceof RouteInterface) { |
82 | - $name = $route->getName(); |
|
82 | + $name = $route->getName(); |
|
83 | 83 | } elseif ($route instanceof ArticleInterface) { |
84 | - $name = $route->getId(); |
|
84 | + $name = $route->getId(); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return md5($name . serialize($parameters) . $type); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * {@inheritdoc} |
|
92 | - */ |
|
93 | - public function supports($name) { |
|
90 | + /** |
|
91 | + * {@inheritdoc} |
|
92 | + */ |
|
93 | + public function supports($name) { |
|
94 | 94 | return |
95 | 95 | ($name instanceof Meta && ( |
96 | 96 | $name->getValues() instanceof ArticleInterface || |
@@ -106,5 +106,5 @@ discard block |
||
106 | 106 | 'swp_media_get' !== $name && |
107 | 107 | false === strpos($name, 'swp_api_') |
108 | 108 | ); |
109 | - } |
|
109 | + } |
|
110 | 110 | } |
@@ -27,53 +27,53 @@ |
||
27 | 27 | |
28 | 28 | class ArticleAuthorMediaRouter extends Router implements VersatileGeneratorInterface { |
29 | 29 | |
30 | - const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__"; |
|
30 | + const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__"; |
|
31 | 31 | |
32 | - protected $authorMediaManager; |
|
32 | + protected $authorMediaManager; |
|
33 | 33 | |
34 | - public function __construct( |
|
35 | - ContainerInterface $container, |
|
36 | - $resource, |
|
37 | - array $options = [], |
|
38 | - RequestContext $context = null, |
|
39 | - ContainerInterface $parameters = null, |
|
40 | - LoggerInterface $logger = null, |
|
41 | - string $defaultLocale = null |
|
42 | - ) { |
|
34 | + public function __construct( |
|
35 | + ContainerInterface $container, |
|
36 | + $resource, |
|
37 | + array $options = [], |
|
38 | + RequestContext $context = null, |
|
39 | + ContainerInterface $parameters = null, |
|
40 | + LoggerInterface $logger = null, |
|
41 | + string $defaultLocale = null |
|
42 | + ) { |
|
43 | 43 | $this->authorMediaManager = $container->get('swp_core_bundle.manager.author_media'); |
44 | 44 | |
45 | 45 | parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale); |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
48 | + public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { |
|
49 | 49 | if (self::OBJECT_BASED_ROUTE_NAME === $meta |
50 | 50 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
51 | 51 | ) { |
52 | - $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
53 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
52 | + $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
53 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | if ($meta instanceof Meta && ($meta->getValues() instanceof AuthorMediaInterface)) { |
57 | - return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage()); |
|
57 | + return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return ''; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function supports($name) { |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function supports($name) { |
|
67 | 67 | return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && ($name->getValues() instanceof AuthorMediaInterface)); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - public function getRouteDebugMessage($name, array $parameters = []) { |
|
70 | + public function getRouteDebugMessage($name, array $parameters = []) { |
|
71 | 71 | if (self::OBJECT_BASED_ROUTE_NAME === $name |
72 | 72 | && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters) |
73 | 73 | ) { |
74 | - $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
75 | - unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
74 | + $name = $parameters[RouteObjectInterface::ROUTE_OBJECT]; |
|
75 | + unset($parameters[RouteObjectInterface::ROUTE_OBJECT]); |
|
76 | 76 | } |
77 | 77 | return 'Route for article author media ' . $name->getValues()->getId() . ' not found'; |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
@@ -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 | } |