[AsseticBundle] moved base path to object property
This commit is contained in:
parent
dea5b26c3f
commit
a11f18687b
@ -26,6 +26,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*/
|
*/
|
||||||
class DumpCommand extends Command
|
class DumpCommand extends Command
|
||||||
{
|
{
|
||||||
|
private $basePath;
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
@ -36,20 +38,23 @@ class DumpCommand extends Command
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function initialize(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
if (!$basePath = $input->getArgument('write_to')) {
|
parent::initialize($input, $output);
|
||||||
$basePath = $this->container->getParameter('assetic.write_to');
|
|
||||||
|
$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');
|
$am = $this->container->get('assetic.asset_manager');
|
||||||
|
|
||||||
if ($input->getOption('watch')) {
|
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) {
|
foreach ($am->getNames() as $name) {
|
||||||
$this->dumpAsset($am->get($name), $basePath, $output);
|
$this->dumpAsset($am->get($name), $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +65,10 @@ class DumpCommand extends Command
|
|||||||
* manager for changes.
|
* manager for changes.
|
||||||
*
|
*
|
||||||
* @param LazyAssetManager $am The asset manager
|
* @param LazyAssetManager $am The asset manager
|
||||||
* @param string $basePath The base directory to write to
|
|
||||||
* @param OutputInterface $output The command output
|
* @param OutputInterface $output The command output
|
||||||
* @param Boolean $debug Debug mode
|
* @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) {
|
if (!$debug) {
|
||||||
throw new \RuntimeException('The --watch option is only available in debug mode.');
|
throw new \RuntimeException('The --watch option is only available in debug mode.');
|
||||||
@ -74,7 +78,7 @@ class DumpCommand extends Command
|
|||||||
$prop = $refl->getProperty('assets');
|
$prop = $refl->getProperty('assets');
|
||||||
$prop->setAccessible(true);
|
$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)) {
|
if (file_exists($cache)) {
|
||||||
$previously = unserialize(file_get_contents($cache));
|
$previously = unserialize(file_get_contents($cache));
|
||||||
} else {
|
} else {
|
||||||
@ -86,7 +90,7 @@ class DumpCommand extends Command
|
|||||||
try {
|
try {
|
||||||
foreach ($am->getNames() as $name) {
|
foreach ($am->getNames() as $name) {
|
||||||
if ($asset = $this->checkAsset($am, $name, $previously)) {
|
if ($asset = $this->checkAsset($am, $name, $previously)) {
|
||||||
$this->dumpAsset($asset, $basePath, $output);
|
$this->dumpAsset($asset, $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,14 +141,13 @@ class DumpCommand extends Command
|
|||||||
* Writes an asset.
|
* Writes an asset.
|
||||||
*
|
*
|
||||||
* @param AssetInterface $asset An asset
|
* @param AssetInterface $asset An asset
|
||||||
* @param string $basePath The base directory to write to
|
|
||||||
* @param OutputInterface $output The command output
|
* @param OutputInterface $output The command output
|
||||||
*
|
*
|
||||||
* @throws RuntimeException If there is a problem writing the asset
|
* @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))) {
|
if (!is_dir($dir = dirname($target))) {
|
||||||
$output->writeln('<info>[dir+]</info> '.$dir);
|
$output->writeln('<info>[dir+]</info> '.$dir);
|
||||||
if (false === @mkdir($dir, 0777, true)) {
|
if (false === @mkdir($dir, 0777, true)) {
|
||||||
|
Reference in New Issue
Block a user