diff --git a/src/Cached.php b/src/Cached.php index fd0fd66..a272ec7 100644 --- a/src/Cached.php +++ b/src/Cached.php @@ -4,6 +4,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Cache; use ReflectionClass; @@ -52,8 +53,9 @@ final public function handle($event = null): void [$driver, $ident] = self::parseCacheString($this->store ?? throw new \Exception('The $store property in ['.static::class.'] must be overridden'), ); + Cache::driver($driver)->forever($ident, - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line */ $this->run($event), ); } @@ -111,20 +113,20 @@ public static function schedule($callback) /** * Get the event (if any) this cacher listens for. * - * @return class-string|null + * @return array> */ - final public static function getListenerEvent(): ?string + final public static function getListenerEvent(): array { $reflection = new ReflectionClass(static::class); - $concrete = $reflection->getProperty('event')->getDefaultValue(); + $concrete = Arr::wrap($reflection->getProperty('event')->getDefaultValue()); /** @phpstan-ignore-next-line */ - return $concrete ?? ($reflection + return $concrete ?: Arr::wrap(($reflection ->getMethod('run') ->getParameters()[0] ?? null) ?->getType() - ?->getName(); + ?->getName()); } /** diff --git a/src/PermanentCache.php b/src/PermanentCache.php index e4fdc44..8712b71 100755 --- a/src/PermanentCache.php +++ b/src/PermanentCache.php @@ -11,11 +11,6 @@ class PermanentCache */ protected array $cachers = []; - /** - * @var array>> - */ - protected array $static = []; - /** * @param array> $cachers * @return $this @@ -23,32 +18,25 @@ class PermanentCache public function caches(array $cachers): self { foreach ($cachers as $cacher) { - $event = $cacher::getListenerEvent(); - - if (is_null($event)) { - $static[] = $cacher; - - continue; - } + $events = $cacher::getListenerEvent(); - $resolved[$event][] = $cacher; + $resolved[$cacher] = $events; - Event::listen($event, $cacher); + Event::listen($events, $cacher); } $this->cachers = array_merge($this->cachers, $resolved ?? []); - $this->static = array_merge($this->static, $static ?? []); return $this; } - public function staticCaches(): array + public function configuredCaches(): array { - return $this->static; + return $this->cachers; } - public function configuredCaches(): array + public function staticCaches(): array { - return $this->cachers; + return array_filter($this->cachers); } }