lithium\core\Libraries::path PHP Метод

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

Get the corresponding physical file path for a class or namespace name.
public static path ( string $class, array $options = [] ) : string
$class string The class name to locate the physical file for. If `$options['dirs']` is set to `true`, `$class` may also be a namespace name, in which case the corresponding directory will be located.
$options array Options for converting `$class` to a physical path: - `'dirs'`: Defaults to `false`. If `true`, will attempt to case-sensitively look up directories in addition to files (in which case `$class` is assumed to actually be a namespace).
Результат string Returns the absolute path to the file containing `$class`, or `null` if the file cannot be found.
    public static function path($class, array $options = array())
    {
        $defaults = array('dirs' => false);
        $options += $defaults;
        $class = ltrim($class, '\\');
        if (isset(static::$_cachedPaths[$class]) && !$options['dirs']) {
            return static::$_cachedPaths[$class];
        }
        if (isset(static::$_map[$class]) && !$options['dirs']) {
            return static::$_map[$class];
        }
        foreach (static::$_configurations as $name => $config) {
            $params = $options + $config;
            $suffix = $params['suffix'];
            if ($params['prefix'] && strpos($class, $params['prefix']) !== 0) {
                continue;
            }
            if ($transform = $params['transform']) {
                if ($file = static::_transformPath($transform, $class, $params)) {
                    return $file;
                }
                continue;
            }
            $path = str_replace("\\", '/', substr($class, strlen($params['prefix'])));
            $fullPath = "{$params['path']}/{$path}";
            if (!$options['dirs']) {
                return static::$_cachedPaths[$class] = static::realPath($fullPath . $suffix);
            }
            $list = glob(dirname($fullPath) . '/*');
            $list = array_map(function ($i) {
                return str_replace('\\', '/', $i);
            }, $list);
            if (in_array($fullPath . $suffix, $list)) {
                return static::$_cachedPaths[$class] = static::realPath($fullPath . $suffix);
            }
            return is_dir($fullPath) ? static::realPath($fullPath) : null;
        }
    }

Usage 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\core\Libraries::path