From 643ec0e1f2d4738984caed4753fe6c4f95302ca8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Wed, 14 Oct 2020 03:42:55 +0200 Subject: [PATCH 1/1] Rename pack_package into path_package --- Asset/PathPackage.php | 56 ++++++++++++++++++++++ Resources/config/packages/rapsys_pack.yaml | 6 +-- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Asset/PathPackage.php diff --git a/Asset/PathPackage.php b/Asset/PathPackage.php new file mode 100644 index 0000000..50c6172 --- /dev/null +++ b/Asset/PathPackage.php @@ -0,0 +1,56 @@ +basePath = '/'; + } else { + if ('/' != $basePath[0]) { + $basePath = '/'.$basePath; + } + + $this->basePath = rtrim($basePath, '/').'/'; + } + } + + /** + * @todo Try retrive public dir from the member function BundleNameBundle::getPublicDir() return value ? + * @xxx see https://symfony.com/doc/current/bundles.html#overridding-the-bundle-directory-structure + * {@inheritdoc} + */ + public function getUrl($path) { + //Match url starting with a bundle name + if (preg_match('%^@([A-Z][a-zA-Z]*?)(?:Bundle/Resources/public)?/(.*)$%', $path, $matches)) { + //Handle empty or without replacement pattern basePath + if (empty($this->basePath) || strpos($this->basePath, '%s') === false) { + //Set path from hardcoded format + $path = '/bundles/'.strtolower($matches[1]).'/'.$matches[2]; + //Proceed with basePath pattern replacement + } else { + //Set path from basePath pattern + //XXX: basePath has a trailing / added by constructor + $path = sprintf($this->basePath, strtolower($matches[1])).$matches[2]; + } + } + + //Return parent getUrl result + return parent::getUrl($path); + } +} diff --git a/Resources/config/packages/rapsys_pack.yaml b/Resources/config/packages/rapsys_pack.yaml index cdae053..0fe0346 100644 --- a/Resources/config/packages/rapsys_pack.yaml +++ b/Resources/config/packages/rapsys_pack.yaml @@ -1,11 +1,11 @@ #Services configuration services: #Register assets pack package - rapsys.pack_package: - class: 'Rapsys\PackBundle\Asset\PackPackage' + rapsys.path_package: + class: 'Rapsys\PackBundle\Asset\PathPackage' arguments: [ '/', '@assets.empty_version_strategy', '@assets.context' ] #Register twig pack extension rapsys.pack_extension: class: 'Rapsys\PackBundle\Twig\PackExtension' - arguments: [ '@file_locator', '@service_container', '@rapsys.pack_package' ] + arguments: [ '@file_locator', '@service_container', '@rapsys.path_package' ] tags: [ 'twig.extension' ] -- 2.41.1