mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 23:14:03 +00:00
Move logic from separate method to __call
This commit is contained in:
parent
2d0ee2c7cd
commit
940fb1744b
1 changed files with 16 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue