Files
kiri-core/kiri-engine/Abstracts/Component.php
T

130 lines
2.5 KiB
PHP
Raw Normal View History

2022-01-09 03:50:38 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/3/30 0030
* Time: 14:28
*/
declare(strict_types=1);
namespace Kiri\Abstracts;
use Exception;
use JetBrains\PhpStorm\Pure;
2022-02-23 16:32:08 +08:00
use Kiri;
2023-11-16 23:50:06 +08:00
use Kiri\Error\StdoutLogger;
2024-09-04 10:07:59 +08:00
use Kiri\Events\EventDispatch;
use Kiri\Events\EventProvider;
use Psr\Container\ContainerInterface;
2022-01-09 03:50:38 +08:00
/**
* Class Component
2022-01-12 14:10:33 +08:00
* @package Kiri\Base
2024-09-04 10:07:59 +08:00
* @property ContainerInterface $container
* @property EventDispatch $dispatch
* @property EventProvider $provider
2022-01-09 03:50:38 +08:00
*/
class Component implements Configure
{
2023-08-28 12:01:30 +08:00
/**
* BaseAbstract constructor.
*/
public function __construct()
{
}
/**
* @return void
*/
public function init(): void
{
}
/**
* @return string
*/
#[Pure] public static function className(): string
{
return static::class;
}
/**
2023-11-16 23:50:06 +08:00
* @return StdoutLogger
2023-12-12 15:35:38 +08:00
* @throws
2023-08-28 12:01:30 +08:00
*/
2023-11-16 23:50:06 +08:00
public function getLogger(): StdoutLogger
2023-08-28 12:01:30 +08:00
{
return Kiri::getLogger();
}
/**
* @param string $name
* @return mixed
2023-12-12 15:35:38 +08:00
* @throws
2023-08-28 12:01:30 +08:00
*/
public function __get(string $name)
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->{$method}();
} else if (method_exists($this, $name)) {
return $this->{$name};
} else {
throw new Exception('Unable getting property ' . get_called_class() . '::' . $name);
}
}
/**
* @param string $name
* @param $value
* @return void
2023-12-12 15:35:38 +08:00
* @throws
2023-08-28 12:01:30 +08:00
*/
public function __set(string $name, $value): void
{
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} else if (method_exists($this, $name)) {
$this->{$name} = $value;
} else {
throw new Exception('Unable setting property ' . get_called_class() . '::' . $name);
}
}
2022-01-09 03:50:38 +08:00
2022-02-23 16:32:08 +08:00
2024-09-04 10:07:59 +08:00
/**
* @return EventDispatch
*/
public function getDispatch(): EventDispatch
{
return Kiri::getDi()->get(EventDispatch::class);
}
/**
* @return EventProvider
*/
public function getProvider(): EventProvider
{
return Kiri::getDi()->get(EventProvider::class);
}
/**
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface
{
return Kiri::getDi();
}
2022-01-09 03:50:38 +08:00
}