This commit is contained in:
2023-04-15 23:32:00 +08:00
parent 06e2b691bb
commit eebd01bcc5
9 changed files with 404 additions and 349 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace Kiri\Di\Inject;
use Exception;
use Kiri\Di\Container;
use Kiri\Di\Interface\InjectPropertyInterface;
use Kiri\Di\LocalService;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Service implements InjectPropertyInterface
{
/**
* @param string $service
*/
public function __construct(readonly public string $service)
{
}
/**
* @param object $class
* @param string $property
* @return void
* @throws Exception
*/
public function dispatch(object $class, string $property): void
{
$service = Container::instance()->get(LocalService::class);
$class->{$property} = $service->get($this->service);
}
}