public static apply ( string $class, string $method, Closure $filter ) : void | ||
$class | string | The fully namespaced name of a **static** class to which the filter will be applied. The class name specified in `$class` **must** extend `StaticObject`, or else statically implement the `applyFilter()` method. |
$method | string | The method to which the filter will be applied. |
$filter | Closure | The filter to apply to the class method. |
Résultat | void |
public static function apply($class, $method, $filter)
{
if (class_exists($class, false)) {
return $class::applyFilter($method, $filter);
}
static::$_lazyFilters[$class][$method][] = $filter;
}
public function testLazyApply() { $class = 'lithium\\tests\\mocks\\util\\MockFilters'; Filters::apply($class, 'filteredMethod', function ($self, $params, $chain) { return md5($chain->next($self, $params, $chain)); }); $expected = md5('Working?'); $result = $class::filteredMethod(); $this->assertEqual($expected, $result); Filters::apply($class, 'filteredMethod', function ($self, $params, $chain) { return sha1($chain->next($self, $params, $chain)); }); $expected = md5(sha1('Working?')); $result = $class::filteredMethod(); $this->assertEqual($expected, $result); }