改名
This commit is contained in:
@@ -8,6 +8,7 @@ use ReflectionException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use Snowflake\Event;
|
||||
|
||||
/**
|
||||
* Class LocalService
|
||||
@@ -21,8 +22,9 @@ use Snowflake\Snowflake;
|
||||
* LocalService constructor.
|
||||
* @param string $service
|
||||
* @param array $args
|
||||
* @param bool $async_reload
|
||||
*/
|
||||
public function __construct(public string $service, public array $args = [])
|
||||
public function __construct(public string $service, public array $args = [], public bool $async_reload = true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ use Snowflake\Snowflake;
|
||||
* @throws ReflectionException
|
||||
* @throws ComponentException
|
||||
* @throws NotFindClassException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute(array $handler): mixed
|
||||
{
|
||||
@@ -42,6 +45,12 @@ use Snowflake\Snowflake;
|
||||
}
|
||||
|
||||
Snowflake::set($this->service, $class);
|
||||
if ($this->async_reload === true) {
|
||||
$event = Snowflake::app()->getEvent();
|
||||
$event->on(Event::SERVER_BEFORE_RELOAD, function () {
|
||||
Snowflake::app()->remove($this->service);
|
||||
});
|
||||
}
|
||||
|
||||
return parent::execute($handler); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user