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;
     }
 }
Example #2
0
 /**
  * @param $name
  * @param bool $timestamp
  * @return mixed
  */
 public function url($name, $timestamp = true)
 {
     $asset = $this->assetManager->get($name);
     $params = ['filename' => $asset->getTargetPath()];
     if ($timestamp) {
         $params['v'] = $asset->getLastModified();
     }
     return $this->urlGenerator->generate('asset', $params);
 }
Example #3
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);
         }
     }
 }
Example #4
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.");
 }
 /**
  * Writes an asset.
  *
  * If the application or asset is in debug mode, each leaf asset will be
  * dumped as well.
  *
  * @param string          $name   An asset name
  * @param OutputInterface $stdout The command output
  */
 public function dumpAsset($name, OutputInterface $stdout)
 {
     $asset = $this->am->get($name);
     $formula = $this->am->getFormula($name);
     // start by dumping the main asset
     $this->doDump($asset, $stdout);
     // dump each leaf if debug
     if (isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug()) {
         foreach ($asset as $leaf) {
             $this->doDump($leaf, $stdout);
         }
     }
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->container = $this->getContainer();
     $this->assetic = $this->container->get('assetic.asset_manager');
     $asset = $this->assetic->get($input->getArgument('group'));
     $allAssets = $asset->all();
     $content = null;
     if ($input->getArgument('index') !== false) {
         $subAsset = $allAssets[intval($input->getArgument('index')) - 1];
         $content = $this->dump($subAsset);
         echo $content;
     } else {
         foreach ($allAssets as $subAsset) {
             echo $this->dump($subAsset);
         }
     }
 }
    public function get($name)
    {
        if (!parent::has($name) && isset($this->formulae[$name])) {
            $this->flush($name);
        }

        return parent::get($name);
    }
 /**
  * {@inheritdoc}
  */
 public function get($name)
 {
     try {
         return parent::get($name);
     } catch (\InvalidArgumentException $e) {
         return new FakeAsset($name);
     }
 }
 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);
         }
     }
 }
 public function code_mirror_get_css_theme($parameters)
 {
     $am = new AssetManager();
     $am->set('theme', new FileAsset($parameters['theme']));
     $am->get('theme');
     #var_dump($am, $am->get('theme'), $am->getNames()); die;
     if (isset($parameters['theme']) and $theme = $this->assetManager->getTheme($parameters['theme'])) {
         return $theme;
     }
     return false;
 }
 public function testTwo()
 {
     $uglify = new UglifyJs2Filter("/usr/bin/uglifyjs", "/usr/bin/node");
     $uglify->setCompress(true);
     $uglify->setMangle(true);
     $uglify->setCompress(true);
     $am = new AssetManager();
     $am->set("app", new AssetCollection(array(new GlobAsset(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "assets/src/*", array($uglify)))));
     echo $am->get("app")->dump();
     echo PHP_EOL;
 }
Example #12
0
 public function setupRendererFromOptions(Renderer $renderer, array $options)
 {
     if (!$this->hasStrategyForRenderer($renderer)) {
         throw new \Exception(sprintf('no strategy defined for renderer "%s"', $this->getRendererName($renderer)));
     }
     /** @var $strategy \AsseticBundle\View\StrategyInterface */
     $strategy = $this->getStrategyForRenderer($renderer);
     while ($assetAlias = array_shift($options)) {
         $assetAlias = ltrim($assetAlias, '@');
         /** @var $asset \Assetic\Asset\AssetInterface */
         $asset = $this->assetManager->get($assetAlias);
         $strategy->setupAsset($asset);
     }
 }
Example #13
0
 /**
  * Create an array of AssetInterface objects for a group.
  *
  * @param $name
  * @throws \InvalidArgumentException for undefined assets
  * @return array
  */
 protected function createAssetArray($name)
 {
     $config = $this->getConfig($name, 'assets', array());
     $assets = array();
     foreach ($config as $asset) {
         // existing asset definition
         if ($this->assets->has($asset)) {
             $assets[] = $this->assets->get($asset);
         } elseif (str_contains($asset, array('/', '.', '-'))) {
             $assets[] = $this->parseAssetDefinition($asset);
         } else {
             throw new \InvalidArgumentException("No asset '{$asset}' defined");
         }
     }
     return $assets;
 }
Example #14
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);
     }
 }
Example #15
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);
                 }
             }
         }
     }
 }
Example #16
0
 public function get($name)
 {
     if (!$this->loaded) {
         $this->load();
     }
     if (!parent::has($name) && isset($this->formulae[$name])) {
         list($inputs, $filters, $options) = $this->formulae[$name];
         $options['name'] = $name;
         parent::set($name, $this->factory->createAsset($inputs, $filters, $options));
     }
     return parent::get($name);
 }
 /**
  * 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);
 }
Example #18
0
 public function writeManagerAssets(AssetManager $am)
 {
     foreach ($am->getNames() as $name) {
         $this->writeAsset($am->get($name));
     }
 }
Example #19
0
 protected function assetic($files, $type)
 {
     $urls = [];
     foreach ($files as $key => $file) {
         $assetType = $this->parseInput($file);
         if ($assetType == 'http') {
             $urls[] = $file;
             unset($files[$key]);
         }
     }
     if (empty($files)) {
         return $urls;
     }
     $name = md5(implode(',', $files)) . '.' . $type;
     $cachePath = $this->config['paths']['pcache'];
     $cache = $this->config['paths']['cache'];
     $cachedFile = $this->config['locations']['cache'] . $name;
     $file = $cachePath . $name;
     $debug = $this->config['debug'];
     if (!$debug && file_exists($file)) {
         $urls[] = $cachedFile;
         return $urls;
     }
     $aw = new AssetWriter($cachePath);
     $am = new AssetManager();
     // Create the collection
     $collection = new AssetCollection();
     // Create the cache
     $cache = new FilesystemCache($cache);
     foreach ($files as $file) {
         $assetType = $this->parseInput($file);
         // Create the asset
         if ($assetType == 'file') {
             $asset = new FileAsset($file);
         } elseif ($assetType == 'glob') {
             $asset = new GlobAsset($file);
         } elseif ($assetType == 'http') {
             $asset = new HttpAsset($file);
         } elseif ($assetType == 'reference') {
             $asset = new AssetReference($am, substr($file, 1));
         }
         $filters = $this->getFilters($file);
         if (!empty($filters)) {
             foreach ($filters as $filter) {
                 // Add the filter
                 $asset->ensureFilter($filter);
             }
         }
         // Cache the asset so we don't have to reapply filters on future page loads
         $cachedAsset = new AssetCache($asset, $cache);
         // Add the cached asset to the collection
         $collection->add($cachedAsset);
     }
     if (!file_exists($file) || $collection->getLastModified() > filemtime($file)) {
         $am->set($type, $collection);
         $am->get($type)->setTargetPath($name);
         $aw->writeManagerAssets($am);
     }
     $urls[] = $cachedFile;
     return $urls;
 }
Example #20
0
 /**
  * @param string $assetName
  * @return string
  */
 public function __invoke($assetName)
 {
     $asset = $this->assetManager->get($assetName);
     return $asset->getTargetPath();
 }
 /**
  * @return \Assetic\AssetManager
  */
 private function getAssetManager()
 {
     return $this->container->get('assetic.asset_manager');
 }
 /**
  * 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);
             }
         }
     }
 }