From 741124f8147f0884d3b2c10a34253e1ff133c54d Mon Sep 17 00:00:00 2001 From: Mark van Eijk Date: Fri, 12 Apr 2024 17:32:30 +0200 Subject: [PATCH] wip --- src/CachesValue.php | 21 +++++++++++---------- src/PermanentCacheServiceProvider.php | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/CachesValue.php b/src/CachesValue.php index 497a628..8e0273d 100644 --- a/src/CachesValue.php +++ b/src/CachesValue.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\PendingDispatch; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Cache; use Illuminate\View\View; use ReflectionClass; @@ -48,17 +49,17 @@ trait CachesValue * * @internal You shouldn't call this yourself. */ - final public function handle($event = null): void + final public function handle($parameters): void { [$driver, $ident] = self::store(); - /** @phpstan-ignore-next-line */ - if (null === $value = $this->{self::getUpdateMethodString()}($event)) { - return; + if(is_subclass_of(static::class, CachedComponent::class)) { + $value = Blade::renderComponent($this); } - if (is_a($value, View::class)) { - $value = (string) $value; + /** @phpstan-ignore-next-line */ + if (null === $value = $this->{self::getUpdateMethodString()}()) { + return; } Cache::driver($driver)->forever($ident, $value); @@ -67,12 +68,12 @@ final public function handle($event = null): void /** * Manually force a static cache to update. */ - final public static function update(): ?PendingDispatch + final public static function update($parameters = []): ?PendingDispatch { - $instance = app()->make(static::class); + $instance = app()->make(static::class, $parameters); if (! is_a(static::class, ShouldQueue::class, true)) { - $instance->handle(); + $instance->handle($parameters); return null; } @@ -122,7 +123,7 @@ final protected function value($default = null): mixed public static function schedule($callback) { if (! is_a(static::class, Scheduled::class, true)) { - throw new \Exception('Can not schedule a cacher that does not implement the ['.Scheduled::class.'] interface'); + throw new \Exception('Cannot schedule a cacher that does not implement the ['.Scheduled::class.'] interface'); } $reflection = new ReflectionClass(static::class); diff --git a/src/PermanentCacheServiceProvider.php b/src/PermanentCacheServiceProvider.php index 699dfe0..7500e97 100644 --- a/src/PermanentCacheServiceProvider.php +++ b/src/PermanentCacheServiceProvider.php @@ -23,7 +23,7 @@ public function bootingPackage() $this->callAfterResolving(Schedule::class, fn (Schedule $schedule) => collect(Facades\PermanentCache::configuredCaches()) ->filter(fn ($parameters, $cacherClass) => is_a($cacherClass, Scheduled::class, true)) ->map(fn ($parameters, $cacherClass) => $this->app->make($cacherClass, $parameters)) - ->each(fn (Scheduled $cacherClass) => $cacherClass->schedule($schedule->job($cacherClass))) + ->each(fn (Scheduled $instance) => $instance->schedule($schedule->job($instance))) ); } }