Skip to content

Commit 616b206

Browse files
Merge branch '4.1' into 4.2
* 4.1: [Routing] fix trailing slash redirections involving a trailing var [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 0dc0dcf + 8a9f2ff commit 616b206

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;
@@ -56,7 +57,7 @@ protected function configure()
5657
{
5758
$this
5859
->setDefinition(array(
59-
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
60+
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null),
6061
))
6162
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
6263
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
@@ -94,6 +95,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9495
$kernel = $this->getApplication()->getKernel();
9596
$targetArg = rtrim($input->getArgument('target'), '/');
9697

98+
if (!$targetArg) {
99+
$targetArg = $this->getPublicDirectory($this->getContainer());
100+
}
101+
97102
if (!is_dir($targetArg)) {
98103
$targetArg = $kernel->getProjectDir().'/'.$targetArg;
99104

@@ -250,4 +255,27 @@ private function hardCopy(string $originDir, string $targetDir): string
250255

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

0 commit comments

Comments
 (0)