diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index a52fe67aba7d8..333d5cba904df 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; @@ -65,7 +66,7 @@ protected function configure() { $this ->setDefinition(array( - new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'), + new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null), )) ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') @@ -107,6 +108,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $kernel = $this->getApplication()->getKernel(); $targetArg = rtrim($input->getArgument('target'), '/'); + if (!$targetArg) { + $targetArg = $this->getPublicDirectory($this->getContainer()); + } + if (!is_dir($targetArg)) { $targetArg = (isset($baseDir) ? $baseDir : $kernel->getContainer()->getParameter('kernel.project_dir')).'/'.$targetArg; @@ -288,4 +293,24 @@ private function hardCopy($originDir, $targetDir) return self::METHOD_COPY; } + + private function getPublicDirectory(ContainerInterface $container) + { + $kernelProjectDir = $container->getParameter('kernel.project_dir'); + $composerFilePath = $kernelProjectDir . '/composer.json'; + + if (file_exists($composerFilePath)) { + $composerConfig = json_decode(file_get_contents($composerFilePath), true); + + if (isset($composerConfig['extra'])) { + if (isset($composerConfig['extra']['public-dir'])) { + return $composerConfig['extra']['public-dir']; + } elseif (isset($composerConfig['extra']['symfony-web-dir'])) { + return $composerConfig['extra']['symfony-web-dir']; + } + } + } + + return 'public'; + } }