summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2025-03-30 22:22:27 +0100
committerSam Light <samlight1994@gmail.com>2025-03-30 22:22:27 +0100
commit41eda0c73d0a1f5273ccacac57176f450c294e04 (patch)
treecf2caf6cfc247784823906da2d8b4115886d9171
parent5ed1fd22ac92e78c3feae6b1c33df35f3d3cab60 (diff)
Some basic structure
-rw-r--r--src/Assets.php22
-rw-r--r--src/AssetsServiceProvider.php14
-rw-r--r--src/Contracts/ManifestParser.php8
-rw-r--r--src/File.php8
-rw-r--r--src/JsonManifestParser.php13
-rw-r--r--src/Manifest.php51
6 files changed, 116 insertions, 0 deletions
diff --git a/src/Assets.php b/src/Assets.php
new file mode 100644
index 0000000..78cbe59
--- /dev/null
+++ b/src/Assets.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Lightscale\LaralightAssets;
+
+class Assets
+{
+ private string $manifestParser;
+ private array $manifests = [];
+ private array $manifestsParsers = [];
+ private array $files = [];
+ private array $queuedHeadFiles = [];
+ private array $queuedFooterFiles = [];
+
+ public function registerManifest(
+ string $name,
+ string $path,
+ string $baseUrl,
+ ): void
+ {
+
+ }
+}
diff --git a/src/AssetsServiceProvider.php b/src/AssetsServiceProvider.php
new file mode 100644
index 0000000..c59be48
--- /dev/null
+++ b/src/AssetsServiceProvider.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Lightscale\LaralightAssets;
+
+use Illuminate\Support\ServiceProvider;
+
+class AssetsServiceProvider extends ServiceProvider
+{
+
+ public function register(): void
+ {
+
+ }
+}
diff --git a/src/Contracts/ManifestParser.php b/src/Contracts/ManifestParser.php
new file mode 100644
index 0000000..d4442aa
--- /dev/null
+++ b/src/Contracts/ManifestParser.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Lightscale\LaralightAssets\Contracts;
+
+interface ManifestParser
+{
+ public function parse(string $data): array;
+}
diff --git a/src/File.php b/src/File.php
new file mode 100644
index 0000000..3e64938
--- /dev/null
+++ b/src/File.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Lightscale\LaralightAssets;
+
+class File
+{
+
+}
diff --git a/src/JsonManifestParser.php b/src/JsonManifestParser.php
new file mode 100644
index 0000000..9293af1
--- /dev/null
+++ b/src/JsonManifestParser.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace Lightscale\LaralightAssets;
+
+use Lightscale\LaralightAssets\Contracts\ManifestParser;
+
+class JsonManifestParser implements ManifestParser
+{
+ public function parse(string $data): array
+ {
+ return json_decode($data, true);
+ }
+}
diff --git a/src/Manifest.php b/src/Manifest.php
new file mode 100644
index 0000000..b7c5e96
--- /dev/null
+++ b/src/Manifest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Lightscale\LaralightAssets;
+
+class Manifest
+{
+ private ?array $data;
+
+ public function __construct(
+ private string $path,
+ private string $baseUrl,
+ private string $parserClass = JsonManifestParser::class,
+ ) {}
+
+ private function readFile(): string
+ {
+ return filegetcontents($this->path);
+ }
+
+ private function loadData(): void
+ {
+ $data = $this->readFile();
+ $parser = new $this->parserClass;
+ $this->data = $parser->parse($data);
+ }
+
+ private function getData(): array
+ {
+ if ($this->data === null) $this->loadData();
+ return $this->data;
+ }
+
+ public function getFile(string $file): ?string
+ {
+ return $this->getData()[$file] ?? null;
+ }
+
+ public function getUrl(string $file): ?string
+ {
+ $file = $this->getFile($file);
+ return $file === null ? null : "{$this->baseUrl}/{$file}";
+ }
+
+ public function getPath(string $file): ?string
+ {
+ $file = $this->getFile($file);
+ $dir = $this->getDir();
+ return $file === null ? null : "{$dir}/{$file}";
+ }
+
+}