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;
|
2022-02-23 18:02:29 +08:00
|
|
|
use Kiri\Error\StdoutLoggerInterface;
|
2022-01-09 03:50:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Component
|
2022-01-12 14:10:33 +08:00
|
|
|
* @package Kiri\Base
|
2022-01-09 03:50:38 +08:00
|
|
|
*/
|
|
|
|
|
class Component implements Configure
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* BaseAbstract constructor.
|
|
|
|
|
*/
|
2023-04-16 00:59:31 +08:00
|
|
|
public function __construct()
|
2022-01-09 03:50:38 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-16 14:21:55 +08:00
|
|
|
|
2022-01-09 03:50:38 +08:00
|
|
|
/**
|
2023-04-16 14:21:55 +08:00
|
|
|
* @return void
|
2022-01-09 03:50:38 +08:00
|
|
|
*/
|
2023-04-16 14:21:55 +08:00
|
|
|
public function init(): void
|
2022-01-09 03:50:38 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
#[Pure] public static function className(): string
|
|
|
|
|
{
|
|
|
|
|
return static::class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-23 16:32:08 +08:00
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
2022-01-09 03:50:38 +08:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-02-23 16:32:08 +08:00
|
|
|
public function __get(string $name)
|
2022-01-09 03:50:38 +08:00
|
|
|
{
|
2022-02-23 16:32:08 +08:00
|
|
|
$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);
|
2022-01-09 03:50:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-23 16:32:08 +08:00
|
|
|
* @param string $name
|
|
|
|
|
* @param $value
|
|
|
|
|
* @return void
|
2022-01-09 03:50:38 +08:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-02-23 16:32:08 +08:00
|
|
|
public function __set(string $name, $value): void
|
2022-01-09 03:50:38 +08:00
|
|
|
{
|
2022-02-23 16:32:08 +08:00
|
|
|
$method = 'set' . ucfirst($name);
|
|
|
|
|
if (method_exists($this, $method)) {
|
|
|
|
|
$this->{$method}($value);
|
|
|
|
|
} else if (method_exists($this, $name)) {
|
|
|
|
|
$this->{$name} = $value;
|
2022-01-09 03:50:38 +08:00
|
|
|
} else {
|
2022-02-23 16:32:08 +08:00
|
|
|
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
|
|
|
|
2022-01-09 03:50:38 +08:00
|
|
|
}
|