isCallable() public static method

Determines if a given method can be called on an object/class.
public static isCallable ( string | object $object, string $method, boolean $internal = false ) : boolean
$object string | object Class or instance to inspect.
$method string Name of the method.
$internal boolean Should be `true` if you want to check from inside the class/object. When `false` will also check for public visibility, defaults to `false`.
return boolean Returns `true` if the method can be called, `false` otherwise.
 /**
  * Custom check to determine if our given magic methods can be responded to.
  *
  * @param  string  $method     Method name.
  * @param  bool    $internal   Interal call or not.
  * @return bool
  */
 public function respondsTo($method, $internal = false)
 {
     $class = $this->_model;
     $modelRespondsTo = false;
     $parentRespondsTo = parent::respondsTo($method, $internal);
     $staticRespondsTo = $class::respondsTo($method, $internal);
     if (method_exists($class, '_object')) {
         $model = $class::invokeMethod('_object');
         $modelRespondsTo = $model->respondsTo($method);
     } else {
         $modelRespondsTo = Inspector::isCallable($class, $method, $internal);
     }
     return $parentRespondsTo || $staticRespondsTo || $modelRespondsTo;
 }
Example #2
0
 /**
  * Will determine if a method can be called.
  *
  * @param  string  $method     Method name.
  * @param  bool    $internal   Interal call or not.
  * @return bool
  */
 public static function respondsTo($method, $internal = false)
 {
     return Inspector::isCallable(get_called_class(), $method, $internal);
 }
Example #3
0
 public function testCallableVisibility()
 {
     $obj = new MockMethodFiltering();
     $this->assertTrue(Inspector::isCallable($obj, 'method', 0));
     $this->assertTrue(Inspector::isCallable($obj, 'method', 1));
     $this->assertFalse(Inspector::isCallable('lithium\\action\\Dispatcher', '_callable', 0));
     $this->assertTrue(Inspector::isCallable('lithium\\action\\Dispatcher', '_callable', 1));
 }
 /**
  * Will determine if a method can be called.
  *
  * @param  string  $method     Method name.
  * @param  bool    $internal   Interal call or not.
  * @return bool
  */
 public function respondsTo($method, $internal = false)
 {
     return Inspector::isCallable($this, $method, $internal);
 }
Example #5
0
 /**
  * Determines if a given method can be called.
  *
  * @param string $method Name of the method.
  * @param boolean $internal 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;
 }