Elgg\HooksRegistrationService::getOrderedHandlers PHP Méthode

getOrderedHandlers() public méthode

Returns an ordered array of handlers registered for $name and $type.
See also: Elgg\HooksRegistrationService::getAllHandlers()
public getOrderedHandlers ( string $name, string $type ) : callable[]
$name string The name of the hook
$type string The type of the hook
Résultat callable[]
    public function getOrderedHandlers($name, $type)
    {
        $registrations = [];
        if (!empty($this->registrations[$name][$type])) {
            if ($name !== 'all' && $type !== 'all') {
                array_splice($registrations, count($registrations), 0, $this->registrations[$name][$type]);
            }
        }
        if (!empty($this->registrations['all'][$type])) {
            if ($type !== 'all') {
                array_splice($registrations, count($registrations), 0, $this->registrations['all'][$type]);
            }
        }
        if (!empty($this->registrations[$name]['all'])) {
            if ($name !== 'all') {
                array_splice($registrations, count($registrations), 0, $this->registrations[$name]['all']);
            }
        }
        if (!empty($this->registrations['all']['all'])) {
            array_splice($registrations, count($registrations), 0, $this->registrations['all']['all']);
        }
        usort($registrations, function ($a, $b) {
            // priority first
            if ($a[self::REG_KEY_PRIORITY] < $b[self::REG_KEY_PRIORITY]) {
                return -1;
            }
            if ($a[self::REG_KEY_PRIORITY] > $b[self::REG_KEY_PRIORITY]) {
                return 1;
            }
            // then insertion order
            return $a[self::REG_KEY_INDEX] < $b[self::REG_KEY_INDEX] ? -1 : 1;
        });
        $handlers = [];
        foreach ($registrations as $registration) {
            $handlers[] = $registration[self::REG_KEY_HANDLER];
        }
        return $handlers;
    }