mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Code cleanup.
This commit is contained in:
@@ -23,23 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support;
|
||||
|
||||
use Cache;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
* Class CacheProperties.
|
||||
*
|
||||
|
||||
*/
|
||||
class CacheProperties
|
||||
{
|
||||
protected string $hash = '';
|
||||
protected Collection $properties;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->properties = new Collection();
|
||||
@@ -62,20 +55,14 @@ class CacheProperties
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return Cache::get($this->hash);
|
||||
return \Cache::get($this->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHash(): string
|
||||
{
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function has(): bool
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
@@ -83,23 +70,7 @@ class CacheProperties
|
||||
}
|
||||
$this->hash();
|
||||
|
||||
return Cache::has($this->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
private function hash(): void
|
||||
{
|
||||
$content = '';
|
||||
foreach ($this->properties as $property) {
|
||||
try {
|
||||
$content .= json_encode($property, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $e) {
|
||||
// @ignoreException
|
||||
$content .= hash('sha256', (string)time());
|
||||
}
|
||||
}
|
||||
$this->hash = substr(hash('sha256', $content), 0, 16);
|
||||
return \Cache::has($this->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,6 +78,20 @@ class CacheProperties
|
||||
*/
|
||||
public function store($data): void
|
||||
{
|
||||
Cache::forever($this->hash, $data);
|
||||
\Cache::forever($this->hash, $data);
|
||||
}
|
||||
|
||||
private function hash(): void
|
||||
{
|
||||
$content = '';
|
||||
foreach ($this->properties as $property) {
|
||||
try {
|
||||
$content .= json_encode($property, JSON_THROW_ON_ERROR);
|
||||
} catch (\JsonException $e) {
|
||||
// @ignoreException
|
||||
$content .= hash('sha256', (string)time());
|
||||
}
|
||||
}
|
||||
$this->hash = substr(hash('sha256', $content), 0, 16);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user