Esempio n. 1
0
 public function testFiles()
 {
     $glob = new Glob(dirname(__FILE__) . DS, '*');
     $files = $glob->files();
     $this->assertCount(3, $files);
     $this->assertEquals('GlobTest.php', $files[0]->name());
     $this->assertEquals('LocalTest.php', $files[1]->name());
     $this->assertEquals('RemoteTest.php', $files[2]->name());
 }
Esempio n. 2
0
 /**
  * Create a single build target
  *
  * @param string $name The name of the target to build
  * @return \MiniAsset\AssetTarget
  * @throws \RuntimeException
  */
 public function target($name)
 {
     if (!$this->config->hasTarget($name)) {
         throw new RuntimeException("The target named '{$name}' does not exist.");
     }
     $ext = $this->config->getExt($name);
     $themed = $this->config->isThemed($name);
     $filters = $this->config->targetFilters($name);
     $target = $this->config->cachePath($ext) . $name;
     $files = [];
     $scanner = $this->scanner($this->config->paths($ext, $name));
     $paths = $scanner->paths();
     $required = $this->config->requires($name);
     if ($required) {
         $compiler = $this->cachedCompiler();
         foreach ($required as $dependency) {
             $files[] = new Target($this->target($dependency), $compiler);
         }
     }
     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);
 }