|
17 | 17 | use Symfony\Component\Console\Input\InputOption; |
18 | 18 | use Symfony\Component\Console\Output\OutputInterface; |
19 | 19 | use Symfony\Component\Console\Style\SymfonyStyle; |
| 20 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
20 | 21 | use Symfony\Component\Filesystem\Exception\IOException; |
21 | 22 | use Symfony\Component\Filesystem\Filesystem; |
22 | 23 | use Symfony\Component\Finder\Finder; |
@@ -65,7 +66,7 @@ protected function configure() |
65 | 66 | { |
66 | 67 | $this |
67 | 68 | ->setDefinition(array( |
68 | | - new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'), |
| 69 | + new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null), |
69 | 70 | )) |
70 | 71 | ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') |
71 | 72 | ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') |
@@ -107,6 +108,10 @@ protected function execute(InputInterface $input, OutputInterface $output) |
107 | 108 | $kernel = $this->getApplication()->getKernel(); |
108 | 109 | $targetArg = rtrim($input->getArgument('target'), '/'); |
109 | 110 |
|
| 111 | + if (!$targetArg) { |
| 112 | + $targetArg = $this->getPublicDirectory($this->getContainer()); |
| 113 | + } |
| 114 | + |
110 | 115 | if (!is_dir($targetArg)) { |
111 | 116 | $targetArg = (isset($baseDir) ? $baseDir : $kernel->getContainer()->getParameter('kernel.project_dir')).'/'.$targetArg; |
112 | 117 |
|
@@ -288,4 +293,27 @@ private function hardCopy($originDir, $targetDir) |
288 | 293 |
|
289 | 294 | return self::METHOD_COPY; |
290 | 295 | } |
| 296 | + |
| 297 | + private function getPublicDirectory(ContainerInterface $container) |
| 298 | + { |
| 299 | + $defaultPublicDir = 'public'; |
| 300 | + |
| 301 | + if (!$container->hasParameter('kernel.project_dir')) { |
| 302 | + return $defaultPublicDir; |
| 303 | + } |
| 304 | + |
| 305 | + $composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json'; |
| 306 | + |
| 307 | + if (!file_exists($composerFilePath)) { |
| 308 | + return $defaultPublicDir; |
| 309 | + } |
| 310 | + |
| 311 | + $composerConfig = json_decode(file_get_contents($composerFilePath), true); |
| 312 | + |
| 313 | + if (isset($composerConfig['extra']['public-dir'])) { |
| 314 | + return $composerConfig['extra']['public-dir']; |
| 315 | + } |
| 316 | + |
| 317 | + return $defaultPublicDir; |
| 318 | + } |
291 | 319 | } |
0 commit comments