2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Framework\WebBundle\Command;
|
|
|
|
|
|
|
|
use Symfony\Components\Console\Input\InputArgument;
|
|
|
|
use Symfony\Components\Console\Input\InputOption;
|
|
|
|
use Symfony\Components\Console\Input\InputInterface;
|
|
|
|
use Symfony\Components\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Components\Console\Output\Output;
|
|
|
|
use Symfony\Framework\WebBundle\Util\Filesystem;
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* AssetsInstallCommand.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2010-04-07 01:51:29 +01:00
|
|
|
* @package Symfony
|
|
|
|
* @subpackage Framework_WebBundle
|
2010-02-17 13:55:05 +00:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
|
|
|
class AssetsInstallCommand extends Command
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this
|
|
|
|
->setDefinition(array(
|
|
|
|
new InputArgument('target', InputArgument::REQUIRED, 'The target directory'),
|
|
|
|
))
|
|
|
|
->setName('assets:install')
|
|
|
|
;
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When the target directory does not exist
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
if (!is_dir($input->getArgument('target')))
|
|
|
|
{
|
|
|
|
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
|
|
|
|
$dirs = $this->container->getKernelService()->getBundleDirs();
|
|
|
|
foreach ($this->container->getKernelService()->getBundles() as $bundle)
|
|
|
|
{
|
|
|
|
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
|
|
|
|
$namespace = str_replace('/', '\\', dirname($tmp));
|
|
|
|
$class = basename($tmp);
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace].'/'.$class.'/Resources/public'))
|
|
|
|
{
|
|
|
|
$output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($class));
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$filesystem->remove($targetDir);
|
|
|
|
mkdir($targetDir, 0755, true);
|
|
|
|
$filesystem->mirror($originDir, $targetDir);
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
}
|