DMS\Filter\Filters\Callback::apply PHP Method

apply() public method

{@inheritDoc}
public apply ( Rule $rule, $value )
$rule DMS\Filter\Rules\Rule
    public function apply(Rule $rule, $value)
    {
        $type = $rule->getInputType();
        if ($type == CallbackRule::SELF_METHOD_TYPE) {
            return $this->useObjectMethod($rule->callback, $value);
        }
        if ($type == CallbackRule::CALLABLE_TYPE) {
            return $this->useCallable($rule->callback, $value);
        }
        if ($type == CallbackRule::CLOSURE_TYPE) {
            return $this->useClosure($rule->callback, $value);
        }
        throw new InvalidCallbackException("Unsupported callback provided, failed to filter property");
    }

Usage Example

Beispiel #1
0
 /**
  * @expectedException \DMS\Filter\Exception\InvalidCallbackException
  */
 public function testRuleWithNonClosure()
 {
     $this->rule->expects($this->once())->method('getInputType')->will($this->returnValue(CallbackRule::CLOSURE_TYPE));
     $this->rule->callback = "i'm not a closure";
     $result = $this->filter->apply($this->rule, 'value');
 }