From 65c94080f6b8eae4a8217751de0dc847579c923d Mon Sep 17 00:00:00 2001 From: Sam Light 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 @@ +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 @@ + $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 @@ + [ + '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