Permalink
Browse files

[AsseticBundle] moved base path to object property

  • Loading branch information...
1 parent e4277a3 commit 10e1f2fd65c5bfc58bfec87c9e41e2862bbd4431 @kriswallsmith kriswallsmith committed May 7, 2011
Showing with 21 additions and 18 deletions.
  1. +21 −18 Command/DumpCommand.php
View
@@ -26,6 +26,8 @@
*/
class DumpCommand extends Command
{
+ private $basePath;
+
protected function configure()
{
$this
@@ -36,20 +38,23 @@ protected function configure()
;
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function initialize(InputInterface $input, OutputInterface $output)
{
- if (!$basePath = $input->getArgument('write_to')) {
- $basePath = $this->container->getParameter('assetic.write_to');
- }
+ parent::initialize($input, $output);
+ $this->basePath = $input->getArgument('write_to') ?: $this->container->getParameter('assetic.write_to');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
$am = $this->container->get('assetic.asset_manager');
if ($input->getOption('watch')) {
- return $this->watch($am, $basePath, $output, $this->container->getParameter('kernel.debug'));
+ return $this->watch($am, $output, $this->container->getParameter('kernel.debug'));
}
foreach ($am->getNames() as $name) {
- $this->dumpAsset($am->get($name), $basePath, $output);
+ $this->dumpAsset($am->get($name), $output);
}
}
@@ -59,12 +64,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
* This method includes an infinite loop the continuously polls the asset
* manager for changes.
*
- * @param LazyAssetManager $am The asset manager
- * @param string $basePath The base directory to write to
- * @param OutputInterface $output The command output
- * @param Boolean $debug Debug mode
+ * @param LazyAssetManager $am The asset manager
+ * @param OutputInterface $output The command output
+ * @param Boolean $debug Debug mode
*/
- protected function watch(LazyAssetManager $am, $basePath, OutputInterface $output, $debug = false)
+ protected function watch(LazyAssetManager $am, OutputInterface $output, $debug = false)
{
if (!$debug) {
throw new \RuntimeException('The --watch option is only available in debug mode.');
@@ -74,7 +78,7 @@ protected function watch(LazyAssetManager $am, $basePath, OutputInterface $outpu
$prop = $refl->getProperty('assets');
$prop->setAccessible(true);
- $cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($basePath), 0, 7);
+ $cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($this->basePath), 0, 7);
if (file_exists($cache)) {
$previously = unserialize(file_get_contents($cache));
} else {
@@ -86,7 +90,7 @@ protected function watch(LazyAssetManager $am, $basePath, OutputInterface $outpu
try {
foreach ($am->getNames() as $name) {
if ($asset = $this->checkAsset($am, $name, $previously)) {
- $this->dumpAsset($asset, $basePath, $output);
+ $this->dumpAsset($asset, $output);
}
}
@@ -136,15 +140,14 @@ protected function checkAsset(LazyAssetManager $am, $name, array &$previously)
/**
* Writes an asset.
*
- * @param AssetInterface $asset An asset
- * @param string $basePath The base directory to write to
- * @param OutputInterface $output The command output
+ * @param AssetInterface $asset An asset
+ * @param OutputInterface $output The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
- protected function dumpAsset(AssetInterface $asset, $basePath, OutputInterface $output)
+ protected function dumpAsset(AssetInterface $asset, OutputInterface $output)
{
- $target = rtrim($basePath, '/').'/'.str_replace('_controller/', '', $asset->getTargetUrl());
+ $target = rtrim($this->basePath, '/').'/'.str_replace('_controller/', '', $asset->getTargetUrl());
if (!is_dir($dir = dirname($target))) {
$output->writeln('<info>[dir+]</info> '.$dir);
if (false === @mkdir($dir, 0777, true)) {

0 comments on commit 10e1f2f

Please sign in to comment.