Skip to content

Commit 8a9f2ff

Browse files
Merge branch '3.4' into 4.1
* 3.4: [EventDispatcher] Revers event tracing order [Security] Prefer clone over unserialize(serialize()) for user refreshment [Console] OutputFormatter: move strtolower to createStyleFromString Adjust tests to work in the armhf architecture. Fixes #29281. Vietnamese translations improvement [Form] Fixed FormErrorIterator class phpdoc Renamed test controller from Controller to TestController so it doesn't show up in the IDE autocomplete. Don't use he in docs when its not needed EventSubscriberInterface isn't a man fixed public directory of web server and assets install when configured in composer.json
2 parents b561735 + e90c94c commit 8a9f2ff

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
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
2020
use Symfony\Component\Console\Style\SymfonyStyle;
21+
use Symfony\Component\DependencyInjection\ContainerInterface;
2122
use Symfony\Component\Filesystem\Exception\IOException;
2223
use Symfony\Component\Filesystem\Filesystem;
2324
use Symfony\Component\Finder\Finder;
@@ -55,7 +56,7 @@ protected function configure()
5556
{
5657
$this
5758
->setDefinition(array(
58-
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
59+
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null),
5960
))
6061
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
6162
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
@@ -92,6 +93,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9293
$kernel = $this->getApplication()->getKernel();
9394
$targetArg = rtrim($input->getArgument('target'), '/');
9495

96+
if (!$targetArg) {
97+
$targetArg = $this->getPublicDirectory($this->getContainer());
98+
}
99+
95100
if (!is_dir($targetArg)) {
96101
$targetArg = $kernel->getContainer()->getParameter('kernel.project_dir').'/'.$targetArg;
97102

@@ -248,4 +253,27 @@ private function hardCopy(string $originDir, string $targetDir): string
248253

249254
return self::METHOD_COPY;
250255
}
256+
257+
private function getPublicDirectory(ContainerInterface $container)
258+
{
259+
$defaultPublicDir = 'public';
260+
261+
if (!$container->hasParameter('kernel.project_dir')) {
262+
return $defaultPublicDir;
263+
}
264+
265+
$composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json';
266+
267+
if (!file_exists($composerFilePath)) {
268+
return $defaultPublicDir;
269+
}
270+
271+
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
272+
273+
if (isset($composerConfig['extra']['public-dir'])) {
274+
return $composerConfig['extra']['public-dir'];
275+
}
276+
277+
return $defaultPublicDir;
278+
}
251279
}

0 commit comments

Comments
 (0)