Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[AsseticBundle] added error handling to --watch
  • Loading branch information
kriswallsmith committed Feb 25, 2011
commit 3ce1d82589c1ce379fb8a3c8b8104bc500b09f04
37 changes: 26 additions & 11 deletions src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function watch(LazyAssetManager $am, $baseDir, OutputInterface $output, $debug = false)
{
$refl = new \ReflectionClass('Assetic\\AssetManager');
$prop = $refl->getProperty('assets');
$prop->setAccessible(true);

$cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($baseDir), 0, 7);
if (file_exists($cache)) {
$previously = unserialize(file_get_contents($cache));
} else {
$previously = array();
}

$error = '';
while (true) {
// reload formulae when in debug
if ($debug) {
$am->load();
}
try {
foreach ($am->getNames() as $name) {
if ($asset = $this->checkAsset($am, $name, $previously)) {
$this->dumpAsset($asset, $baseDir, $output);
}
}

foreach ($am->getNames() as $name) {
if ($asset = $this->checkAsset($am, $name, $previously)) {
$this->dumpAsset($asset, $baseDir, $output);
// reset the asset manager
$prop->setValue($am, array());
if ($debug) {
$am->load();
}
}

file_put_contents($cache, serialize($previously));
sleep(1);
file_put_contents($cache, serialize($previously));
$error = '';

sleep(1);
} catch (\Exception $e) {
if ($error != $msg = $e->getMessage()) {
$output->writeln('<error>[error]</error> '.$msg);
$error = $msg;
}
}
}
}

Expand All @@ -101,7 +116,7 @@ protected function watch(LazyAssetManager $am, $baseDir, OutputInterface $output
*/
protected function checkAsset(LazyAssetManager $am, $name, array &$previously)
{
$formula = serialize($am->getFormula($name));
$formula = $am->hasFormula($name) ? serialize($am->getFormula($name)) : null;
$asset = $am->get($name);
$mtime = $asset->getLastModified();

Expand Down