Kahlan\Filter\Filter::apply PHP 메소드

apply() 공개 정적인 메소드

Applies a filter to a method.
public static apply ( mixed $context, string | array $methods, string $name ) : string
$context mixed The instance or class name context to apply a new filter.
$methods string | array The name or array of method names to be filtered.
$name string The filter name to apply.
리턴 string The name reference of the applied filter.
    public static function apply($context, $methods, $name)
    {
        if (!isset(static::$_aspects[$name])) {
            throw new Exception("Undefined filter `{$name}`.");
        }
        $aspect = static::$_aspects[$name];
        if (is_object($context)) {
            $aspect = $aspect->bindTo($context, get_class($context));
        } elseif (is_string($context)) {
            $aspect = $aspect->bindTo(null, $context);
            unset(static::$_cachedFilters[$context]);
        } else {
            throw new Exception("Error this context can't be filtered.");
        }
        $methodFilters = static::_methodFilters($context);
        return $methodFilters->apply($methods, $name, $aspect);
    }

Usage Example

예제 #1
0
            Filter::apply($this->specs, 'load', 'spec.load');
            Filter::register('spec.reporters', function ($chain) use(&$order) {
                $order[] = 'reporters';
            });
            Filter::apply($this->specs, 'reporters', 'spec.reporters');
            Filter::register('spec.matchers', function ($chain) use(&$order) {
                $order[] = 'matchers';
            });
            Filter::apply($this->specs, 'matchers', 'spec.matchers');
            Filter::register('spec.run', function ($chain) use(&$order) {
                $order[] = 'run';
            });
            Filter::apply($this->specs, 'run', 'spec.run');
            Filter::register('spec.reporting', function ($chain) use(&$order) {
                $order[] = 'reporting';
            });
            Filter::apply($this->specs, 'reporting', 'spec.reporting');
            Filter::register('spec.stop', function ($chain) use(&$order) {
                $order[] = 'stop';
            });
            Filter::apply($this->specs, 'stop', 'spec.stop');
            Filter::register('spec.quit', function ($chain) use(&$order) {
                $order[] = 'quit';
            });
            Filter::apply($this->specs, 'quit', 'spec.quit');
            $this->specs->run();
            expect($order)->toBe(['bootstrap', 'interceptor', 'namespaces', 'patchers', 'load', 'reporters', 'matchers', 'run', 'reporting', 'stop', 'quit']);
            Interceptor::unpatch();
        });
    });
});
All Usage Examples Of Kahlan\Filter\Filter::apply