From 940fb1744bfe6bf58401ab21ae46966c3607f01d Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 12 Apr 2023 07:21:33 +0200 Subject: [PATCH] Move logic from separate method to __call --- src/CacheManager.php | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/CacheManager.php b/src/CacheManager.php index 0f3f19ed..d343ac52 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -21,29 +21,24 @@ class CacheManager extends BaseCacheManager public function __call($method, $parameters) { if (tenancy()->initialized && static::$addTags) { - return $this->callWithTag($method, $parameters); + $tags = [config('tenancy.cache.tag_base') . tenant()?->getTenantKey()]; + + if ($method === 'tags') { + $count = count($parameters); + + if ($count !== 1) { + throw new \Exception("Method tags() takes exactly 1 argument. $count passed."); + } + + $names = $parameters[0]; + $names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/9.x/cache#removing-tagged-cache-items + + return $this->store()->tags(array_merge($tags, $names)); + } + + return $this->store()->tags($tags)->$method(...$parameters); } return parent::__call($method, $parameters); } - - protected function callWithTag($method, $parameters) - { - $tags = [config('tenancy.cache.tag_base') . tenant()?->getTenantKey()]; - - if ($method === 'tags') { - $count = count($parameters); - - if ($count !== 1) { - throw new \Exception("Method tags() takes exactly 1 argument. $count passed."); - } - - $names = $parameters[0]; - $names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/9.x/cache#removing-tagged-cache-items - - return $this->store()->tags(array_merge($tags, $names)); - } - - return $this->store()->tags($tags)->$method(...$parameters); - } }