info->is_supported()) { continue; } foreach (get_class_methods($extension) as $method) { if (substr($method, 0, 2) == "on") { $event = substr($method, 2) . "Event"; $pos = $extension->get_priority() * 100; while (isset($_shm_event_listeners[$event][$pos])) { $pos += 1; } $_shm_event_listeners[$event][$pos] = $extension; } } } } function _dump_event_listeners(array $event_listeners, string $path): void { $p = "<"."?php\n"; foreach (get_subclasses_of("Extension") as $class) { $p .= "\$$class = new $class(); "; } $p .= "\$_shm_event_listeners = array(\n"; foreach ($event_listeners as $event => $listeners) { $p .= "\t'$event' => array(\n"; foreach ($listeners as $id => $listener) { $p .= "\t\t$id => \$".get_class($listener).",\n"; } $p .= "\t),\n"; } $p .= ");\n"; file_put_contents($path, $p); } /** @private */ global $_shm_event_count; $_shm_event_count = 0; /** * Send an event to all registered Extensions. */ function send_event(Event $event): Event { global $tracer_enabled; global $_shm_event_listeners, $_shm_event_count, $_tracer; if (!isset($_shm_event_listeners[get_class($event)])) { return $event; } $method_name = "on".str_replace("Event", "", get_class($event)); // send_event() is performance sensitive, and with the number // of times tracer gets called the time starts to add up if ($tracer_enabled) { $_tracer->begin(get_class($event)); } // SHIT: https://bugs.php.net/bug.php?id=35106 $my_event_listeners = $_shm_event_listeners[get_class($event)]; ksort($my_event_listeners); foreach ($my_event_listeners as $listener) { if ($tracer_enabled) { $_tracer->begin(get_class($listener)); } if (method_exists($listener, $method_name)) { $listener->$method_name($event); } if ($tracer_enabled) { $_tracer->end(); } if ($event->stop_processing===true) { break; } } $_shm_event_count++; if ($tracer_enabled) { $_tracer->end(); } return $event; }