Skip to content

[HttpKernel] add a deprecation for global dir #31958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<service id="file_locator" class="Symfony\Component\HttpKernel\Config\FileLocator">
<argument type="service" id="kernel" />
<argument>%kernel.root_dir%/Resources</argument>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you removed this argument. how does %kernel.root_dir%/Resources still work then?

<argument>null</argument>
<argument type="collection">
<argument>%kernel.root_dir%</argument>
</argument>
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/HttpKernel/Config/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class FileLocator extends BaseFileLocator
* @param string|null $path The path the global resource directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the phpdoc should be removed if it's not inteded to be used anymore

* @param array $paths An array of paths where to look for resources
*/
public function __construct(KernelInterface $kernel, string $path = null, array $paths = [])
public function __construct(KernelInterface $kernel, $paths = [])
{
$this->kernel = $kernel;
if (null !== $path) {
if (3 === \count(\func_get_args()) && \is_string(func_get_arg(1)) && null !== ($path = func_get_arg(1))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use func_num_args here

$paths = func_get_arg(2);
$this->path = $path;
$paths[] = $path;
@trigger_error(sprintf('Using "$path" for a global resource directory in %s is deprecated since Symfony 4.4 and will be removed in 5.0.', __METHOD__), E_USER_DEPRECATED);
}

parent::__construct($paths);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ public function locateResource($name, $dir = null, $first = true)
$files = [];

if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
if (0 === strpos($dir, 'app') || 0 === strpos($dir, 'src')) {
Copy link
Contributor

@Tobion Tobion Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$dir would normally be %kernel.root_dir%/Resources. I don't see when it would ever start with app or src? What is this supposed to do? Do we not always want to trigger a deprecation if a bundle overwrite is found?

@trigger_error('Using the global fallback to load resources is deprecated since Symfony 4.4 and will be removed in 5.0.', E_USER_DEPRECATED);
}
$files[] = $file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function testLocate()
$locator->locate('/some/path');
}

/**
* @group legacy
* @expectedDeprecated Using the global fallback to load resources is deprecated since Symfony 4.4 and will be removed in 5.0.
*/
public function testLocateWithGlobalResourcePath()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
Expand All @@ -42,7 +46,7 @@ public function testLocateWithGlobalResourcePath()
->method('locateResource')
->with('@BundleName/some/path', '/global/resource/path', false);

$locator = new FileLocator($kernel, '/global/resource/path');
$locator->locate('@BundleName/some/path', null, false);
$locator = new FileLocator($kernel, '/global/resource/path', []);
$locator->locate('@BundleName/some/path', '/global/resource/path', false);
}
}