2023-04-15 23:32:00 +08:00
|
|
|
<?php
|
2023-04-16 01:45:33 +08:00
|
|
|
declare(strict_types=1);
|
2023-04-15 23:32:00 +08:00
|
|
|
|
|
|
|
|
namespace Kiri\Di\Inject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Kiri\Di\Interface\InjectPropertyInterface;
|
|
|
|
|
use Kiri\Di\Container as DContainer;
|
|
|
|
|
|
|
|
|
|
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
|
|
|
|
class Container implements InjectPropertyInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2023-12-12 15:35:35 +08:00
|
|
|
/**
|
|
|
|
|
* @param string $service
|
|
|
|
|
* @param mixed|null $default
|
|
|
|
|
* @throws
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(readonly public string $service, public mixed $default = null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $class
|
|
|
|
|
* @param string $property
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws
|
|
|
|
|
*/
|
|
|
|
|
public function dispatch(object $class, string $property): void
|
|
|
|
|
{
|
|
|
|
|
$class->{$property} = DContainer::instance()->get($this->service);
|
|
|
|
|
}
|
2023-04-15 23:32:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|