Files
tbbank-new/app/Modules/module-helpers.php
2025-10-29 00:06:05 +05:00

116 lines
2.2 KiB
PHP

<?php
use App\Modules\ModuleContract;
use App\Modules\ModuleRepository;
use Illuminate\Support\Collection;
/**
* Return modular repo
*/
function modular(): ModuleRepository
{
return app(ModuleRepository::class);
}
/**
* Modules directory path
*/
function modules_path(string $path = ''): string
{
return modular()->path().'/'.$path;
}
/**
* Get module
*/
function module(string $moduleName): ModuleContract
{
return modular()->module($moduleName);
}
/**
* Modules
*
* @return Collection<array-key, App\Modules\BaseModule>
*/
function modules(bool $withDisabled = false): Collection
{
return $withDisabled ? modular()->allModules() : modular()->modules();
}
/**
* Empty module
*/
function emptyModule(): ModuleContract
{
return modular()->emptyModule();
}
/**
* Module exists
*/
function module_exists(string $moduleName): bool
{
return modular()->moduleExists($moduleName);
}
/**
* Create an anonymous class that acts as a dynamic object.
*
* @param mixed ...$arguments Key-value pairs passed as an associative array.
* @return object Anonymous class instance with dynamic properties.
*/
function emptyClass(...$arguments): object
{
/**
* @var array<string, mixed> $arguments
*/
return new class($arguments)
{
/**
* Internal data storage.
*
* @var array<string, mixed>
*/
private array $data = [];
/**
* Constructor that sets properties.
*
* @param array<string, mixed> $props
*/
public function __construct(array $props)
{
foreach ($props as $key => $value) {
$this->data[$key] = $value;
}
}
/**
* Magic getter.
*
* @return mixed|null
*/
public function __get(string $key): mixed
{
return $this->data[$key] ?? null;
}
/**
* Magic setter.
*/
public function __set(string $key, mixed $value): void
{
$this->data[$key] = $value;
}
/**
* Magic isset.
*/
public function __isset(string $key): bool
{
return isset($this->data[$key]);
}
};
}