taktik - laravel
This commit is contained in:
32
app/Services/CacheKeyBuilder.php
Normal file
32
app/Services/CacheKeyBuilder.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class CacheKeyBuilder
|
||||
{
|
||||
/**
|
||||
* @param mixed ...$args
|
||||
* @return string
|
||||
*/
|
||||
public function buildCacheKeyFromArgs(...$args): string
|
||||
{
|
||||
$cacheName = '';
|
||||
foreach ($args as $key => $arg) {
|
||||
if (is_array($arg)) {
|
||||
$cacheName .= http_build_query($arg, '', '|');
|
||||
} elseif ($arg === null) {
|
||||
$cacheName .= '|N';
|
||||
} elseif (is_scalar($arg)) {
|
||||
$cacheName .= '|' . (string) $arg;
|
||||
} elseif ($arg instanceof CacheKeyInterface) {
|
||||
$cacheName .= $arg->toCacheKey();
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Invalid argument $key type for key generator.");
|
||||
}
|
||||
}
|
||||
|
||||
return $cacheName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user