diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/FileString.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/FileString.php b/src/FileString.php new file mode 100644 index 0000000..0bdca09 --- /dev/null +++ b/src/FileString.php @@ -0,0 +1,42 @@ +<?php + +namespace Lightscale\LaralightAssets; + +use Illuminate\Support\Str; +use Illuminate\Support\Collection; + +class FileString +{ + public ?string $manifestName = null; + public string $fileUri; + + + public function __construct(string $file) + { + $escape = '\\'; + $seperator = '::'; + $seperatorLen = strlen($seperator); + + $pos = 0; + while( + $pos !== false + ) { + $pos = strpos($file, $seperator, $pos); + if ($pos > 0 && $file[$pos - 1] === $escape) { + $pos += $seperatorLen; + } + else break; + } + + + $unescape = fn($v) => str_replace($escape . $seperator, $seperator, $v); + + if ($pos === false) { + $this->fileUri = $unescape($file); + } + else { + $this->manifestName = $unescape(substr($file, 0, $pos)); + $this->fileUri = $unescape(substr($file, $pos + $seperatorLen)); + } + } +} |