This commit is contained in:
2023-04-15 23:32:00 +08:00
parent c825fd0d94
commit 12ab8b5f88
3 changed files with 437 additions and 367 deletions
+388 -358
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -140,7 +140,7 @@ class Loader extends Component
if (!class_exists($class)) { if (!class_exists($class)) {
return null; return null;
} }
return Kiri::getDi()->getReflect($class); return Kiri::getDi()->getReflectionClass($class);
} }
+48 -8
View File
@@ -2,6 +2,7 @@
namespace Kiri\Core; namespace Kiri\Core;
use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use ReturnTypeWillChange; use ReturnTypeWillChange;
use Traversable; use Traversable;
@@ -15,16 +16,25 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
private array $lists = []; private array $lists = [];
/** /**
* @return Traversable * @return Traversable
*/ */
public function getIterator(): Traversable public function getIterator(): Traversable
{ {
return new \ArrayIterator($this->lists); return new \ArrayIterator($this->lists);
} }
/** /**
* @return bool
*/
public function hasItem(): bool
{
return count($this->lists) > 0;
}
/**
* @param string $key * @param string $key
* @param $value * @param $value
*/ */
@@ -34,6 +44,23 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
} }
/**
* @param string $key
* @param $value
* @return void
* @throws Exception
*/
public function append(string $key, $value): void
{
if (!$this->has($key)) {
$this->lists[$key] = [];
} else if (!is_array($this->lists[$key])) {
throw new Exception('Source must a array.');
}
$this->lists[$key][] = $value;
}
/** /**
* @param string $key * @param string $key
* @return mixed * @return mixed
@@ -108,4 +135,17 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
{ {
unset($this->lists[$offset]); unset($this->lists[$offset]);
} }
public static function Tree(HashMap $root, string $leaf)
{
if ($root->has($leaf)) {
$hashMap = $root->get($leaf);
} else {
$hashMap = new HashMap();
$root->put($leaf, $hashMap);
}
return $hashMap;
}
} }