2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Output\Output;
|
2010-07-09 09:05:26 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\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-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
|
|
|
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'),
|
|
|
|
))
|
2010-10-07 20:26:30 +01:00
|
|
|
->addOption('symlink', null, InputOption::PARAMETER_NONE, 'Symlinks the assets instead of copying it')
|
2010-05-06 12:25:53 +01:00
|
|
|
->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-11-23 21:43:09 +00:00
|
|
|
foreach ($this->container->get('kernel')->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);
|
2010-10-07 20:26:30 +01:00
|
|
|
|
|
|
|
if ($input->getOption('symlink')) {
|
|
|
|
$filesystem->symlink($originDir, $targetDir);
|
|
|
|
} else {
|
|
|
|
mkdir($targetDir, 0777, true);
|
|
|
|
$filesystem->mirror($originDir, $targetDir);
|
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
}
|