]> Raphaƫl G. Git Repositories - packbundle/blobdiff - Asset/PathPackage.php
Fix indentation
[packbundle] / Asset / PathPackage.php
index 371ffccf9be42c04d76bebd02258adc564a11724..50c6172b16d2668439428ed805ab9c0bb0704cdd 100644 (file)
@@ -3,13 +3,13 @@
 namespace Rapsys\PackBundle\Asset;
 
 use Symfony\Component\Asset\Context\ContextInterface;
 namespace Rapsys\PackBundle\Asset;
 
 use Symfony\Component\Asset\Context\ContextInterface;
-use Symfony\Component\Asset\PathPackage as BasePackage;
+use Symfony\Component\Asset\Package;
 use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
 
 /**
  * (@inheritdoc)
  */
 use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
 
 /**
  * (@inheritdoc)
  */
-class PathPackage extends BasePackage {
+class PathPackage extends Package {
        //The base path
        protected $basePath;
 
        //The base path
        protected $basePath;
 
@@ -17,7 +17,7 @@ class PathPackage extends BasePackage {
         * {@inheritdoc}
         */
        public function __construct(string $basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null) {
         * {@inheritdoc}
         */
        public function __construct(string $basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null) {
-               parent::__construct($basePath, $versionStrategy, $context);
+               parent::__construct($versionStrategy, $context);
 
                if (!$basePath) {
                        $this->basePath = '/';
 
                if (!$basePath) {
                        $this->basePath = '/';
@@ -31,18 +31,21 @@ class PathPackage extends BasePackage {
        }
 
        /**
        }
 
        /**
+        * @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
         * {@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)) {
+               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
                        //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];
+                               $path = '/bundles/'.strtolower($matches[1]).'/'.$matches[2];
                        //Proceed with basePath pattern replacement
                        } else {
                                //Set path from basePath pattern
                        //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];
                        }
                }
                                $path = sprintf($this->basePath, strtolower($matches[1])).$matches[2];
                        }
                }