/**
     * @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->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);
                }
            }
        }
    }
Exemplo n.º 2
0
 /**
  * execute the command
  *
  * @param InputInterface $input 
  * @param OutputInterface $output 
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // var_dump($this->application);die();
     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->application->getKernel()->getBundleDirs();
     foreach ($this->application->getKernel()->getBundles() as $bundle) {
         $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
         $namespace = str_replace('/', '\\', dirname($tmp));
         $class = basename($tmp);
         if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace] . '/' . $class . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($class));
             $filesystem->remove($targetDir);
             if (!file_exists(dirname($targetDir))) {
                 mkdir(dirname($targetDir), 0755, true);
             }
             $filesystem->symlink($originDir, $targetDir);
         }
     }
 }