lithium\data\Entity::respondsTo PHP Method

respondsTo() public method

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
return boolean Returns `true` if the method can be called, `false` otherwise.
    public function respondsTo($method, $internal = false)
    {
        if (method_exists($class = $this->_model, '_object')) {
            $result = $class::invokeMethod('_object')->respondsTo($method);
        } else {
            $result = Inspector::isCallable($class, $method, $internal);
        }
        $result = $result || parent::respondsTo($method, $internal);
        $result = $result || $class::respondsTo($method, $internal);
        return $result;
    }

Usage Example

Beispiel #1
0
 public function testRespondsToParentCall()
 {
     $model = $this->_model;
     $data = array('foo' => true);
     $entity = new Entity(compact('model', 'data'));
     $this->assertTrue($entity->respondsTo('applyFilter'));
     $this->assertFalse($entity->respondsTo('fooBarBaz'));
 }