Property | Type | Description | |
---|---|---|---|
$_cachedPaths | array | Holds cached class paths generated and used by lithium\core\Libraries::load(). | |
$_configurations | array | The list of class libraries registered with the class loader. | |
$_default | string | Stores the name of the default library. When adding a library configuration to the application, if the 'default' option flag is set to true, the name of the library will be assigned. To retrieve the default library's configuration, use Libraries::get(true). | |
$_map | array | Holds associations between fully-namespaced class names and file's paths mapped with lithium\core\Libraries::map(). | |
$_methodFilters | array | Stores the closures that represent the method filters. They are indexed by method name. | |
$_paths | array | Used by Libraries::locate() to perform service location. This allows new types of objects (i.e. models, helpers, cache adapters and data sources) to be automatically 'discovered' when you register a new vendor library or plugin (using Libraries::add()). Because paths are checked in the order in which they appear, path templates should be specified from most-specific to least-specific. See the locate() method for usage examples. |
Method | Description | |
---|---|---|
add ( string $name, array $config = [] ) : array | Adds a class library from which files can be loaded. | |
applyFilter ( string $method, Closure $filter = null ) : void | Apply a closure to a method in Libraries. | |
cache ( array $cache = null ) : array | Returns or sets the the class path cache used for mapping class names to file paths, or locating classes using Libraries::locate(). | |
find ( mixed $library, array $options = [] ) : array | Finds the classes or namespaces belonging to a particular library. _Note_: This method assumes loaded class libraries use a consistent class-to-file naming convention. | |
get ( mixed $name = null, string $key = null ) : mixed | Allows library information to be retrieved in various ways, including: | |
instance ( string $type, string $name, array $options = [] ) : object | Uses service location (i.e. Libraries::locate()) to look up a named class of a particular type, and creates an instance of it, and passes an array of parameters to the constructor. | |
load ( string $class, boolean $require = false ) : void | Loads the class definition specified by $class. Looks through the list of libraries defined in $_configurations, which are added through lithium\core\Libraries::add(). | |
locate ( string $type, string $name = null, array $options = [] ) : mixed | Performs service location for an object of a specific type. If $name is a string, finds the first instance of a class with the given name in any registered library (i.e. apps, plugins or vendor libraries registered via Libraries::add()), based on each library's order of precedence. For example, this will find the first model called File in any plugin or class library loaded into an application, including the application itself. | |
map ( array $classes ) : void | Associtates fully-namespaced class names to their corresponding paths on the file system. | |
path ( string $class, array $options = [] ) : string | Get the corresponding physical file path for a class or namespace name. | |
paths ( mixed $path = null ) : mixed | Accessor method for the class path templates which Libraries uses to look up and load classes. Using this method, you can define your own types of classes, or modify the default organization of built-in class types. | |
realPath ( string $path ) : string | Wraps the PHP realpath() function to add support for finding paths to files inside Phar archives. | |
remove ( mixed $name ) | Removes a registered library, and unregister's the library's autoloader, if it has one. | |
unmap ( mixed $classes ) | Unmap fully-namespaced class names mapped using lithium\core\Libraries::map(). |
Method | Description | |
---|---|---|
_configure ( array $config ) : void | Configures the application environment based on a library's settings, including appending to the include path, loading a bootstrap file, and registering a loader with SPL's autoloading system. | |
_filter ( array $libs, array $config, array $options = [] ) : array | Filters a list of library search results by the given set of options. | |
_locateAll ( array $params, array $options = [] ) : array | Locates all possible classes for given set of parameters. | |
_locateDeferred ( boolean | null $defer, array $paths, array $params, array $options = [] ) : string | Performs service location lookups by library, based on the library's 'defer' flag. | |
_locatePath ( string $type, array $params ) : string | null | Helper function for returning known paths given a certain type. | |
_params ( string $type, string $name = "*" ) : array | Get params from type. | |
_search ( string $config, array $options, string $name = null ) : array | Search file system. | |
_searchPaths ( array $paths, string $library ) : array | Returns the list of valid search path templates for the given service location lookup. | |
_transformPath ( mixed $transform, string $class, array $options = [] ) : string | Handles the conversion of a class name to a file name using a custom transformation typically defined in the 'transform' key of a configuration defined through Libraries::add(). |
protected static _configure ( array $config ) : void | ||
$config | array | The new library's configuration array. |
return | void |
protected static _filter ( array $libs, array $config, array $options = [] ) : array | ||
$libs | array | List of found libraries. |
$config | array | The configuration of the library currently being searched within. |
$options | array | The options used to filter/format `$libs`. |
return | array | Returns a copy of `$libs`, filtered and transformed based on the configuration provided in `$options`. |
protected static _locateDeferred ( boolean | null $defer, array $paths, array $params, array $options = [] ) : string | ||
$defer | boolean | null | A boolean flag indicating which libraries to search, either the ones with the `'defer'` flag set, or the ones without. Providing `null` will cause the method to ignore the `'defer'` flag set on any library and perform a complete lookup. |
$paths | array | List of paths to be searched for the given service (class). These are defined in `lithium\core\Libraries::$_paths`, and are organized by class type. |
$params | array | The list of insert parameters to be injected into each path format string when searching for classes. |
$options | array | |
return | string | Returns a class path as a string if a given class is found, or null if no class in any path matching any of the parameters is located. |
protected static _transformPath ( mixed $transform, string $class, array $options = [] ) : string | ||
$transform | mixed | Either a closure or an array containing a regular expression match and replacement. If the closure returns an empty value, or the regular expression fails to match, will return `null`. |
$class | string | The class name which is attempting to be mapped to a file. |
$options | array | The configuration of the library as passed to `Libraries::add()`, along with any options specified in the call to `Libraries::path()`. |
return | string | Returns transformed path of a class to a file, or `null` if the transformation did not match. |
public static add ( string $name, array $config = [] ) : array | ||
$name | string | Library name, i.e. `'app'`, `'lithium'`, `'pear'` or `'aura'`. |
$config | array | Specifies where the library is in the filesystem, and how classes should be loaded from it. Allowed keys are: - `'bootstrap'` _mixed_: A file path (relative to `'path'`) to a bootstrap script that should be run when the library is added, or `true` to use the default bootstrap path, i.e. `config/bootstrap.php`. - `'defer'` _boolean_: If `true`, indicates that, when locating classes, this library should defer to other libraries in order of preference. - `'includePath'` _mixed_: If `true`, appends the absolutely-resolved value of `'path'` to the PHP include path. If a string, the value is appended to PHP's. - `'loader'`: An auto-loader method associated with the library, if any. - `'path'`: The directory containing the library. - `'prefix'` _string_: The class prefix this library uses, i.e. `'lithium\'`, `'Zend_'` or `'Solar_'`. If the library has no global prefix, set to `false`. - `'suffix'` _string_: Gets appended to the end of the file name. For example, most libraries end classes in `'.php'`, but some use `'.class.php'`, or `'.inc.php'`. - `'transform'` _\Closure_: Defines a custom way to transform a class name into its corresponding file path. Accepts either an array of two strings which are interpreted as the pattern and replacement for a regex, or an anonymous function, which receives the class name and library configuration arrays as parameters, and returns the full physical file path as output. - `'resources'` _string_: If this is the default library, this maybe set to the absolute path to the write-enabled application resources directory, which is used for caching, log files, uploads, etc. |
return | array | Returns the resulting set of options created for this library. |
public static cache ( array $cache = null ) : array | ||
$cache | array | An array of keys and values to use when pre-populating the cache. Keys are either class names (which match to file paths as values), or dot-separated lookup paths used by `locate()` (which matches to either a single class or an array of classes). If `false`, the cache is cleared. |
return | array | Returns an array of cached class lookups, formatted per the description for `$cache`. |
public static find ( mixed $library, array $options = [] ) : array | ||
$library | mixed | The name of a library added to the application with `Libraries::add()`, or `true` to search all libraries. |
$options | array | The options this method accepts: - `'path'` _string_: A physical filesystem path relative to the directory of the library being searched. If provided, only the classes or namespaces within this path will be returned. - `'recursive'` _boolean_: If `true`, recursively searches all directories (namespaces) in the given library. If `false` (the default), only searches the top level of the given path. - `'filter'` _string_: A regular expression applied to a class after it is transformed into a fully-namespaced class name. The default regular expression filters class names based on the [PSR-0](http://groups.google.com/group/php-standards/web/psr-0-final-proposal) PHP 5.3 naming standard. - `'exclude'` _mixed_: Can be either a regular expression of classes/namespaces to exclude, or a PHP callable to be used with `array_filter()`. - `'namespaces'` _boolean_: Indicates whether namespaces should be included in the search results. If `false` (the default), only classes are returned. |
return | array | Returns an array of fully-namespaced class names found in the given library or libraries. |
public static get ( mixed $name = null, string $key = null ) : mixed | ||
$name | mixed | Either the name of a library added in `Libraries::add()`, an array of library names, or a fully-namespaced class name (see usage examples above). |
$key | string | Optional key name. If `$name` is set and is the name of a valid library (or an array of valid libraries), returns the given named configuration key, i.e. `'path'`, `'webroot'` or `'resources'`. |
return | mixed | A configuation array for one or more libraries, or a string value if `$key` is specified and `$name` is a string, or a library name (string) if `$name` is a fully-namespaced class name. |
public static instance ( string $type, string $name, array $options = [] ) : object | ||
$type | string | The type of class as defined by `Libraries::$_paths`. |
$name | string | The un-namespaced name of the class to instantiate. |
$options | array | An array of constructor parameters to pass to the class. |
return | object | If the class is found, returns an instance of it, otherwise throws an exception. |
public static locate ( string $type, string $name = null, array $options = [] ) : mixed | ||
$type | string | The type of class to search for. Typically follows the name of the directory in which the class is stored, i.e. `'models'`, `'controllers'` or `'adapter'`. Some classes types, such as adapters, will require a greater degree of specificity when looking up the desired class. In this case, the dot syntax is used, as in this example when looking up cache adapters: `'adapter.storage.cache'`, or this example, when looking up authentication adapters: `'adapter.security.auth'`. |
$name | string | The base name (without namespace) of the class you wish to locate. If unspecified, `locate()` will attempt to find all classes of the type specified in `$type`. If you only wish to search for classes within a single plugin or library, you may use the dot syntax to prefix the class name with the library name, i.e. `'app.Post'`, which will only look for a `Post` model within the app itself. |
$options | array | The options to use when searching and returning class names. - `'type'` _string_: Defaults to `'class'`. If set to `'file'`, returns file names instead of class names. - `'library'` _string_: When specified, only the given library/plugin name will be searched. |
return | mixed | If `$name` is specified, returns the name of the first class found that matches `$name` and `$type`, or returns `null` if no matching classes were found in any registered library. If `$name` is not specified, returns an array of all classes found which match `$type`. |
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). |
return | string | Returns the absolute path to the file containing `$class`, or `null` if the file cannot be found. |
protected static array $_cachedPaths | ||
return | array |
protected static array $_configurations | ||
return | array |
protected static string $_default | ||
return | string |
protected static array $_map | ||
return | array |
protected static array $_methodFilters | ||
return | array |
protected static array $_paths | ||
return | array |