diff options
| author | Sam Light <sam@lightscale.co.uk> | 2025-03-31 22:07:52 +0100 | 
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2025-03-31 22:07:52 +0100 | 
| commit | 68fc7984097c4373d7b73538260b13dd5b4a8340 (patch) | |
| tree | 4ab482231bac3eaa3ee0e66ee7282216bbf3f9b4 /src | |
| parent | 3c1056bdee2798d6bd5d9aad2f60ccbb8cb1d8d9 (diff) | |
Create FileString class
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)); +        } +    } +} | 
