This commit is contained in:
2021-03-31 00:58:18 +08:00
parent 4a86077e72
commit 7983438222
2 changed files with 63 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace Annotation;
use ReflectionException;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
/**
* Class LocalService
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class LocalService extends Attribute
{
/**
* LocalService constructor.
* @param string $service
* @param array $args
*/
public function __construct(public string $service, public array $args = [])
{
}
/**
* @param array $handler
* @return mixed
* @throws ReflectionException
* @throws ComponentException
* @throws NotFindClassException
*/
public function execute(array $handler): mixed
{
$class = ['class' => get_class($handler[0])];
if (!empty($this->args)) {
$class = array_merge($class, $this->args);
}
Snowflake::set($this->service, $class);
return parent::execute($handler); // TODO: Change the autogenerated stub
}
}
+14
View File
@@ -56,6 +56,20 @@ class Snowflake
static::$service = $service;
}
/**
* @param $alias
* @param array $array
* @return mixed
* @throws ComponentException
* @throws NotFindClassException
* @throws ReflectionException
*/
public static function set($alias, $array = []): mixed
{
return static::app()->set($alias, $array);
}
/**
* @return Application|null
*/