public function writeAsset(AssetInterface $asset)
 {
     foreach ($this->getCombinations($asset->getVars()) as $combination) {
         $asset->setValues($combination);
         static::write($this->dir . '/' . PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()), $asset->dump());
     }
 }
Exemple #2
0
 public function getLastModified()
 {
     $source = PathUtils::resolvePath($this->source, $this->getVars(), $this->getValues());
     if (!is_file($source)) {
         throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
     }
     return filemtime($source);
 }
Exemple #3
0
 public function load(FilterInterface $additionalFilter = null)
 {
     if (false === ($content = @file_get_contents(PathUtils::resolvePath($this->sourceUrl, $this->getVars(), $this->getValues())))) {
         if ($this->ignoreErrors) {
             return;
         }
         throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
     }
     $this->doLoad($content, $additionalFilter);
 }
Exemple #4
0
 /**
  * Initializes the collection based on the glob(s) passed in.
  */
 private function initialize()
 {
     foreach ($this->globs as $glob) {
         $glob = PathUtils::resolvePath($glob, $this->getVars(), $this->getValues());
         if (false !== ($paths = glob($glob))) {
             foreach ($paths as $path) {
                 $this->add(new FileAsset($path, array(), $this->getSourceRoot()));
             }
         }
     }
     $this->initialized = true;
 }
 private function doDump(AssetInterface $asset, $documentRoot)
 {
     $writer = new AssetWriter(sys_get_temp_dir(), $this->container->getParameter('assetic.variables'));
     $ref = new \ReflectionMethod($writer, 'getCombinations');
     $ref->setAccessible(true);
     $combinations = $ref->invoke($writer, $asset->getVars());
     foreach ($combinations as $combination) {
         $asset->setValues($combination);
         $target = rtrim($documentRoot, '/') . '/' . str_replace('_controller/', '', PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()));
         if (!is_dir($dir = dirname($target))) {
             if (false === @mkdir($dir, 0777, true)) {
                 throw new \RuntimeException('Unable to create directory ' . $dir);
             }
         }
         if (false === @file_put_contents($target, $asset->dump())) {
             throw new \RuntimeException('Unable to write file ' . $target);
         }
     }
 }
Exemple #6
0
 /**
  * Performs the asset dump.
  *
  * @param AssetInterface  $asset  An asset
  * @param OutputInterface $output The command output
  *
  * @throws RuntimeException If there is a problem writing the asset
  */
 private function doDump(AssetInterface $asset, OutputInterface $output)
 {
     $writer = new AssetWriter(sys_get_temp_dir(), $this->getContainer()->getParameter('assetic.variables'));
     $ref = new \ReflectionMethod($writer, 'getCombinations');
     $ref->setAccessible(true);
     $combinations = $ref->invoke($writer, $asset->getVars());
     foreach ($combinations as $combination) {
         $asset->setValues($combination);
         $target = rtrim($this->basePath, '/') . '/' . str_replace('_controller/', '', PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()));
         if (!is_dir($dir = dirname($target))) {
             $output->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
             if (false === @mkdir($dir, 0777, true)) {
                 throw new \RuntimeException('Unable to create directory ' . $dir);
             }
         }
         $output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
         if ($this->verbose) {
             if ($asset instanceof \Traversable) {
                 foreach ($asset as $leaf) {
                     $root = $leaf->getSourceRoot();
                     $path = $leaf->getSourcePath();
                     $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
                 }
             } else {
                 $root = $asset->getSourceRoot();
                 $path = $asset->getSourcePath();
                 $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
             }
         }
         if (false === @file_put_contents($target, $asset->dump())) {
             throw new \RuntimeException('Unable to write file ' . $target);
         }
     }
 }