Skip to content

Commit 548839f

Browse files
fixed public directory of web server and assets install when configured in composer.json
1 parent 1c1f86b commit 548839f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Command/AssetsInstallCommand.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Symfony\Component\DependencyInjection\ContainerInterface;
2021
use Symfony\Component\Filesystem\Exception\IOException;
2122
use Symfony\Component\Filesystem\Filesystem;
2223
use Symfony\Component\Finder\Finder;
@@ -65,7 +66,7 @@ protected function configure()
6566
{
6667
$this
6768
->setDefinition(array(
68-
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
69+
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null),
6970
))
7071
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
7172
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
@@ -107,6 +108,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
107108
$kernel = $this->getApplication()->getKernel();
108109
$targetArg = rtrim($input->getArgument('target'), '/');
109110

111+
if (!$targetArg) {
112+
$targetArg = $this->getPublicDirectory($this->getContainer());
113+
}
114+
110115
if (!is_dir($targetArg)) {
111116
$targetArg = (isset($baseDir) ? $baseDir : $kernel->getContainer()->getParameter('kernel.project_dir')).'/'.$targetArg;
112117

@@ -288,4 +293,27 @@ private function hardCopy($originDir, $targetDir)
288293

289294
return self::METHOD_COPY;
290295
}
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+
}
291319
}

0 commit comments

Comments
 (0)