触发事件.
@param mixed $class 类名.
@param string $name 事件名.
@param self $event 事件参数.
@return void
354739
public static function trigger(
        $class,
        string $name,
        self $event = null
    ): void {
        $wildcardEventHandlers = [];
        foreach (static::$_eventWildcards as
            $nameWildcard => $classHandlers) {
            if (!StringHelper::matchWildcard($nameWildcard, $name)) {
                continue;
            }
            $wildcardEventHandlers = array_merge(
                $wildcardEventHandlers,
                $classHandlers
            );
        }

        if (
            empty(static::$_events[$name])
            && empty($wildcardEventHandlers)
        ) {
            return;
        }

        $event === null && $event = new static;
        $event->handled = false;
        $event->name = $name;

        if (is_object($class)) {
            $event->sender === null && $event->sender = $class;
            $class = get_class($class);
        } else {
            $class = ltrim($class, '\\');
        }

        $classes = array_merge(
            [$class],
            class_parents($class, true),
            class_implements($class, true)
        );

        foreach ($classes as $class) {
            $eventHandlers = [];
            foreach ($wildcardEventHandlers as $classWildcard => $handlers) {
                if (StringHelper::matchWildcard($classWildcard, $class)) {
                    $eventHandlers = array_merge($eventHandlers, $handlers);
                    unset($wildcardEventHandlers[$classWildcard]);
                }
            }

            if (!empty(static::$_events[$name][$class])) {
                $eventHandlers = array_merge(
                    $eventHandlers,
                    static::$_events[$name][$class]
                );
            }

            foreach ($eventHandlers as $handler) {
                $event->data = $handler[1];
                call_user_func($handler[0], $event);
                if ($event->handled) {
                    return;
                }
            }
        }
    }
177871
public function serializeEvent($name, Event $event)
    {
        $context = SerializationContext::create();

        return serialize(array(
            'name' => $name,
            'class' => get_class($event),
            'event' => $this->serializer->serialize($event, 'json', $context),
        ));
    }
135416
public static function trigger($name, $args) {
        if (array_key_exists($name, static::$events)) {
            $infos = static::$events[ $name ];
            if ($infos) {
                foreach ($infos as $info) {
                    $module = Ioc::get($info[ 'class' ]);
                    if ($info[ 'action' ]) {
                        static::doAction($module, $info[ 'action' ], $args);
                    }
                }
            }
        }
    }
187362
private static function remove(
        array &$event,
        string $name,
        string $class,
        ? callable $handler
    ): bool {
        $removed = false;
        if (isset($event[$name][$class])) {
            foreach ($event[$name][$class] as $i => $item) {
                if ($item[0] === $handler) {
                    unset($event[$name][$class][$i]);
                    $removed = true;
                }
            }
            if ($removed) {
                $event[$name][$class] = array_values($event[$name][$class]);
                if (empty($event[$name][$class])) {
                    unset($event[$name][$class]);
                    if (empty($event[$name])) {
                        unset($event[$name]);
                    }
                }
            }
        }
        return $removed;
    }
1074385
public static function hasHandlers($class, string $name): bool
    {
        if (
            empty(static::$_eventWildcards)
            && empty(static::$_events[$name])
        ) {
            return false;
        }
        $class = is_object($class)
            ? get_class($class)
            : ltrim($class, '\\');
        $classes = array_merge(
            [$class],
            class_parents($class, true),
            class_implements($class, true)
        );
        foreach ($classes as $class) {
            if (!empty(static::$_events[$name][$class])) {
                return true;
            }
        }
        foreach (static::$_eventWildcards as
            $nameWildcard => $classHandlers) {
            if (!StringHelper::matchWildcard($nameWildcard, $name)) {
                continue;
            }
            foreach ($classHandlers as $classWildcard => $handlers) {
                if (empty($handlers)) {
                    continue;
                }
                foreach ($classes as $class) {
                    if (!StringHelper::matchWildcard($classWildcard, $class)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
1341215
public static function trigger($name, $data = [], $target = null, $paramClass = EventParam::class)
    {
        static::getInstance()->__trigger($name, $data, $target, $paramClass);
    }
561866
public function hasEventHandlers($name)
    {
        $this->ensureBehaviors();
        return !empty($this->__events__[$name]) || Event::hasHandlers($this, $name);
    }
538402
public function register($name, $fieldClass = null)
    {
        if (new $fieldClass instanceof FormFieldInterface) {
            $this->registeredFields[$name] = $fieldClass;
        }
    }
107682
public static function registerEvent($name, $className)
    {
        if (isset(static::$eventList[$name]) === false) {
            static::$eventList[$name] = array();
        }
        static::$eventList[$name][$className] = $className;
    }
628337
public function initialize(Event $event) {
		$table = $event->getSubject();
		if (!in_array(get_class($table), $this->config['tableClass'])) {
			return;
		}

		$this->_setValidators($table);
	}
941210
public function setPropertyValue($class, $name, $value)
    {
        $property = $this->findProperty($class, $name);
        $property->setAccessible(true);
        $property->setValue(
            is_object($class) ? $class : null,
            $value
        );
    }
616089
public static function add($name, $class, $action) {
        if (!$action) {
            $action = "on" . ucfirst($name);
        }
        $info = array('name' => $name, 'class' => $class, "action" => $action);
        if (!key_exists($name, static::$events)) {
            static::$events[ $name ] = array();
        }
        static::$events[ $name ][] = $info;
    }
165863
public function execute($eventName, $object)
    {
        if (isset($this->events[$eventName]) && is_array(($this->events[$eventName]))) {
            foreach ($this->events[$eventName] as $method) {
                call_user_func([$object, $method]);
            }
        }
    }
273197
protected function registerObserver($class)
    {
        $className = $this->resolveObserverClassName($class);

        // When registering a model observer, we will spin through the possible events
        // and determine if this observer has that method. If it does, we will hook
        // it into the model's event system, making it convenient to watch these.
        foreach ($this->getObservableEvents() as $event) {
            if (method_exists($class, $event)) {
                static::registerModelEvent($event, $className.'@'.$event);
            }
        }
    }
181949
public function off($name, $callback)
    {
        if(isset($this->events[$name]))
        {
            // 数据映射
            $this->events[$name]->detach($callback);
            $this->eventChangeRecords[$name] = true;
        }
    }
813887
public function attachEventListener($name, $handler) {
    $em    = $this->getEventsManager();
    if (!$name) {
      $event = self::EVENT_PREFIX;
    }
    elseif (!strstr($name,':') && $name != self::EVENT_PREFIX) {
      $event = self::EVENT_PREFIX.':'.$name;
    }
    else {
      $event = $name;
    }
    
    $em->attach($event, $handler);
  }
610183
public static function countClass($class)
    {
        $class = ObjectHelper::getClass($class);
        $count = 0;
        do {
            if (!empty(self::$events[$class])) {
                $count += count(static::$events[$class]);
            }
        } while (($class = get_parent_class($class)) !== false);

        return $count;
    }