MiniAsset\AssetConfig::paths PHP Метод

paths() публичный Метод

Get/set paths for an extension. Setting paths will replace global or per target existing paths. Its only intended for testing.
public paths ( string $ext, string $target = null, array $paths = null ) : array
$ext string Extension to get paths for.
$target string A build target. If provided the target's paths (if any) will also be returned.
$paths array Paths to replace either the global or per target paths.
Результат array An array of paths to search for assets on.
    public function paths($ext, $target = null, $paths = null)
    {
        if ($paths === null) {
            if (empty($this->_data[$ext]['paths'])) {
                $paths = array();
            } else {
                $paths = (array) $this->_data[$ext]['paths'];
            }
            if ($target !== null && !empty($this->_targets[$target]['paths'])) {
                $buildPaths = $this->_targets[$target]['paths'];
                $paths = array_merge($paths, $buildPaths);
            }
            return array_unique($paths);
        }
        $paths = array_map(array($this, '_replacePathConstants'), $paths);
        if ($target === null) {
            $this->_data[$ext]['paths'] = $paths;
        } else {
            $this->_targets[$target]['paths'] = $paths;
        }
    }

Usage Example

Пример #1
0
 /**
  * Create a single build target
  *
  * @param string $name The name of the target to build
  * @return MiniAsset\AssetTarget
  */
 public function target($name)
 {
     $ext = $this->config->getExt($name);
     $paths = $this->config->paths($ext, $name);
     $themed = $this->config->isThemed($name);
     $filters = $this->config->targetFilters($name);
     $target = $this->config->cachePath($ext) . $name;
     $files = [];
     $scanner = $this->scanner($paths);
     foreach ($this->config->files($name) as $file) {
         if (preg_match('#^https?://#', $file)) {
             $files[] = new Remote($file);
         } else {
             if (preg_match('/(.*\\/)(\\*.*?)$/U', $file, $matches)) {
                 $path = $scanner->find($matches[1]);
                 if ($path === false) {
                     throw new RuntimeException("Could not locate folder {$file} for {$name} in any configured path.");
                 }
                 $glob = new Glob($path, $matches[2]);
                 $files = array_merge($files, $glob->files());
             } elseif (preg_match(static::CALLBACK_PATTERN, $file, $matches)) {
                 $callback = new Callback($matches[1], $matches[2], $scanner);
                 $files = array_merge($files, $callback->files());
             } else {
                 $path = $scanner->find($file);
                 if ($path === false) {
                     throw new RuntimeException("Could not locate {$file} for {$name} in any configured path.");
                 }
                 $files[] = new Local($path);
             }
         }
     }
     return new AssetTarget($target, $files, $filters, $paths, $themed);
 }