/** * Checks if an asset should be dumped. * * @param string $name The asset name * @param array &$previously An array of previous visits * * @return Boolean Whether the asset should be dumped */ private function checkAsset($name, array &$previously) { $formula = $this->am->hasFormula($name) ? serialize($this->am->getFormula($name)) : null; $asset = $this->am->get($name); $mtime = 0; foreach ($this->getAssetVarCombinations($asset) as $combination) { $asset->setValues($combination); $mtime = max($mtime, $this->am->getLastModified($asset)); } if (isset($previously[$name])) { $changed = $previously[$name]['mtime'] != $mtime || $previously[$name]['formula'] != $formula; } else { $changed = true; } $previously[$name] = array('mtime' => $mtime, 'formula' => $formula); return $changed; }
public function computeAsset($relative_path, $name = null) { $paths = is_array($relative_path) ? $relative_path : array($relative_path); if (count($paths) > 1 && null === $name) { throw new Exception('You have to define a name for asset collection'); } $am = new LazyAssetManager(new AssetFactory('')); $assets = array(); $asset_collection = new AssetCollection(); if ($this->settings['modes'] & Modes::CONCAT) { $assets[] = $asset_collection; } foreach ($paths as $p) { $file = $this->loader->fromAppPath($p); $asset = $file->asset(['compass' => $this->settings['modes'] & Modes::COMPASS]); $ext = str_replace(array('sass', 'scss'), 'css', File::getExt($p)); $filename = substr($p, 0, strrpos($p, '.')); if ($this->settings['modes'] & Modes::CONCAT) { $asset_collection->add($asset); if (null === $name) { $name = $filename . $ext; } $asset_collection->setTargetPath($name); } else { $asset->setTargetPath($filename . $ext); $assets[] = $asset; } } foreach ($assets as $asset) { // add the timestamp $target_path = explode('/', $asset->getTargetPath()); $file_name = array_pop($target_path); $target_path[] = $am->getLastModified($asset) . '-' . $file_name; $web_path = implode('/', $target_path); $asset->setTargetPath($web_path); if (!file_exists($this->settings['public_path'] . '/' . $this->settings['compiled_dir'] . '/' . $asset->getTargetPath())) { if ($this->settings['modes'] & Modes::MINIFY) { switch ($ext) { case '.css': $asset->ensureFilter(new \Assetic\Filter\CssMinFilter()); break; case '.js': $asset->ensureFilter(new \Assetic\Filter\JSMinFilter()); break; } } $writer = new AssetWriter($this->settings['public_path'] . '/' . $this->settings['compiled_dir']); $writer->writeAsset($asset); } } return $assets[0]; }