install
This commit is contained in:
64
app/Modules/AppHelpers/AppHelpersModule.php
Normal file
64
app/Modules/AppHelpers/AppHelpersModule.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\AppHelpers;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class AppHelpersModule implements ModuleContract
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
* Module is enabled
|
||||
*/
|
||||
protected bool $enabled = true;
|
||||
|
||||
/**
|
||||
* Check if is module enabled
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable module
|
||||
*/
|
||||
public function disable(): void
|
||||
{
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable module
|
||||
*/
|
||||
public function enable(): void
|
||||
{
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module has a filament resource
|
||||
*/
|
||||
public function hasFilamentResource(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer requirements
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*/
|
||||
public function getComposerSuggestions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal file
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\AppHelpers\Repositories;
|
||||
|
||||
class CacheRepository
|
||||
{
|
||||
/**
|
||||
* Cache name
|
||||
*/
|
||||
protected string $name;
|
||||
|
||||
/**
|
||||
* Value
|
||||
*/
|
||||
protected mixed $value;
|
||||
|
||||
/**
|
||||
* Time
|
||||
*/
|
||||
protected int $time;
|
||||
|
||||
/**
|
||||
* Cache repo
|
||||
*/
|
||||
public function __construct(string $name, mixed $value, int $time = 600)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache Repo
|
||||
*
|
||||
* @param string $name key
|
||||
* @param mixed $value value
|
||||
* @param int|int $time time in seconds
|
||||
*/
|
||||
public static function make(string $name, mixed $value, int $time = 600): mixed
|
||||
{
|
||||
$repo = new self($name, $value, $time);
|
||||
|
||||
return $repo->handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cache
|
||||
*/
|
||||
public function handle(): mixed
|
||||
{
|
||||
return cache()->has($this->name)
|
||||
? cache($this->name)
|
||||
: cache()->remember(
|
||||
key: $this->name,
|
||||
ttl: $this->time,
|
||||
callback: fn () => is_callable($this->value) ? call_user_func($this->value) : $this->value
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget the key from cache
|
||||
*/
|
||||
public static function forget(string $name): void
|
||||
{
|
||||
cache()->forget($name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user