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

Analyzes a passed $identifier for more detailed information such as method/property modifiers (e.g. public, private, abstract)
public static info ( string $identifier, array $info = [] ) : array
$identifier string The identifier to be analyzed
$info array Optionally restrict or expand the default information returned from the `info` method. By default, the information returned is the same as the array keys contained in the `$_methodMap` property of Inspector.
Результат array An array of the parsed meta-data information of the given identifier.
Пример #1
0
 public static function get($library, $identifier, array $options = array())
 {
     static::_ensureIndexedLibrary($library);
     $defaults = array('namespaceDoc' => array(), 'language' => 'en');
     $options += $defaults;
     $options['namespaceDoc'] = (array) $options['namespaceDoc'];
     $config = Libraries::get('li3_docs');
     if (isset($config['namespaceDoc'])) {
         $options['namespaceDoc'] = array_merge($options['namespaceDoc'], (array) $config['namespaceDoc']);
     }
     $path = Libraries::path($identifier);
     static::_ensurePathInBase($path);
     if (file_exists($path) && !static::_isClassFile($path)) {
         return static::_file(compact('library', 'path', 'identifier'), $options);
     }
     $data = Inspector::info($identifier);
     $proto = compact('identifier', 'library') + array('name' => null, 'type' => Inspector::type($identifier), 'info' => array(), 'classes' => null, 'methods' => null, 'properties' => null, 'parent' => null, 'children' => null, 'source' => null, 'subClasses' => array(), 'description' => isset($data['description']) ? $data['description'] : null, 'text' => isset($data['text']) ? $data['text'] : null);
     $format = "_{$proto['type']}";
     $data = static::$format($proto, (array) $data, $options);
     if (!$data) {
         return false;
     }
     foreach (array('text', 'description') as $key) {
         $data[$key] = Code::embed($data[$key], compact('library'));
     }
     return $data;
 }
Пример #2
0
 /**
  * Runs main console application logic. Returns a list of 
  * available exercises by default. Otherwise runs the specified exercise.
  *
  * @param string $command 
  * @return void
  */
 public function run($command = null)
 {
     if ($command == null) {
         $this->out("{:heading}EXERCISES{:end}");
         foreach ($this->_exercises as $key => $exercise) {
             $library = strtok($exercise, '\\');
             $info = Inspector::info($exercise);
             $this->out($this->_pad($key . " {:blue}via {$library}{:end}"), 'heading');
             $this->out($this->_pad($info['description'] == '' ? '(No description)' : $info['description']), 2);
         }
         $this->stop();
     }
     if (isset($this->_exercises[$command])) {
         $className = $this->_exercises[$command];
         $exercise = new $className(array('command' => $this));
         $exercise->run();
     } else {
         $this->out("{:error}The exercise {:end}{:blue}\"{$command}\"{:end}{:error} you specified cannot be found. Please supply a valid exercise name.{:end}");
         $this->out();
         $this->stop(1);
     }
 }
Пример #3
0
 /**
  * Locates original location of closures.
  *
  * @param mixed $reference File or class name to inspect.
  * @param integer $callLine Line number of class reference.
  * @return mixed Returns the line number where the method called is defined.
  */
 protected static function _definition($reference, $callLine)
 {
     if (file_exists($reference)) {
         foreach (array_reverse(token_get_all(file_get_contents($reference))) as $token) {
             if (!is_array($token) || $token[2] > $callLine) {
                 continue;
             }
             if ($token[0] === T_FUNCTION) {
                 return $token[2];
             }
         }
         return;
     }
     list($class, ) = explode('::', $reference);
     if (!class_exists($class)) {
         return;
     }
     $classRef = new ReflectionClass($class);
     $methodInfo = Inspector::info($reference);
     $methodDef = join("\n", Inspector::lines($classRef->getFileName(), range($methodInfo['start'] + 1, $methodInfo['end'] - 1)));
     foreach (array_reverse(token_get_all("<?php {$methodDef} ?>")) as $token) {
         if (!is_array($token) || $token[2] > $callLine) {
             continue;
         }
         if ($token[0] === T_FUNCTION) {
             return $token[2] + $methodInfo['start'];
         }
     }
 }
Пример #4
0
 /**
  * This docblock has an extra * in the closing element.
  *
  */
 public function testBadlyClosedDocblock()
 {
     $info = Inspector::info(__METHOD__ . '()');
     $description = 'This docblock has an extra * in the closing element.';
     $this->assertEqual($description, $info['description']);
     $this->assertEqual('', $info['text']);
 }
Пример #5
0
 /**
  * Get the api for the class.
  *
  * @param string $class fully namespaced class in dot notation
  * @param string $type method|property
  * @param string $name the name of the method or property
  * @return array
  */
 public function api($class = null, $type = null, $name = null)
 {
     $class = str_replace(".", "\\", $class);
     switch ($type) {
         default:
             $info = Inspector::info($class);
             $result = array('class' => array('name' => Inflector::classify($info['shortName']), 'description' => $info['description']));
             break;
         case 'method':
             $result = $this->_methods($class, compact('name'));
             break;
         case 'property':
             $result = $this->_properties($class, compact('name'));
             break;
     }
     $this->_render($result);
 }
Пример #6
0
 /**
  * Tests getting reflection information based on a string identifier.
  */
 public function testIdentifierIntrospection()
 {
     $result = Inspector::info(__METHOD__);
     $this->assertEqual(array('public'), $result['modifiers']);
     $this->assertEqual(__FUNCTION__, $result['name']);
     $this->assertNull(Inspector::info('\\lithium\\util'));
     $info = Inspector::info('\\lithium\\analysis\\Inspector');
     $result = str_replace('\\', '/', $info['file']);
     $this->assertNotEmpty(strpos($result, '/analysis/Inspector.php'));
     $this->assertEqual('lithium\\analysis', $info['namespace']);
     $this->assertEqual('Inspector', $info['shortName']);
     $result = Inspector::info('\\lithium\\analysis\\Inspector::$_methodMap');
     $this->assertEqual('_methodMap', $result['name']);
     $expected = 'Maps reflect method names to result array keys.';
     $this->assertEqual($expected, $result['description']);
     $this->assertEqual(array('var' => 'array'), $result['tags']);
     $result = Inspector::info('\\lithium\\analysis\\Inspector::info()', array('modifiers', 'namespace', 'foo'));
     $this->assertEqual(array('modifiers', 'namespace'), array_keys($result));
     $this->assertNull(Inspector::info('\\lithium\\analysis\\Inspector::$foo'));
     $this->assertNull(Inspector::info('\\lithium\\core\\Foo::$foo'));
 }
Пример #7
0
 /**
  * Output the formatted available commands.
  *
  * @return void
  */
 protected function _renderCommands()
 {
     $commands = Libraries::locate('command', null, array('recursive' => false));
     foreach ($commands as $key => $command) {
         $library = strtok($command, '\\');
         if (!$key || strtok($commands[$key - 1], '\\') != $library) {
             $this->out("{:heading}COMMANDS{:end} {:blue}via {$library}{:end}");
         }
         $info = Inspector::info($command);
         $name = strtolower(Inflector::slug($info['shortName']));
         $this->out($this->_pad($name), 'heading');
         $this->out($this->_pad($info['description']), 2);
     }
     $message = 'See `{:command}li3 help COMMAND{:end}`';
     $message .= ' for more information on a specific command.';
     $this->out($message, 2);
 }
Пример #8
0
 /**
  * This is a helper method for testStorageMechanism to fetch a private
  * property of the Inflector class.
  *
  * @param string $property
  * @return string The value of the property.
  */
 private function getProtectedValue($property)
 {
     $info = Inspector::info("lithium\\util\\Inflector::{$property}");
     return $info['value'];
 }
Пример #9
0
 public function _parseClass($class)
 {
     $data = array();
     // $methods = Inspector::methods($class, null, array('public' => false));
     $methods = get_class_methods($class);
     $properties = array_keys(get_class_vars($class));
     $ident = $class;
     $info = Inspector::info($ident);
     $info = Docblock::comment($info['comment']);
     $data = $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
     $this->_merge($data, array('id' => $info['text'], 'comments' => array($class)));
     foreach ($methods as $method) {
         $ident = "{$class}::{$method}()";
         $info = Inspector::info($ident);
         $info = Docblock::comment($info['comment']);
         $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
         $this->_merge($data, array('id' => $info['text'], 'comments' => array($ident)));
         if (isset($info['tags']['return'])) {
             $this->_merge($data, array('id' => $info['tags']['return'], 'comments' => array($ident)));
         }
         foreach (Set::extract($info, '/tags/params/text') as $text) {
             $this->_merge($data, array('id' => $text, 'comments' => array($ident)));
         }
     }
     foreach ($properties as $property) {
         $ident = "{$class}::\${$property}";
         $info = Inspector::info($ident);
         $info = Docblock::comment($info['comment']);
         $data = $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
         $data = $this->_merge($data, array('id' => $info['text'], 'comments' => array($ident)));
     }
     return $data;
 }