/** * Finds handlers in this Parser's directory. */ protected static function find_handlers() { $class_info = Library::get_class_info(get_called_class()); $handler_namespace = $class_info['namespace'] . '\\handlers'; foreach (scandir(Library::directory_from_namespace($handler_namespace)) as $file_name) { if ($file_name[0] == '.') { continue; } $handler = $handler_namespace . '\\' . Library::class_name_from_file_name($file_name); $trigger = $handler::trigger(); if (!$trigger) { continue; } if (is_array($trigger)) { foreach ($trigger as $_trigger) { static::$handlers[$_trigger] = $handler; } } else { static::$handlers[$trigger] = $handler; } } if (empty(static::$handlers)) { throw new Exception('Sanity error: there are no handlers'); } uksort(static::$handlers, function ($a, $b) { if (strlen($a) < strlen($b)) { return 1; } if (strlen($a) == strlen($b)) { return 0; } if (strlen($a) > strlen($b)) { return -1; } }); }