改名
This commit is contained in:
@@ -4,12 +4,19 @@ namespace Server\Tasker;
|
|||||||
|
|
||||||
use Annotation\Inject;
|
use Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Kiri\Abstracts\BaseObject;
|
||||||
|
use Kiri\Core\HashMap;
|
||||||
use Kiri\Di\Container;
|
use Kiri\Di\Container;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use ReflectionException;
|
||||||
use Server\Contract\OnTaskInterface;
|
use Server\Contract\OnTaskInterface;
|
||||||
use Server\SwooleServerInterface;
|
use Server\SwooleServerInterface;
|
||||||
|
|
||||||
class AsyncTask
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class AsyncTaskExecute extends BaseObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +34,28 @@ class AsyncTask
|
|||||||
public ContainerInterface $container;
|
public ContainerInterface $container;
|
||||||
|
|
||||||
|
|
||||||
|
private HashMap $hashMap;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->hashMap = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param $handler
|
||||||
|
*/
|
||||||
|
public function reg(string $key, $handler)
|
||||||
|
{
|
||||||
|
$this->hashMap->put($key, $handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OnTaskInterface|string $handler
|
* @param OnTaskInterface|string $handler
|
||||||
* @param array $params
|
* @param array $params
|
||||||
@@ -49,11 +78,14 @@ class AsyncTask
|
|||||||
* @param $handler
|
* @param $handler
|
||||||
* @param $params
|
* @param $params
|
||||||
* @return object
|
* @return object
|
||||||
* @throws \ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function handle($handler, $params): object
|
private function handle($handler, $params): object
|
||||||
{
|
{
|
||||||
|
if (!class_exists($handler) && $this->hashMap->has($handler)) {
|
||||||
|
$handler = $this->hashMap->get($handler);
|
||||||
|
}
|
||||||
$implements = $this->container->getReflect($handler);
|
$implements = $this->container->getReflect($handler);
|
||||||
if (!in_array(OnTaskInterface::class, $implements->getInterfaceNames())) {
|
if (!in_array(OnTaskInterface::class, $implements->getInterfaceNames())) {
|
||||||
throw new Exception('Task must instance ' . OnTaskInterface::class);
|
throw new Exception('Task must instance ' . OnTaskInterface::class);
|
||||||
Reference in New Issue
Block a user