lithium\analysis\Inspector::invokeMethod PHP Метод

invokeMethod() публичный статический Метод

Calls a method on this object with the given parameters. Provides an OO wrapper for forward_static_call_array().
public static invokeMethod ( string $method, array $params = [] ) : mixed
$method string Name of the method to call.
$params array Parameter list to use when calling `$method`.
Результат mixed Returns the result of the method call.
    public static function invokeMethod($method, $params = array())
    {
        return forward_static_call_array(array(get_called_class(), $method), $params);
    }

Usage Example

Пример #1
0
 /**
  * Get the methods for the class
  *
  * @param string $class
  * @param array $options
  * @return array
  */
 protected function _methods($class, $options = array())
 {
     $defaults = array('name' => null);
     $options += $defaults;
     $methods = Inspector::methods($class)->map(function ($item) {
         if ($item->name[0] === '_') {
             return;
         }
         $modifiers = array_values(Inspector::invokeMethod('_modifiers', array($item)));
         $setAccess = array_intersect($modifiers, array('private', 'protected')) != array();
         if ($setAccess) {
             $item->setAccessible(true);
         }
         $result = compact('modifiers') + array('docComment' => $item->getDocComment(), 'name' => $item->getName());
         if ($setAccess) {
             $item->setAccessible(false);
         }
         return $result;
     }, array('collect' => false));
     $results = array();
     foreach ($methods as $method) {
         $comment = Docblock::comment($method['docComment']);
         $name = $method['name'];
         $description = $comment['description'];
         $args = !isset($comment['tags']['params']) ? null : $comment['tags']['params'];
         $return = !isset($comment['tags']['return']) ? null : trim(strtok($comment['tags']['return'], ' '));
         $command = $name === 'run' ? null : $name;
         $command = !$command && !empty($args) ? '[ARGS]' : $command;
         $usage = "{$command} ";
         $usage .= empty($args) ? null : join(' ', array_map(function ($a) {
             return '[' . str_replace('$', '', trim($a)) . ']';
         }, array_keys($args)));
         $results[$name] = compact('name', 'description', 'return', 'args', 'usage');
         if ($name && $name == $options['name']) {
             return array($name => $results[$name]);
         }
     }
     return $results;
 }
All Usage Examples Of lithium\analysis\Inspector::invokeMethod