| @@ -41,14 +41,14 @@ discard block | ||
| 41 | 41 | use FOS\RestBundle\Controller\Annotations\Route; | 
| 42 | 42 | |
| 43 | 43 |  class ContentPushController extends AbstractController { | 
| 44 | - private EventDispatcherInterface $eventDispatcher; | |
| 45 | - private FormFactoryInterface $formFactory; | |
| 46 | - private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context | |
| 47 | - private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package | |
| 48 | - private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media | |
| 49 | - private EntityManagerInterface $entityManager; // swp.object_manager.media | |
| 50 | - private PackageRepository $packageRepository;//swp.repository.package | |
| 51 | - private FileProviderInterface $fileProvider; | |
| 44 | + private EventDispatcherInterface $eventDispatcher; | |
| 45 | + private FormFactoryInterface $formFactory; | |
| 46 | + private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context | |
| 47 | + private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package | |
| 48 | + private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media | |
| 49 | + private EntityManagerInterface $entityManager; // swp.object_manager.media | |
| 50 | + private PackageRepository $packageRepository;//swp.repository.package | |
| 51 | + private FileProviderInterface $fileProvider; | |
| 52 | 52 | |
| 53 | 53 | /** | 
| 54 | 54 | * @param EventDispatcherInterface $eventDispatcher | 
| @@ -60,11 +60,11 @@ discard block | ||
| 60 | 60 | * @param PackageRepository $packageRepository | 
| 61 | 61 | * @param FileProviderInterface $fileProvider | 
| 62 | 62 | */ | 
| 63 | - public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, | |
| 64 | - MessageBusInterface $messageBus, | |
| 65 | - DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, | |
| 66 | - EntityManagerInterface $entityManager, PackageRepository $packageRepository, | |
| 67 | -                              FileProviderInterface    $fileProvider) { | |
| 63 | + public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, | |
| 64 | + MessageBusInterface $messageBus, | |
| 65 | + DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, | |
| 66 | + EntityManagerInterface $entityManager, PackageRepository $packageRepository, | |
| 67 | +                                FileProviderInterface    $fileProvider) { | |
| 68 | 68 | $this->eventDispatcher = $eventDispatcher; | 
| 69 | 69 | $this->formFactory = $formFactory; | 
| 70 | 70 | $this->messageBus = $messageBus; | 
| @@ -73,13 +73,13 @@ discard block | ||
| 73 | 73 | $this->entityManager = $entityManager; | 
| 74 | 74 | $this->packageRepository = $packageRepository; | 
| 75 | 75 | $this->fileProvider = $fileProvider; | 
| 76 | - } | |
| 76 | + } | |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** | |
| 80 | -   * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") | |
| 81 | - */ | |
| 82 | -  public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { | |
| 79 | + /** | |
| 80 | +     * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") | |
| 81 | + */ | |
| 82 | +    public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { | |
| 83 | 83 | $package = $this->dataTransformer->transform($request->getContent()); | 
| 84 | 84 | $this->eventDispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); | 
| 85 | 85 | |
| @@ -88,27 +88,27 @@ discard block | ||
| 88 | 88 | $this->messageBus->dispatch(new ContentPushMessage($currentTenant->getId(), $request->getContent())); | 
| 89 | 89 | |
| 90 | 90 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); | 
| 91 | - } | |
| 91 | + } | |
| 92 | 92 | |
| 93 | - /** | |
| 94 | -   * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") | |
| 95 | - */ | |
| 96 | -  public function pushAssetsAction(Request $request): SingleResourceResponseInterface { | |
| 93 | + /** | |
| 94 | +     * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") | |
| 95 | + */ | |
| 96 | +    public function pushAssetsAction(Request $request): SingleResourceResponseInterface { | |
| 97 | 97 |      $form = $this->formFactory->createNamed('', MediaFileType::class); | 
| 98 | 98 | $form->handleRequest($request); | 
| 99 | 99 | |
| 100 | 100 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 101 | - $mediaManager = $this->mediaManager; | |
| 102 | - $uploadedFile = $form->getData()['media']; | |
| 103 | -      $mediaId = $request->request->get('mediaId'); | |
| 101 | + $mediaManager = $this->mediaManager; | |
| 102 | + $uploadedFile = $form->getData()['media']; | |
| 103 | +        $mediaId = $request->request->get('mediaId'); | |
| 104 | 104 | |
| 105 | -      if ($uploadedFile->isValid()) { | |
| 105 | +        if ($uploadedFile->isValid()) { | |
| 106 | 106 | $fileProvider = $this->fileProvider; | 
| 107 | 107 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $uploadedFile->guessExtension()); | 
| 108 | 108 | |
| 109 | 109 |          if (null === $file) { | 
| 110 | - $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); | |
| 111 | - $this->entityManager->flush(); | |
| 110 | + $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); | |
| 111 | + $this->entityManager->flush(); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | return new SingleResourceResponse( | 
| @@ -121,23 +121,23 @@ discard block | ||
| 121 | 121 | ], | 
| 122 | 122 | new ResponseContext(201) | 
| 123 | 123 | ); | 
| 124 | - } | |
| 124 | + } | |
| 125 | 125 | |
| 126 | -      throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); | |
| 126 | +        throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); | |
| 127 | 127 | } | 
| 128 | 128 | |
| 129 | 129 | return new SingleResourceResponse($form); | 
| 130 | - } | |
| 130 | + } | |
| 131 | 131 | |
| 132 | - /** | |
| 133 | -   * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") | |
| 134 | - */ | |
| 135 | -  public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { | |
| 132 | + /** | |
| 133 | +     * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") | |
| 134 | + */ | |
| 135 | +    public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { | |
| 136 | 136 | $fileProvider = $this->fileProvider; | 
| 137 | 137 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension); | 
| 138 | 138 | |
| 139 | 139 |      if (null === $file) { | 
| 140 | -      throw new NotFoundHttpException('Media don\'t exist in storage'); | |
| 140 | +        throw new NotFoundHttpException('Media don\'t exist in storage'); | |
| 141 | 141 | } | 
| 142 | 142 | |
| 143 | 143 | $mediaManager = $this->mediaManager; | 
| @@ -149,9 +149,9 @@ discard block | ||
| 149 | 149 | 'mime_type' => MimeTypeHelper::getByExtension($file->getFileExtension()), | 
| 150 | 150 | 'filemeta' => [], | 
| 151 | 151 | ]); | 
| 152 | - } | |
| 152 | + } | |
| 153 | 153 | |
| 154 | -  protected function getPackageRepository() { | |
| 154 | +    protected function getPackageRepository() { | |
| 155 | 155 | return $this->packageRepository; | 
| 156 | - } | |
| 156 | + } | |
| 157 | 157 | } | 
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | } | 
| 48 | 48 | } | 
| 49 | 49 | $mim = MimeTypeHelper::getByExtension($extension); | 
| 50 | -                $response->headers->set('Content-Type', $mim .'; charset=UTF-8'); | |
| 50 | +                $response->headers->set('Content-Type', $mim.'; charset=UTF-8'); | |
| 51 | 51 | } | 
| 52 | 52 | } | 
| 53 | 53 | } | 
| @@ -26,137 +26,137 @@ | ||
| 26 | 26 | use Symfony\Component\Routing\Annotation\Route; | 
| 27 | 27 | |
| 28 | 28 |  class StaticThemeAssetsController extends Controller { | 
| 29 | - /** | |
| 30 | - * Directory with assets inside theme. | |
| 31 | - */ | |
| 32 | - const ASSETS_DIRECTORY = 'public'; | |
| 33 | - | |
| 34 | - private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 35 | - private ThemeLoaderInterface $themeLoader; | |
| 36 | - private ThemeRepositoryInterface $themeRepository; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 40 | - * @param ThemeLoaderInterface $themeLoader | |
| 41 | - * @param ThemeRepositoryInterface $themeRepository | |
| 42 | - */ | |
| 43 | - public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 44 | - ThemeLoaderInterface $themeLoader, | |
| 45 | -                              ThemeRepositoryInterface         $themeRepository) { | |
| 29 | + /** | |
| 30 | + * Directory with assets inside theme. | |
| 31 | + */ | |
| 32 | + const ASSETS_DIRECTORY = 'public'; | |
| 33 | + | |
| 34 | + private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 35 | + private ThemeLoaderInterface $themeLoader; | |
| 36 | + private ThemeRepositoryInterface $themeRepository; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 40 | + * @param ThemeLoaderInterface $themeLoader | |
| 41 | + * @param ThemeRepositoryInterface $themeRepository | |
| 42 | + */ | |
| 43 | + public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 44 | + ThemeLoaderInterface $themeLoader, | |
| 45 | +                                ThemeRepositoryInterface         $themeRepository) { | |
| 46 | 46 | $this->tenantAwareThemeContext = $tenantAwareThemeContext; | 
| 47 | 47 | $this->themeLoader = $themeLoader; | 
| 48 | 48 | $this->themeRepository = $themeRepository; | 
| 49 | - } | |
| 49 | + } | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** | |
| 53 | -   * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) | |
| 54 | -   * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) | |
| 55 | -   * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) | |
| 56 | - */ | |
| 57 | -  public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { | |
| 52 | + /** | |
| 53 | +     * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) | |
| 54 | +     * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) | |
| 55 | +     * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) | |
| 56 | + */ | |
| 57 | +    public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { | |
| 58 | 58 | $themes = $themeHierarchyProvider->getThemeHierarchy( | 
| 59 | 59 | $this->tenantAwareThemeContext->getTheme() | 
| 60 | 60 | ); | 
| 61 | 61 | |
| 62 | 62 | $fileName = (null === $fileExtension) ? basename($fileName) : $fileName . '.' . $fileExtension; | 
| 63 | 63 |      foreach ($themes as $theme) { | 
| 64 | - $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; | |
| 65 | -      if (null !== $response = $this->handleFileLoading($filePath)) { | |
| 64 | + $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; | |
| 65 | +        if (null !== $response = $this->handleFileLoading($filePath)) { | |
| 66 | 66 | return $response; | 
| 67 | - } | |
| 67 | + } | |
| 68 | 68 | } | 
| 69 | 69 | |
| 70 | 70 |      throw new NotFoundHttpException('File was not found.'); | 
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | -   * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ | |
| 75 | - * "type": "organization|tenant" | |
| 76 | - * }) | |
| 77 | - */ | |
| 78 | -  public function screenshotsAction(string $type, string $themeName, $fileName) { | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | +     * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ | |
| 75 | + * "type": "organization|tenant" | |
| 76 | + * }) | |
| 77 | + */ | |
| 78 | +    public function screenshotsAction(string $type, string $themeName, $fileName) { | |
| 79 | 79 |      if ('organization' === $type) { | 
| 80 | -      $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); | |
| 80 | +        $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); | |
| 81 | 81 |      } elseif ('tenant' === $type) { | 
| 82 | -      $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); | |
| 82 | +        $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); | |
| 83 | 83 |      } else { | 
| 84 | -      throw new NotFoundHttpException('File was not found.'); | |
| 84 | +        throw new NotFoundHttpException('File was not found.'); | |
| 85 | 85 | } | 
| 86 | 86 | |
| 87 | 87 | $filePath = $theme->getPath() . '/screenshots/' . $fileName; | 
| 88 | 88 |      if (null !== $response = $this->handleFileLoading($filePath)) { | 
| 89 | - return $response; | |
| 89 | + return $response; | |
| 90 | 90 | } | 
| 91 | 91 | |
| 92 | 92 |      throw new NotFoundHttpException('File was not found.'); | 
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * @param $filePath | |
| 97 | - * | |
| 98 | - * @return Response | |
| 99 | - */ | |
| 100 | -  private function handleFileLoading($filePath) { | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @param $filePath | |
| 97 | + * | |
| 98 | + * @return Response | |
| 99 | + */ | |
| 100 | +    private function handleFileLoading($filePath) { | |
| 101 | 101 |      if (file_exists($filePath)) { | 
| 102 | - $response = new Response(file_get_contents($filePath)); | |
| 103 | - $disposition = $response->headers->makeDisposition( | |
| 104 | - ResponseHeaderBag::DISPOSITION_INLINE, | |
| 105 | - basename($filePath) | |
| 106 | - ); | |
| 107 | -      $response->headers->set('Content-Disposition', $disposition); | |
| 108 | - | |
| 109 | -      try { | |
| 110 | - $mime = MimeTypeHelper::getByPath($filePath); | |
| 111 | -      } catch (\Exception $e) { | |
| 102 | + $response = new Response(file_get_contents($filePath)); | |
| 103 | + $disposition = $response->headers->makeDisposition( | |
| 104 | + ResponseHeaderBag::DISPOSITION_INLINE, | |
| 105 | + basename($filePath) | |
| 106 | + ); | |
| 107 | +        $response->headers->set('Content-Disposition', $disposition); | |
| 108 | + | |
| 109 | +        try { | |
| 110 | + $mime = MimeTypeHelper::getByPath($filePath); | |
| 111 | +        } catch (\Exception $e) { | |
| 112 | 112 | $mime = 'text/plain'; | 
| 113 | - } | |
| 113 | + } | |
| 114 | 114 | |
| 115 | -      $response->headers->set('Content-Type', $mime); | |
| 116 | - $response->setStatusCode(Response::HTTP_OK); | |
| 117 | - $response->setPublic(); | |
| 118 | - $response->setMaxAge(3600); | |
| 119 | - $response->setSharedMaxAge(7200); | |
| 115 | +        $response->headers->set('Content-Type', $mime); | |
| 116 | + $response->setStatusCode(Response::HTTP_OK); | |
| 117 | + $response->setPublic(); | |
| 118 | + $response->setMaxAge(3600); | |
| 119 | + $response->setSharedMaxAge(7200); | |
| 120 | 120 | |
| 121 | - return $response; | |
| 121 | + return $response; | |
| 122 | + } | |
| 122 | 123 | } | 
| 123 | - } | |
| 124 | 124 | |
| 125 | - /** | |
| 126 | - * @return mixed | |
| 127 | - */ | |
| 128 | -  private function loadOrganizationTheme(string $themeName) { | |
| 125 | + /** | |
| 126 | + * @return mixed | |
| 127 | + */ | |
| 128 | +    private function loadOrganizationTheme(string $themeName) { | |
| 129 | 129 | $loadedThemes = $this->themeLoader->load(); | 
| 130 | 130 | |
| 131 | 131 | return $this->filterThemes($loadedThemes, $themeName); | 
| 132 | - } | |
| 132 | + } | |
| 133 | 133 | |
| 134 | - /** | |
| 135 | - * @return mixed | |
| 136 | - */ | |
| 137 | -  private function loadTenantTheme(string $themeName) { | |
| 134 | + /** | |
| 135 | + * @return mixed | |
| 136 | + */ | |
| 137 | +    private function loadTenantTheme(string $themeName) { | |
| 138 | 138 | $loadedThemes = $this->themeRepository->findAll(); | 
| 139 | 139 | |
| 140 | 140 | return $this->filterThemes($loadedThemes, $themeName); | 
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * @param array $loadedThemes | |
| 145 | - * | |
| 146 | - * @return mixed | |
| 147 | - */ | |
| 148 | -  private function filterThemes($loadedThemes, string $themeName) { | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * @param array $loadedThemes | |
| 145 | + * | |
| 146 | + * @return mixed | |
| 147 | + */ | |
| 148 | +    private function filterThemes($loadedThemes, string $themeName) { | |
| 149 | 149 | $themes = array_filter( | 
| 150 | 150 | $loadedThemes, | 
| 151 | 151 |          function ($element) use (&$themeName) { | 
| 152 | - return $element->getName() === $themeName; | |
| 152 | + return $element->getName() === $themeName; | |
| 153 | 153 | } | 
| 154 | 154 | ); | 
| 155 | 155 | |
| 156 | 156 |      if (0 === count($themes)) { | 
| 157 | -      throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); | |
| 157 | +        throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); | |
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | 160 | return reset($themes); | 
| 161 | - } | |
| 161 | + } | |
| 162 | 162 | } | 
| @@ -29,50 +29,50 @@ | ||
| 29 | 29 | |
| 30 | 30 |  class ThemeLogoController extends Controller { | 
| 31 | 31 | |
| 32 | - private Filesystem $filesystem; | |
| 33 | - private ThemeLogoUploaderInterface $themeLogoUploader; | |
| 34 | - private CacheInterface $cacheInterface; | |
| 32 | + private Filesystem $filesystem; | |
| 33 | + private ThemeLogoUploaderInterface $themeLogoUploader; | |
| 34 | + private CacheInterface $cacheInterface; | |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * @param Filesystem $filesystem | |
| 38 | - * @param ThemeLogoUploaderInterface $themeLogoUploader | |
| 39 | - * @param CacheInterface $cacheInterface | |
| 40 | - */ | |
| 41 | - public function __construct(Filesystem $filesystem, ThemeLogoUploaderInterface $themeLogoUploader, | |
| 42 | -                              CacheInterface $cacheInterface) { | |
| 36 | + /** | |
| 37 | + * @param Filesystem $filesystem | |
| 38 | + * @param ThemeLogoUploaderInterface $themeLogoUploader | |
| 39 | + * @param CacheInterface $cacheInterface | |
| 40 | + */ | |
| 41 | + public function __construct(Filesystem $filesystem, ThemeLogoUploaderInterface $themeLogoUploader, | |
| 42 | +                                CacheInterface $cacheInterface) { | |
| 43 | 43 | $this->filesystem = $filesystem; | 
| 44 | 44 | $this->themeLogoUploader = $themeLogoUploader; | 
| 45 | 45 | $this->cacheInterface = $cacheInterface; | 
| 46 | - } | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | -   * @Route("/theme_logo/{id}", options={"expose"=true}, requirements={"id"=".+"}, methods={"GET"}, name="swp_theme_logo_get") | |
| 50 | - */ | |
| 51 | -  public function getLogoAction(string $id) { | |
| 48 | + /** | |
| 49 | +     * @Route("/theme_logo/{id}", options={"expose"=true}, requirements={"id"=".+"}, methods={"GET"}, name="swp_theme_logo_get") | |
| 50 | + */ | |
| 51 | +    public function getLogoAction(string $id) { | |
| 52 | 52 | $cacheKey = md5(serialize(['upload', $id])); | 
| 53 | 53 |      return $this->cacheInterface->get($cacheKey, function (CacheItemInterface $item, &$save) use ($id) { | 
| 54 | - $item->expiresAfter(63072000); | |
| 54 | + $item->expiresAfter(63072000); | |
| 55 | 55 | |
| 56 | - $fileSystem = $this->filesystem; | |
| 57 | - $themeLogoUploader = $this->themeLogoUploader; | |
| 58 | - $id = $themeLogoUploader->getThemeLogoUploadPath($id); | |
| 59 | - $file = $fileSystem->has($id); | |
| 60 | -      if (!$file) { | |
| 56 | + $fileSystem = $this->filesystem; | |
| 57 | + $themeLogoUploader = $this->themeLogoUploader; | |
| 58 | + $id = $themeLogoUploader->getThemeLogoUploadPath($id); | |
| 59 | + $file = $fileSystem->has($id); | |
| 60 | +        if (!$file) { | |
| 61 | 61 | $save = false; | 
| 62 | 62 |          throw new NotFoundHttpException('File was not found.'); | 
| 63 | - } | |
| 63 | + } | |
| 64 | 64 | |
| 65 | - $path = $fileSystem->get($id)->getPath(); | |
| 66 | - $response = new Response(); | |
| 67 | - $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, pathinfo($path, PATHINFO_BASENAME)); | |
| 68 | -      $response->headers->set('Content-Disposition', $disposition); | |
| 69 | -      $response->headers->set('Content-Type', MimeTypeHelper::getByPath($path)); | |
| 70 | - $response->setPublic(); | |
| 71 | - $response->setMaxAge(63072000); | |
| 72 | - $response->setSharedMaxAge(63072000); | |
| 73 | - $response->setContent($fileSystem->read($path)); | |
| 65 | + $path = $fileSystem->get($id)->getPath(); | |
| 66 | + $response = new Response(); | |
| 67 | + $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, pathinfo($path, PATHINFO_BASENAME)); | |
| 68 | +        $response->headers->set('Content-Disposition', $disposition); | |
| 69 | +        $response->headers->set('Content-Type', MimeTypeHelper::getByPath($path)); | |
| 70 | + $response->setPublic(); | |
| 71 | + $response->setMaxAge(63072000); | |
| 72 | + $response->setSharedMaxAge(63072000); | |
| 73 | + $response->setContent($fileSystem->read($path)); | |
| 74 | 74 | |
| 75 | - return $response; | |
| 75 | + return $response; | |
| 76 | 76 | }); | 
| 77 | - } | |
| 77 | + } | |
| 78 | 78 | } | 
| @@ -50,38 +50,38 @@ | ||
| 50 | 50 | protected function execute(InputInterface $input, OutputInterface $output) | 
| 51 | 51 |      { | 
| 52 | 52 |          $dir = $this->container->getParameter('kernel.project_dir'); | 
| 53 | -        $path = $dir . '/' . $input->getArgument('path'); | |
| 53 | +        $path = $dir.'/'.$input->getArgument('path'); | |
| 54 | 54 | |
| 55 | 55 |          if (!file_exists($path)) { | 
| 56 | -            throw new \InvalidArgumentException('File ' . $path . ' doe not exist.'); | |
| 56 | +            throw new \InvalidArgumentException('File '.$path.' doe not exist.'); | |
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | -        $output->writeln('<info>Checking file:</info> ' . $path); | |
| 59 | +        $output->writeln('<info>Checking file:</info> '.$path); | |
| 60 | 60 | |
| 61 | 61 | $mimType = new FileBinaryMimeTypeGuesser(); | 
| 62 | -        $output->writeln('<info>FileBinaryMimeTypeGuesser:</info> ' . $mimType->guessMimeType($path)); | |
| 62 | +        $output->writeln('<info>FileBinaryMimeTypeGuesser:</info> '.$mimType->guessMimeType($path)); | |
| 63 | 63 | |
| 64 | 64 | $mimType = new FileinfoMimeTypeGuesser(); | 
| 65 | -        $output->writeln('<info>FileinfoMimeTypeGuesser:</info> ' . $mimType->guessMimeType($path)); | |
| 65 | +        $output->writeln('<info>FileinfoMimeTypeGuesser:</info> '.$mimType->guessMimeType($path)); | |
| 66 | 66 | |
| 67 | 67 | $mim = MimeTypes::getDefault()->guessMimeType($path); | 
| 68 | -        $output->writeln('<info>Default Symfony MimType:</info> ' . $mim); | |
| 68 | +        $output->writeln('<info>Default Symfony MimType:</info> '.$mim); | |
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | $mimByExtension = MimeTypes::getDefault()->getMimeTypes($ext = pathinfo($path, PATHINFO_EXTENSION)); | 
| 72 | -        $output->writeln('<info>MimType by extension:</info> ' . implode(',', $mimByExtension)); | |
| 72 | +        $output->writeln('<info>MimType by extension:</info> '.implode(',', $mimByExtension)); | |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | $mimExtension = MimeTypes::getDefault()->getExtensions($mimByExtension[0]); | 
| 76 | -        $output->writeln('<info>Extension of mim types:</info> ' . $mimByExtension[0] . ' <info>is:</info> ' . implode(',', $mimExtension)); | |
| 76 | +        $output->writeln('<info>Extension of mim types:</info> '.$mimByExtension[0].' <info>is:</info> '.implode(',', $mimExtension)); | |
| 77 | 77 | |
| 78 | 78 |          $output->writeln('--------------- My ----------------'); | 
| 79 | 79 | |
| 80 | -        $output->writeln('<info>My MimTypes checker:</info> ' . \SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getByPath($path)); | |
| 81 | -        $output->writeln('<info>My Extensions by MimTypes checker:</info> ' . \SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('application/json')); | |
| 82 | -        $output->writeln('<info>My Extensions by MimTypes checker:</info> ' . \SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('application/javascript')); | |
| 83 | -        $output->writeln('<info>My Extensions by MimTypes checker:</info> ' . \SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('image/png')); | |
| 84 | -        $output->writeln('<info>My Extensions by MimTypes checker:</info> ' . \SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('image/jpeg')); | |
| 80 | +        $output->writeln('<info>My MimTypes checker:</info> '.\SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getByPath($path)); | |
| 81 | +        $output->writeln('<info>My Extensions by MimTypes checker:</info> '.\SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('application/json')); | |
| 82 | +        $output->writeln('<info>My Extensions by MimTypes checker:</info> '.\SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('application/javascript')); | |
| 83 | +        $output->writeln('<info>My Extensions by MimTypes checker:</info> '.\SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('image/png')); | |
| 84 | +        $output->writeln('<info>My Extensions by MimTypes checker:</info> '.\SWP\Bundle\CoreBundle\Util\MimeTypeHelper::getExtensionByMimeType('image/jpeg')); | |
| 85 | 85 | |
| 86 | 86 | return 0; | 
| 87 | 87 | } | 
| @@ -20,7 +20,7 @@ discard block | ||
| 20 | 20 | * @param bool $all | 
| 21 | 21 | * @return array|string | 
| 22 | 22 | */ | 
| 23 | - public static function getByPath(string $path, bool $all = false): array|string | |
| 23 | + public static function getByPath(string $path, bool $all = false): array | string | |
| 24 | 24 |      { | 
| 25 | 25 | $ext = pathinfo($path, PATHINFO_EXTENSION); | 
| 26 | 26 | return self::getByExtension($ext, $all); | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | * @param bool $all | 
| 32 | 32 | * @return array|string | 
| 33 | 33 | */ | 
| 34 | - public static function getByExtension(string $ext, bool $all = false): array|string | |
| 34 | + public static function getByExtension(string $ext, bool $all = false): array | string | |
| 35 | 35 |      { | 
| 36 | 36 | $mimeType = MimeTypes::getDefault(); | 
| 37 | 37 | $types = $mimeType->getMimeTypes($ext); | 
| @@ -52,7 +52,7 @@ discard block | ||
| 52 | 52 | * @param bool $all | 
| 53 | 53 | * @return array|string | 
| 54 | 54 | */ | 
| 55 | - public static function getExtensionByMimeType(string $mime, bool $all = false): array|string | |
| 55 | + public static function getExtensionByMimeType(string $mime, bool $all = false): array | string | |
| 56 | 56 |      { | 
| 57 | 57 | $mimeType = MimeTypes::getDefault(); | 
| 58 | 58 | $extensions = $mimeType->getExtensions($mime); |