diff --git a/kiri-engine/Core/HashMap.php b/kiri-engine/Core/HashMap.php new file mode 100644 index 00000000..75ca890b --- /dev/null +++ b/kiri-engine/Core/HashMap.php @@ -0,0 +1,98 @@ +lists[$key] = $value; + } + + + /** + * @param string $key + * @return mixed + */ + #[Pure] public function get(string $key): mixed + { + if (!$this->has($key)) { + return null; + } + return $this->lists[$key]; + } + + + /** + * @param string $key + */ + public function del(string $key) + { + if (!$this->has($key)) { + return; + } + unset($this->lists[$key]); + } + + + /** + * @param string $key + * @return bool + */ + public function has(string $key): bool + { + return array_key_exists($key, $this->lists); + } + + + /** + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset): bool + { + return isset($this->lists[$offset]); + } + + + /** + * @param mixed $offset + * @return mixed + */ + #[Pure] public function offsetGet($offset): mixed + { + return $this->get($offset); + } + + + /** + * @param mixed $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) + { + $this->put($offset, $value); + } + + + /** + * @param mixed $offset + */ + public function offsetUnset($offset) + { + unset($this->lists[$offset]); + } +} diff --git a/kiri-note/Asynchronous.php b/kiri-note/Task.php similarity index 63% rename from kiri-note/Asynchronous.php rename to kiri-note/Task.php index be8698f6..2eb5a195 100644 --- a/kiri-note/Asynchronous.php +++ b/kiri-note/Task.php @@ -6,19 +6,20 @@ namespace Annotation; use Exception; use Kiri\Kiri; +use Server\Tasker\AsyncTaskExecute; /** - * Class Asynchronous + * Class Task * @package Annotation * Task任务 */ -#[\Attribute(\Attribute::TARGET_CLASS)] class Asynchronous extends Attribute +#[\Attribute(\Attribute::TARGET_CLASS)] class Task extends Attribute { /** - * Asynchronous constructor. + * Task constructor. * @param string $name */ public function __construct(public string $name) @@ -35,8 +36,8 @@ use Kiri\Kiri; */ public function execute(mixed $class, mixed $method = null): bool { - $async = Kiri::app()->getAsync(); - $async->addAsync($this->name, $class); + $task = Kiri::getDi()->get(AsyncTaskExecute::class); + $task->reg($this->name, $class); return true; }