Skip to content

Commit 2aede9c

Browse files
committed
feature #29840 [FrameworkBundle] pass project dir into the assets install command (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [FrameworkBundle] pass project dir into the assets install command | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | symfony/symfony#29708 (comment) | License | MIT | Doc PR | Commits ------- b373d4206b pass project dir into the assets install command
2 parents ef6f382 + 8c55f2c commit 2aede9c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
4.3.0
55
-----
66

7+
* Not passing the project directory to the constructor of the `AssetsInstallCommand` is deprecated. This argument will
8+
be mandatory in 5.0.
79
* Added `ControllerTrait::isFormValid()`
810

911
4.2.0

Command/AssetsInstallCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ class AssetsInstallCommand extends Command
4242
protected static $defaultName = 'assets:install';
4343

4444
private $filesystem;
45+
private $projectDir;
4546

46-
public function __construct(Filesystem $filesystem)
47+
public function __construct(Filesystem $filesystem, string $projectDir = null)
4748
{
4849
parent::__construct();
4950

51+
if (null === $projectDir) {
52+
@trigger_error(sprintf('Not passing the project directory to the constructor of %s is deprecated since Symfony 4.3 and will not be supported in 5.0.', __CLASS__), E_USER_DEPRECATED);
53+
}
54+
5055
$this->filesystem = $filesystem;
56+
$this->projectDir = $projectDir;
5157
}
5258

5359
/**
@@ -260,11 +266,11 @@ private function getPublicDirectory(ContainerInterface $container)
260266
{
261267
$defaultPublicDir = 'public';
262268

263-
if (!$container->hasParameter('kernel.project_dir')) {
269+
if (null === $this->projectDir && !$container->hasParameter('kernel.project_dir')) {
264270
return $defaultPublicDir;
265271
}
266272

267-
$composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json';
273+
$composerFilePath = ($this->projectDir ?? $container->getParameter('kernel.project_dir')).'/composer.json';
268274

269275
if (!file_exists($composerFilePath)) {
270276
return $defaultPublicDir;

Resources/config/console.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<service id="console.command.assets_install" class="Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand">
2121
<argument type="service" id="filesystem" />
22+
<argument>%kernel.project_dir%</argument>
2223
<tag name="console.command" command="assets:install" />
2324
</service>
2425

0 commit comments

Comments
 (0)