2022-05-03 10:06:57 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZM\Event;
|
|
|
|
|
|
|
|
|
|
|
|
use Iterator;
|
2022-05-04 22:43:23 +08:00
|
|
|
|
use ReturnTypeWillChange;
|
2022-05-04 21:05:10 +08:00
|
|
|
|
use ZM\Console\Console;
|
2022-05-03 10:06:57 +08:00
|
|
|
|
|
|
|
|
|
|
class EventMapIterator implements Iterator
|
|
|
|
|
|
{
|
|
|
|
|
|
private $offset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private $class;
|
|
|
|
|
|
|
|
|
|
|
|
private $method;
|
|
|
|
|
|
|
|
|
|
|
|
private $event_name;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($class, $method, $event_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->class = $class;
|
|
|
|
|
|
$this->method = $method;
|
|
|
|
|
|
$this->event_name = $event_name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-04 22:43:23 +08:00
|
|
|
|
#[ReturnTypeWillChange]
|
2022-05-03 10:06:57 +08:00
|
|
|
|
public function current()
|
|
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug('从 [' . $this->offset . '] 开始获取');
|
2022-05-03 10:06:57 +08:00
|
|
|
|
return EventManager::$event_map[$this->class][$this->method][$this->offset];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function next(): void
|
|
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug('下一个offset为 [' . ++$this->offset . ']');
|
2022-05-03 10:06:57 +08:00
|
|
|
|
$this->nextToValid();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-04 22:43:23 +08:00
|
|
|
|
#[ReturnTypeWillChange]
|
2022-05-03 10:06:57 +08:00
|
|
|
|
public function key()
|
|
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug('返回key:' . $this->offset);
|
|
|
|
|
|
return isset(EventManager::$event_map[$this->class][$this->method][$this->offset]) ? $this->offset : null;
|
2022-05-03 10:06:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-04 21:05:10 +08:00
|
|
|
|
public function valid($s = false): bool
|
2022-05-03 10:06:57 +08:00
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug(
|
|
|
|
|
|
"[{$this->offset}] " .
|
|
|
|
|
|
($s ? 'valid' : '') . '存在:' .
|
|
|
|
|
|
(!isset(EventManager::$event_map[$this->class][$this->method][$this->offset]) ? Console::setColor('false', 'red') : ('true' .
|
|
|
|
|
|
(is_a(EventManager::$event_map[$this->class][$this->method][$this->offset], $this->event_name, true) ? ',是目标对象' : ',不是目标对象')))
|
|
|
|
|
|
);
|
|
|
|
|
|
return
|
|
|
|
|
|
isset(EventManager::$event_map[$this->class][$this->method][$this->offset])
|
|
|
|
|
|
&& is_a(EventManager::$event_map[$this->class][$this->method][$this->offset], $this->event_name, true);
|
2022-05-03 10:06:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function rewind(): void
|
|
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug('回到0');
|
2022-05-03 10:06:57 +08:00
|
|
|
|
$this->offset = 0;
|
2022-05-04 21:05:10 +08:00
|
|
|
|
$this->nextToValid();
|
2022-05-03 10:06:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function nextToValid()
|
|
|
|
|
|
{
|
2022-05-04 21:05:10 +08:00
|
|
|
|
while (
|
|
|
|
|
|
isset(EventManager::$event_map[$this->class][$this->method][$this->offset])
|
|
|
|
|
|
&& !is_a(EventManager::$event_map[$this->class][$this->method][$this->offset], $this->event_name, true)
|
|
|
|
|
|
) {
|
2022-05-03 10:06:57 +08:00
|
|
|
|
++$this->offset;
|
|
|
|
|
|
}
|
2022-05-04 21:05:10 +08:00
|
|
|
|
Console::debug('内部偏移offset为 [' . $this->offset . ']');
|
2022-05-03 10:06:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|