Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand::execute PHP Method

execute() protected method

See also: Command
protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    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->get('kernel')->getBundles() as $bundle) {
            if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
                $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));

                $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));

                $filesystem->remove($targetDir);

                if ($input->getOption('symlink')) {
                    $filesystem->symlink($originDir, $targetDir);
                } else {
                    mkdir($targetDir, 0777, true);
                    $filesystem->mirror($originDir, $targetDir);
                }
            }
        }
    }

Usage Example

コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $excludeBundles = $input->getOption('exclude');
     if (!empty($excludeBundles)) {
         /** @var ContainerProxy $containerProxy */
         $containerProxy = $this->getContainer();
         $kernelProxy = new KernelProxy($containerProxy->get('kernel'));
         foreach ($excludeBundles as $bundleName) {
             $kernelProxy->excludeBundle($bundleName);
         }
         $containerProxy->replace('kernel', $kernelProxy);
     }
     parent::execute($input, $output);
 }
AssetsInstallCommand