lithium\analysis\Inspector::info PHP Method

info() public static method

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.
return array An array of the parsed meta-data information of the given identifier.
    public static function info($identifier, $info = array())
    {
        $info = $info ?: array_keys(static::$_methodMap);
        $type = static::type($identifier);
        $result = array();
        $class = null;
        if ($type === 'method' || $type === 'property') {
            list($class, $identifier) = explode('::', $identifier);
            try {
                $classInspector = new ReflectionClass($class);
            } catch (Exception $e) {
                return null;
            }
            if ($type === 'property') {
                $identifier = substr($identifier, 1);
                $accessor = 'getProperty';
            } else {
                $identifier = str_replace('()', '', $identifier);
                $accessor = 'getMethod';
            }
            try {
                $inspector = $classInspector->{$accessor}($identifier);
            } catch (Exception $e) {
                return null;
            }
            $result['modifiers'] = static::_modifiers($inspector);
        } elseif ($type === 'class') {
            $inspector = new ReflectionClass($identifier);
            $classInspector = null;
        } else {
            return null;
        }
        foreach ($info as $key) {
            if (!isset(static::$_methodMap[$key])) {
                continue;
            }
            if (method_exists($inspector, static::$_methodMap[$key])) {
                $setAccess = ($type === 'method' || $type === 'property') && array_intersect($result['modifiers'], array('private', 'protected')) !== array() && method_exists($inspector, 'setAccessible');
                if ($setAccess) {
                    $inspector->setAccessible(true);
                }
                $result[$key] = $inspector->{static::$_methodMap[$key]}();
                if ($setAccess) {
                    $inspector->setAccessible(false);
                }
            }
        }
        if ($type === 'property' && $classInspector && !$classInspector->isAbstract()) {
            $inspector->setAccessible(true);
            try {
                $result['value'] = $inspector->getValue(static::_class($class));
            } catch (Exception $e) {
                return null;
            }
        }
        if (isset($result['start']) && isset($result['end'])) {
            $result['length'] = $result['end'] - $result['start'];
        }
        if (isset($result['comment'])) {
            $result += Docblock::comment($result['comment']);
        }
        return $result;
    }

Usage Example

Example #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;
 }
All Usage Examples Of lithium\analysis\Inspector::info