lithium\core\Libraries::get PHP Method

get() public static method

By name: embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(1-1) With no parameters, to return all configuration for all libraries: embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(22-22) By list of names with a key to extract: embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(34-34) With no name, and a key to extract, to return a key/value array, where the library name is the key, and the $key value is the value: embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(37-37) By containing class name: embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(45-45)
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 function get($name = null, $key = null)
    {
        $configs = static::$_configurations;
        if (!$name && !$key) {
            return $configs;
        }
        if ($name === true) {
            $name = static::$_default;
        }
        if (is_array($name) || !$name && $key) {
            $name = $name ?: array_keys(static::$_configurations);
            $call = array(get_called_class(), 'get');
            return array_combine($name, array_map($call, $name, array_fill(0, count($name), $key)));
        }
        $config = isset($configs[$name]) ? $configs[$name] : null;
        if ($key) {
            return isset($config[$key]) ? $config[$key] : null;
        }
        if (strpos($name, '\\') === false) {
            return $config;
        }
        foreach (static::$_configurations as $library => $config) {
            if ($config['prefix'] && strpos($name, $config['prefix']) === 0) {
                return $library;
            }
        }
    }

Usage Example

Ejemplo n.º 1
6
 /**
  * Compiles a template and writes it to a cache file, which is used for inclusion.
  *
  * @param string $file The full path to the template that will be compiled.
  * @param array $options Options for compilation include:
  *        - `path`: Path where the compiled template should be written.
  *        - `fallback`: Boolean indicating that if the compilation failed for some
  *                      reason (e.g. `path` is not writable), that the compiled template
  *                      should still be returned and no exception be thrown.
  * @return string The compiled template.
  */
 public static function template($file, array $options = array())
 {
     $cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
     $defaults = array('path' => $cachePath, 'fallback' => false);
     $options += $defaults;
     $stats = stat($file);
     $oname = basename(dirname($file)) . '_' . basename($file, '.php');
     $oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
     $template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
     $template = "{$options['path']}/{$template}";
     if (file_exists($template)) {
         return $template;
     }
     $compiled = static::compile(file_get_contents($file));
     if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
         foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
             if ($expired !== $template) {
                 unlink($expired);
             }
         }
         return $template;
     }
     if ($options['fallback']) {
         return $file;
     }
     throw new TemplateException("Could not write compiled template `{$template}` to cache.");
 }
All Usage Examples Of lithium\core\Libraries::get