From: Raphaƫl Gertz Date: Tue, 26 Nov 2019 15:26:47 +0000 (+0100) Subject: Add asset path package class X-Git-Tag: 0.1.3~8 X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/packbundle/commitdiff_plain/06e25924552ccb7dd05880ed38aecd86bbda49e8?hp=ba4cac691e8a7a3dd193680ee2414b6aac0c1088 Add asset path package class --- diff --git a/Asset/PathPackage.php b/Asset/PathPackage.php new file mode 100644 index 0000000..371ffcc --- /dev/null +++ b/Asset/PathPackage.php @@ -0,0 +1,53 @@ +basePath = '/'; + } else { + if ('/' != $basePath[0]) { + $basePath = '/'.$basePath; + } + + $this->basePath = rtrim($basePath, '/').'/'; + } + } + + /** + * {@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 + $path = sprintf($this->basePath, strtolower($matches[1])).$matches[2]; + } + } + + //Return parent getUrl result + return parent::getUrl($path); + } +}