diff options
| -rw-r--r-- | src/File.php | 22 | ||||
| -rw-r--r-- | src/ScriptFile.php | 17 | ||||
| -rw-r--r-- | src/StyleFile.php | 17 | 
3 files changed, 55 insertions, 1 deletions
| diff --git a/src/File.php b/src/File.php index 3e64938..b2c52fc 100644 --- a/src/File.php +++ b/src/File.php @@ -2,7 +2,27 @@  namespace Lightscale\LaralightAssets; -class File +use Illuminate\Contracts\Support\Htmlable; + +abstract class File implements Htmlable  { +    private string $path; + +    protected function setPath(string $path): void +    { +        $this->path = $path; +    } + +    public function getPath(): string +    { +        return $this->path; +    } + +    public function hash(): string +    { +        $class = static::class; +        return md5("{$class}|{$this->path}"); +    } +    abstract public function toHtml(): string  } diff --git a/src/ScriptFile.php b/src/ScriptFile.php new file mode 100644 index 0000000..f8f11cd --- /dev/null +++ b/src/ScriptFile.php @@ -0,0 +1,17 @@ +<?php + +namespace Lightscale\LaralightAssets; + +class ScriptFile extends File +{ +    public function __construct(string $path) +    { +        $this->setPath($path); +    } + +    public function toHtml(): string +    { +        $path = $this->getPath(); +        return "<script src=\"{$path}\"></script>"; +    } +} diff --git a/src/StyleFile.php b/src/StyleFile.php new file mode 100644 index 0000000..ea3e425 --- /dev/null +++ b/src/StyleFile.php @@ -0,0 +1,17 @@ +<?php + +namespace Lightscale\LaralightAssets; + +class StyleFile extends File +{ +    public function __construct(string $path) +    { +        $this->setPath($path); +    } + +    public function toHtml(): string +    { +        $path = $this->getPath(); +        return "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$path}\" />"; +    } +} | 
