From 65c94080f6b8eae4a8217751de0dc847579c923d Mon Sep 17 00:00:00 2001
From: Sam Light <samlight1994@gmail.com>
Date: Sat, 15 Jun 2024 11:16:44 +0100
Subject: Initial commit

---
 src/Http/Controllers/SvgController.php | 17 +++++++++++
 src/SvgCollection.php                  | 30 +++++++++++++++++++
 src/SvgService.php                     | 53 ++++++++++++++++++++++++++++++++++
 src/SvgServiceProvider.php             | 39 +++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
 create mode 100644 src/Http/Controllers/SvgController.php
 create mode 100644 src/SvgCollection.php
 create mode 100644 src/SvgService.php
 create mode 100644 src/SvgServiceProvider.php

(limited to 'src')

diff --git a/src/Http/Controllers/SvgController.php b/src/Http/Controllers/SvgController.php
new file mode 100644
index 0000000..5296024
--- /dev/null
+++ b/src/Http/Controllers/SvgController.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Lightscale\LaralightSvg\Http\Controllers;
+
+use Lightscale\LaralightSvg\SvgService;
+
+use Illuminate\Http\Controller;
+
+class SvgController extends Controller
+{
+
+    public function serveSvg(SvgService $svg, string $collection)
+    {
+        \Log::debug($collection);
+    }
+
+}
diff --git a/src/SvgCollection.php b/src/SvgCollection.php
new file mode 100644
index 0000000..6d7407f
--- /dev/null
+++ b/src/SvgCollection.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Lightscale\LaralightSvg;
+
+
+class SvgCollection
+{
+    private array $paths = [];
+
+    public function __construct(
+        private string $name
+    )
+    {}
+
+    public function addPath(string $path)
+    {
+        $this->paths[] = $path;
+    }
+
+    public function getName(): string
+    {
+        return $this->name;
+    }
+
+    public function getSvgUrl(string $svg): string
+    {
+        return route('laralight-svg.serve-svg', $this->getName());
+    }
+
+}
diff --git a/src/SvgService.php b/src/SvgService.php
new file mode 100644
index 0000000..436e9ec
--- /dev/null
+++ b/src/SvgService.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Lightscale\LaralightSvg;
+
+class SvgService
+{
+    protected array $collections = [];
+
+    public function __construct()
+    {
+        $collections = config('svg.collections');
+
+        foreach ($collections as $k => $collection) {
+            $this->addCollectionConfig($k, $collection);
+        }
+    }
+
+    protected function addCollectionFromConfig(
+        string $collectionName,
+        array $collectionConfig
+    ): void
+    {
+        $c = new SvgCollection($collectionName);
+
+        foreach ($collectionConfig['paths'] as $p) {
+            $c->addPath($p);
+        }
+
+        $this->addCollection($c);
+    }
+
+
+    public function addCollection(SvgCollection $collection): void
+    {
+        $this->collections[$collection->getName()] = $collection;
+    }
+
+    public function registerCollection(string $collection): void
+    {
+        $this->addCollection(new SvgCollection($collection));
+    }
+
+    public function addCollectionPath(string $collection, string $path): void
+    {
+        $this->collections[$collection]->addPath($path);
+    }
+
+    public function getSvgUrl(string $collection, string $svg): string
+    {
+        return $this->collections[$collection]->getSvgUrl($collection, $svg);
+    }
+
+}
diff --git a/src/SvgServiceProvider.php b/src/SvgServiceProvider.php
new file mode 100644
index 0000000..a05effe
--- /dev/null
+++ b/src/SvgServiceProvider.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Lightscale\LaralightSvg;
+
+use Lightscale\LaralightSvg\Http\Controllers\SvgController;
+
+use Illuminate\Foundation\Console\AboutCommand;
+use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Route;
+
+class SvgServiceProvider extends ServiceProvider
+{
+    const NAMESPACE = 'laralight-svg';
+    const ROOT_PATH = __DIR__ . '../';
+
+    public $singletons = [
+        SvgService::class,
+    ];
+
+    public function boot()
+    {
+        AboutCommand::add('Laralight SVG', fn() => [
+            'Version' => 'dev'
+        ]);
+
+        $this->mergeConfigFrom(static::ROOT_PATH . '/config/svg.php', 'svg');
+        $this->loadViewsFrom(Service::ROOT_PATH . '/resources/views', static::NAMESPACE);
+
+        $this->publishes([
+            static::ROOT_PATH . '/config/svg.php' => config_path('svg.php'),
+        ], static::NAMESPACE . '-config');
+
+        Route::get($this->app['config']->get('svg.svg_route'), [SvgController::class, 'serveSvg'])
+             ->name('laralight-svg.serve-svg');
+
+
+    }
+
+}
-- 
cgit v1.2.3