2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2010-06-24 06:49:27 +01:00
|
|
|
namespace Symfony\Framework\FoundationBundle\Command;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
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;
|
2010-06-24 06:49:27 +01:00
|
|
|
use Symfony\Framework\FoundationBundle\Util\Filesystem;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/*
|
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
|
2010-06-24 06:49:27 +01:00
|
|
|
* @subpackage Framework_FoundationBundle
|
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-07 15:09:11 +01:00
|
|
|
if (!is_dir($input->getArgument('target'))) {
|
2010-05-06 12:25:53 +01:00
|
|
|
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($this->container->getKernelService()->getBundles() as $bundle) {
|
2010-05-19 09:24:36 +01:00
|
|
|
if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
|
|
|
|
$output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-19 09:24:36 +01:00
|
|
|
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));
|
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
|
|
|
}
|
|
|
|
}
|