Habari\Format::apply PHP Метод

apply() публичный статический Метод

Called to register a format function to a plugin hook, only passing the hook's first parameter to the Format function.
public static apply ( string $format, string $onwhat )
$format string A function name that exists in a Format class
$onwhat string A plugin hook to apply that Format function to as a filter
    public static function apply($format, $onwhat)
    {
        if (self::$formatters == null) {
            self::load_all();
        }
        $priority = 8;
        if (preg_match('#^(.+)_(\\d+)$#', $onwhat, $matches)) {
            $priority = intval($matches[2]);
            $onwhat = $matches[1];
        }
        $method = false;
        if (is_callable($format)) {
            $method = $format;
        } else {
            foreach (self::$formatters as $formatobj) {
                if (method_exists($formatobj, $format)) {
                    $method = array($formatobj, $format);
                    break;
                }
            }
        }
        if ($method) {
            $args = func_get_args();
            $args = array_slice($args, 2);
            $lambda = function () use($args, $method) {
                $filterargs = func_get_args();
                $filterargs = array_slice($filterargs, 0, 1);
                foreach ($args as $arg) {
                    $filterargs[] = $arg;
                }
                return call_user_func_array($method, $filterargs);
            };
            Plugins::register($lambda, 'filter', $onwhat, $priority);
        }
    }