From 06e25924552ccb7dd05880ed38aecd86bbda49e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Tue, 26 Nov 2019 16:26:47 +0100 Subject: [PATCH] Add asset path package class --- Asset/PathPackage.php | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Asset/PathPackage.php 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); + } +} -- 2.41.1