Files
kiri-core/kiri-engine/Abstracts/Component.php
T
2026-06-12 23:57:25 +08:00

66 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Kiri\Abstracts;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri;
use Kiri\Error\StdoutLogger;
use Kiri\Events\EventDispatch;
use Kiri\Events\EventProvider;
use Psr\Container\ContainerInterface;
class Component
{
public function __construct()
{
}
public function init(): void
{
}
#[Pure] public static function className(): string
{
return static::class;
}
/**
* @throws
*/
public function getLogger(): StdoutLogger
{
return Kiri::getLogger();
}
public function getDispatch(): EventDispatch
{
return Kiri::getDi()->get(EventDispatch::class);
}
public function getProvider(): EventProvider
{
return Kiri::getDi()->get(EventProvider::class);
}
public function getContainer(): ContainerInterface
{
return Kiri::getDi();
}
/**
* @throws
*/
public function __get(string $name)
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->{$method}();
}
throw new Exception('Unable getting property ' . get_called_class() . '::' . $name);
}
}