* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * AssetsInstallCommand. * * @package Symfony * @subpackage Framework_FoundationBundle * @author Fabien Potencier */ class AssetsInstallCommand extends Command { /** * @see Command */ protected function configure() { $this ->setDefinition(array( new InputArgument('target', InputArgument::REQUIRED, 'The target directory'), )) ->setName('assets:install') ; } /** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { if (!is_dir($input->getArgument('target'))) { throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); } $filesystem = new Filesystem(); foreach ($this->container->getKernelService()->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { $output->writeln(sprintf('Installing assets for %s\\%s', $bundle->getNamespacePrefix(), $bundle->getName())); $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName())); $filesystem->remove($targetDir); mkdir($targetDir, 0755, true); $filesystem->mirror($originDir, $targetDir); } } } }