From d8f75116ee6740e21b4bffc531585a3457632f7d Mon Sep 17 00:00:00 2001 From: Ambroise Maupate Date: Fri, 8 Mar 2024 15:27:37 +0100 Subject: [PATCH] refactor: Removed deprecated Packages.php --- lib/Documents/src/Packages.php | 366 ---------------------- lib/RoadizCoreBundle/config/services.yaml | 2 - 2 files changed, 368 deletions(-) delete mode 100644 lib/Documents/src/Packages.php diff --git a/lib/Documents/src/Packages.php b/lib/Documents/src/Packages.php deleted file mode 100644 index 910d5524..00000000 --- a/lib/Documents/src/Packages.php +++ /dev/null @@ -1,366 +0,0 @@ -requestStackContext = new RequestStackContext($requestStack); - $this->requestStack = $requestStack; - $this->fileAware = $fileAware; - $this->staticDomain = $staticDomain; - $this->versionStrategy = $versionStrategy; - $this->ready = false; - } - - /** - * Defer creating package collection not to create error - * when warming up cache on dependency injection. - * These packages need a valid Request object. - */ - protected function initializePackages(): void - { - $this->setDefaultPackage($this->getDefaultPackage()); - $packages = [ - static::DOCUMENTS => $this->getDocumentPackage(), - static::PUBLIC_PATH => $this->getPublicPathPackage(), - static::PRIVATE_PATH => $this->getPrivatePathPackage(), - static::FONTS_PATH => $this->getFontsPathPackage(), - ]; - if (null !== $this->getRequest()) { - $packages = array_merge($packages, [ - static::ABSOLUTE => $this->getAbsoluteDefaultPackage(), - static::ABSOLUTE_DOCUMENTS => $this->getAbsoluteDocumentPackage(), - ]); - } - foreach ($packages as $name => $package) { - $this->addPackage((string) $name, $package); - } - $this->ready = true; - } - - /** - * @inheritDoc - */ - public function getPackage($name = null): PackageInterface - { - if (false === $this->ready) { - $this->initializePackages(); - } - - return parent::getPackage($name); - } - - /** - * @return bool - */ - public function useStaticDomain(): bool - { - return $this->staticDomain != ""; - } - - /** - * @return string - */ - protected function getStaticDomainAndPort(): string - { - /* - * Add non-default port to static domain. - */ - $staticDomainAndPort = $this->staticDomain; - $request = $this->getRequest(); - if ( - null !== $request - && (($this->requestStackContext->isSecure() && $request->getPort() != 443) - || (!$this->requestStackContext->isSecure() && $request->getPort() != 80)) - ) { - $staticDomainAndPort .= ':' . $request->getPort(); - } - - /* - * If no protocol, use https as default - */ - if ( - !preg_match("~^//~i", $staticDomainAndPort) - && !preg_match("~^(?:f|ht)tps?://~i", $staticDomainAndPort) - ) { - $staticDomainAndPort = "https://" . $staticDomainAndPort; - } - - return $staticDomainAndPort; - } - - /** - * @return PathPackage|UrlPackage - */ - protected function getDefaultPackage(): PathPackage|UrlPackage - { - if ($this->useStaticDomain()) { - return new UrlPackage( - $this->getStaticDomainAndPort(), - $this->versionStrategy - ); - } - - return new PathPackage( - '/', - $this->versionStrategy, - $this->requestStackContext - ); - } - - /** - * @return PathPackage|UrlPackage - */ - protected function getAbsoluteDefaultPackage(): PathPackage|UrlPackage - { - if ($this->useStaticDomain()) { - return $this->getDefaultPackage(); - } - $scheme = ''; - if (null !== $this->getRequest()) { - $scheme = $this->getRequest()->getSchemeAndHttpHost(); - } - return new UrlPackage( - $scheme . $this->requestStackContext->getBasePath(), - $this->versionStrategy - ); - } - - /** - * @return PathPackage|UrlPackage - */ - protected function getDocumentPackage(): PathPackage|UrlPackage - { - if ($this->useStaticDomain()) { - return new UrlPackage( - $this->getStaticDomainAndPort() . $this->fileAware->getPublicFilesBasePath(), - $this->versionStrategy - ); - } - - return new PathPackage( - $this->fileAware->getPublicFilesBasePath(), - $this->versionStrategy, - $this->requestStackContext - ); - } - - /** - * @return PathPackage|UrlPackage - */ - protected function getAbsoluteDocumentPackage(): PathPackage|UrlPackage - { - if ($this->useStaticDomain()) { - return $this->getDocumentPackage(); - } - $scheme = ''; - if (null !== $this->getRequest()) { - $scheme = $this->getRequest()->getSchemeAndHttpHost(); - } - return new UrlPackage( - $scheme . $this->requestStackContext->getBasePath() . $this->fileAware->getPublicFilesBasePath(), - $this->versionStrategy - ); - } - - /** - * @return PathPackage - */ - protected function getPublicPathPackage(): PathPackage - { - return new PathPackage( - $this->fileAware->getPublicFilesPath(), - $this->versionStrategy - ); - } - - /** - * @return PathPackage - */ - protected function getPrivatePathPackage(): PathPackage - { - return new PathPackage( - $this->fileAware->getPrivateFilesPath(), - $this->versionStrategy - ); - } - - /** - * @return PathPackage - */ - protected function getFontsPathPackage(): PathPackage - { - return new PathPackage( - $this->fileAware->getFontsFilesPath(), - $this->versionStrategy - ); - } - - /** - * Shortcut for $this->getUrl($relativePath, static::FONTS_PATH). - * - * @param string $relativePath - * @return string - * @deprecated Use FilesystemOperator font.storage instead to support external filesystems. - */ - public function getFontsPath(string $relativePath): string - { - return $this->getUrl($relativePath, static::FONTS_PATH); - } - - /** - * Shortcut for $this->getUrl($relativePath, static::PUBLIC_PATH). - * - * @param string $relativePath - * @return string - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function getPublicFilesPath(string $relativePath): string - { - return $this->getUrl($relativePath, static::PUBLIC_PATH); - } - - /** - * Shortcut for $this->getUrl($relativePath, static::PRIVATE_PATH). - * - * @param string $relativePath - * @return string - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function getPrivateFilesPath(string $relativePath): string - { - return $this->getUrl($relativePath, static::PRIVATE_PATH); - } - - /** - * @param DocumentInterface $document - * @return string Document file absolute path according if document is private or not. - * @throws DocumentWithoutFileException - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function getDocumentFilePath(DocumentInterface $document): string - { - if (!$document->isLocal()) { - throw new DocumentWithoutFileException($document); - } - if ($document->isPrivate()) { - return $this->getPrivateFilesPath($document->getRelativePath() ?? ''); - } - return $this->getPublicFilesPath($document->getRelativePath() ?? ''); - } - - /** - * @param DocumentInterface $document - * @return string Document folder absolute path according if document is private or not. - * @throws DocumentWithoutFileException - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function getDocumentFolderPath(DocumentInterface $document): string - { - if (!$document->isLocal()) { - throw new DocumentWithoutFileException($document); - } - if ($document->isPrivate()) { - return $this->getPrivateFilesPath($document->getFolder()); - } - return $this->getPublicFilesPath($document->getFolder()); - } - - /** - * @return string - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function getStaticDomain(): string - { - return $this->staticDomain; - } - - /** - * @param string $staticDomain - * @return Packages - * @deprecated Use FilesystemOperator documents.storage instead to support external filesystems. - */ - public function setStaticDomain(string $staticDomain): Packages - { - $this->staticDomain = $staticDomain; - return $this; - } - - /** - * @return null|Request - */ - protected function getRequest(): ?Request - { - return $this->requestStack->getMainRequest(); - } -} diff --git a/lib/RoadizCoreBundle/config/services.yaml b/lib/RoadizCoreBundle/config/services.yaml index c8a5f262..1e50e239 100644 --- a/lib/RoadizCoreBundle/config/services.yaml +++ b/lib/RoadizCoreBundle/config/services.yaml @@ -27,7 +27,6 @@ services: $cmsVersion: '%roadiz_core.cms_version%' $appVersion: '%roadiz_core.app_version%' $cmsVersionPrefix: '%roadiz_core.cms_version_prefix%' - $staticDomain: '%roadiz_core.static_domain_name%' $hideRoadizVersion: '%roadiz_core.hide_roadiz_version%' $inheritanceType: '%roadiz_core.inheritance_type%' $maxPixelSize: '%rz_intervention_request.max_pixel_size%' @@ -544,7 +543,6 @@ services: alias: RZ\Roadiz\CoreBundle\Filesystem\RoadizFileDirectories public: true - RZ\Roadiz\Documents\Packages: ~ RZ\Roadiz\Documents\DownscaleImageManager: ~ RZ\Roadiz\Documents\DocumentArchiver: ~ #