public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->container = $this->getContainer();
     $this->assetic = $this->container->get('assetic.asset_manager');
     $files = array();
     foreach ($this->assetic->getNames() as $name) {
         $asset = $this->assetic->get($name);
         $group = array();
         foreach ($asset as $assetPart) {
             $absPath = realpath($assetPart->getSourceRoot() . '/' . $assetPart->getSourcePath());
             if ($absPath === false) {
                 continue;
             }
             $group[] = $assetPart->getTargetPath();
             $files[$assetPart->getTargetPath()] = $absPath;
         }
         $files[$asset->getTargetPath()] = $group;
     }
     switch ($input->getArgument('format')) {
         case 'json':
             $output->write(json_encode($files));
             break;
         default:
             $output->write(var_export($files, true));
             break;
     }
 }
Пример #2
0
 public function match(Http\IRequest $httpRequest)
 {
     $path = $httpRequest->getUrl()->getPath();
     foreach ($this->assetManager->getNames() as $name) {
         $asset = $this->assetManager->get($name);
         if ('/' . $asset->getTargetPath() === $path) {
             $this->dumpAsset($asset);
         }
     }
 }
Пример #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Dumping assets:');
     foreach ($this->assetManager->getNames() as $name) {
         $asset = $this->assetManager->get($name);
         $this->assetWriter->writeAsset($asset);
         $output->writeln("    <info>{$name}</info> -> <info>{$asset->getTargetPath()}</info>");
     }
     $count = count($this->assetManager->getNames());
     $output->writeln('');
     $output->writeln("Successfully dumped <info>{$count}</info> assets.");
 }
Пример #4
0
 public function writeManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         $asset = $am->get($name);
         $path = $this->dir . '/' . $asset->getTargetPath();
         if (!file_exists($path) || filemtime($path) < $asset->getLastModified()) {
             $this->writeAsset($asset);
         }
     }
 }
Пример #5
0
 public function writeManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         // pega as configuracoes de cada formula
         $combine = true;
         if ($am instanceof LazyAssetManager) {
             list($inputs, $filters, $options) = $am->getFormula($name);
             if (isset($options['combine'])) {
                 $combine = $options['combine'];
             } else {
                 if (isset($options['debug'])) {
                     $combine = !$options['debug'];
                 } else {
                     $combine = !$am->isDebug();
                 }
             }
         }
         $this->writeAsset($am->get($name), $combine);
     }
 }
Пример #6
0
 protected function dumpManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         $asset = $am->get($name);
         if ($am instanceof LazyAssetManager) {
             $formula = $am->getFormula($name);
         }
         $dump = true;
         if ($this->watching) {
             // watching mode
             $dump = false;
             $resolved = VarUtils::resolve($asset->getTargetPath(), $asset->getVars(), $asset->getValues());
             $dest = $this->pathToWeb . '/' . $resolved;
             if (file_exists($dest)) {
                 $destmtime = filemtime($dest);
             } else {
                 $destmtime = 0;
             }
             // compare source and destination mtime
             if ($asset->getLastModified() > $destmtime) {
                 if ($this->commandOutput) {
                     $this->commandOutput->writeln("Dumping {$dest}");
                 }
                 $dump = true;
             }
         }
         if ($dump) {
             $this->writer->writeAsset($asset);
             if (!isset($formula[2])) {
                 continue;
             }
             $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $am->isDebug();
             $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : null;
             if (null !== $combine ? !$combine : $debug) {
                 foreach ($asset as $leaf) {
                     $this->writer->writeAsset($leaf);
                 }
             }
         }
     }
 }
Пример #7
0
 public function getNames()
 {
     if (!$this->loaded) {
         $this->load();
     }
     return array_unique(array_merge(parent::getNames(), array_keys($this->formulae)));
 }
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset An asset
  */
 public function filterDump(AssetInterface $asset)
 {
     if (!$asset instanceof PuliAsset) {
         return;
     }
     $pathMap = array();
     // Get a map of repository paths to target paths
     // e.g. "/webmozart/puli/images/bg.png" => "/images/bg.png"
     foreach ($this->am->getNames() as $name) {
         $this->extractTargetPaths($this->am->get($name), $pathMap);
     }
     // Remember the repository dir of the current resource
     $repoPath = $asset->getSourcePath();
     $repoDir = Path::getDirectory($repoPath);
     // Get the target directory of the current resource
     // e.g. "css"
     $targetPath = $asset->getTargetPath();
     $targetDir = Path::getDirectory($targetPath);
     // Convert to an absolute path so that we can create a proper
     // relative path later on
     // e.g. "/css"
     if (!Path::isAbsolute($targetDir)) {
         $targetDir = '/' . $targetDir;
     }
     $content = CssUtils::filterReferences($asset->getContent(), function ($matches) use($pathMap, $repoDir, $repoPath, $targetDir, $targetPath) {
         // The referenced path is a repository path
         // e.g. "/webmozart/puli/images/bg.png"
         $referencedPath = $matches['url'];
         // Ignore empty URLs
         if ('' === $referencedPath) {
             return $matches[0];
         }
         // Ignore non-local paths
         if (!Path::isLocal($referencedPath)) {
             return $matches[0];
         }
         // Ignore "data:" URLs
         if (0 === strpos($referencedPath, 'data:')) {
             return $matches[0];
         }
         // If the referenced path is not absolute, resolve it relative to
         // the directory of the source file
         if (!Path::isAbsolute($referencedPath)) {
             $referencedPath = Path::makeAbsolute($referencedPath, $repoDir);
         }
         // The referenced asset must be known
         if (!array_key_exists($referencedPath, $pathMap)) {
             throw new AssetException(sprintf('The asset "%s" referenced in "%s" could not be found.', $referencedPath, $repoPath));
         }
         // The target path of the referenced file must be set
         if (!$pathMap[$referencedPath]) {
             throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $matches['url']));
         }
         // The target path of the source file must be set
         if (!$targetPath) {
             throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $repoPath));
         }
         // Get the relative path from the source directory to the reference
         // e.g. "/css/style.css" + "/images/bg.png" = "../images/bg.png"
         $relativePath = Path::makeRelative($pathMap[$referencedPath], $targetDir);
         return str_replace($matches['url'], $relativePath, $matches[0]);
     });
     $asset->setContent($content);
 }
Пример #9
0
 public function writeManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         $this->writeAsset($am->get($name));
     }
 }
Пример #10
0
 /**
  * Dumps the assets of given manager
  *
  * Doesn't use AssetWriter::writeManagerAssets since we also want to dump non-combined assets
  * (for example, when using twig extension in debug mode).
  *
  * @param AssetManager $am
  * @param AssetWriter  $writer
  */
 protected function dumpManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         $asset = $am->get($name);
         if ($am instanceof LazyAssetManager) {
             $formula = $am->getFormula($name);
         }
         $this->writer->writeAsset($asset);
         if (!isset($formula[2])) {
             continue;
         }
         $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $am->isDebug();
         $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : null;
         if (null !== $combine ? !$combine : $debug) {
             foreach ($asset as $leaf) {
                 $this->writer->writeAsset($leaf);
             }
         }
     }
 }