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);
}
}