3 namespace Rapsys\PackBundle\Asset
;
5 use Symfony\Component\Asset\Context\ContextInterface
;
6 use Symfony\Component\Asset\Package
;
7 use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface
;
12 class PathPackage
extends Package
{
19 public function __construct(string $basePath, VersionStrategyInterface
$versionStrategy, ContextInterface
$context = null) {
20 parent
::__construct($versionStrategy, $context);
23 $this->basePath
= '/';
25 if ('/' != $basePath[0]) {
26 $basePath = '/'.$basePath;
29 $this->basePath
= rtrim($basePath, '/').'/';
34 * @todo Try retrive public dir from the member function BundleNameBundle::getPublicDir() return value ?
35 * @xxx see https://symfony.com/doc/current/bundles.html#overridding-the-bundle-directory-structure
38 public function getUrl($path) {
39 //Match url starting with a bundle name
40 if (preg_match('%^@([A-Z][a-zA-Z]*?)(?:Bundle/Resources/public)?/(.*)$%', $path, $matches)) {
41 //Handle empty or without replacement pattern basePath
42 if (empty($this->basePath
) || strpos($this->basePath
, '%s') === false) {
43 //Set path from hardcoded format
44 $path = '/bundles/'.strtolower($matches[1]).'/'.$matches[2];
45 //Proceed with basePath pattern replacement
47 //Set path from basePath pattern
48 //XXX: basePath has a trailing / added by constructor
49 $path = sprintf($this->basePath
, strtolower($matches[1])).$matches[2];
53 //Return parent getUrl result
54 return parent
::getUrl($path);