Skip to content

remove deprecated global resource dir and kernel.root_dir #33285

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

Merged
merged 1 commit into from
Aug 27, 2019
Merged
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
10 changes: 5 additions & 5 deletions src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function getDebugTemplateNameTestData()

public function testDebugTemplateNameWithChainLoader()
{
$tester = $this->createCommandTester(['templates/' => null], [], null, null, true);
$tester = $this->createCommandTester(['templates/' => null], [], null, true);
$ret = $tester->execute(['name' => 'base.html.twig'], ['decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
Expand All @@ -264,7 +264,7 @@ public function testDebugTemplateNameWithChainLoader()
public function testWithGlobals()
{
$message = '<error>foo</error>';
$tester = $this->createCommandTester([], [], null, null, false, ['message' => $message]);
$tester = $this->createCommandTester([], [], null, false, ['message' => $message]);
$tester->execute([], ['decorated' => true]);
$display = $tester->getDisplay();
$this->assertStringContainsString(json_encode($message), $display);
Expand All @@ -273,7 +273,7 @@ public function testWithGlobals()
public function testWithGlobalsJson()
{
$globals = ['message' => '<error>foo</error>'];
$tester = $this->createCommandTester([], [], null, null, false, $globals);
$tester = $this->createCommandTester([], [], null, false, $globals);
$tester->execute(['--format' => 'json'], ['decorated' => true]);
$display = $tester->getDisplay();
$display = json_decode($display, true);
Expand All @@ -292,7 +292,7 @@ public function testWithFilter()
$this->assertNotSame($display1, $display2);
}

private function createCommandTester(array $paths = [], array $bundleMetadata = [], string $defaultPath = null, string $rootDir = null, bool $useChainLoader = false, array $globals = []): CommandTester
private function createCommandTester(array $paths = [], array $bundleMetadata = [], string $defaultPath = null, bool $useChainLoader = false, array $globals = []): CommandTester
{
$projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
$loader = new FilesystemLoader([], $projectDir);
Expand All @@ -314,7 +314,7 @@ private function createCommandTester(array $paths = [], array $bundleMetadata =
}

$application = new Application();
$application->add(new DebugCommand($environment, $projectDir, $bundleMetadata, $defaultPath, null, $rootDir));
$application->add(new DebugCommand($environment, $projectDir, $bundleMetadata, $defaultPath, null));
$command = $application->find('debug:twig');

return new CommandTester($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@

<service id="file_locator" class="Symfony\Component\HttpKernel\Config\FileLocator">
<argument type="service" id="kernel" />
<argument>%kernel.root_dir%/Resources</argument>
<argument type="collection">
<argument>%kernel.root_dir%</argument>
</argument>
<argument>false</argument>
</service>
<service id="Symfony\Component\HttpKernel\Config\FileLocator" alias="file_locator" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ function ($path, $catalogue) use ($loadedMessages) {
->willReturn([]);

$container = new Container();
$container->setParameter('kernel.root_dir', $this->translationDir);

$kernel
->expects($this->any())
->method('getContainer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function ($path, $catalogue) use ($loadedMessages) {
->willReturn([]);

$container = new Container();
$container->setParameter('kernel.root_dir', $this->translationDir);
$kernel
->expects($this->any())
->method('getContainer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,6 @@ protected function createContainer(array $data = [])
'kernel.debug' => false,
'kernel.environment' => 'test',
'kernel.name' => 'kernel',
'kernel.root_dir' => __DIR__,
'kernel.container_class' => 'testContainer',
'container.build_hash' => 'Abc1234',
'container.build_id' => hash('crc32', 'Abc123423456789'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private function createContainer($sessionStorageOptions)
$container->setParameter('kernel.container_class', 'cc');
$container->setParameter('kernel.debug', true);
$container->setParameter('kernel.project_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->setParameter('kernel.secret', __DIR__);
if (null !== $sessionStorageOptions) {
$container->setParameter('session.storage.options', $sessionStorageOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ public function testRememberMeCookieInheritFrameworkSessionCookie($config, $same
$container->registerExtension(new FrameworkExtension());
$container->setParameter('kernel.bundles_metadata', []);
$container->setParameter('kernel.project_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->setParameter('kernel.cache_dir', __DIR__);

$container->loadFromExtension('security', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,10 @@ public function testRuntimeLoader()
$this->assertEquals('foo', $args['FooClass']->getValues()[0]);
}

private function createContainer(string $rootDir = __DIR__.'/Fixtures')
private function createContainer()
{
$container = new ContainerBuilder(new ParameterBag([
'kernel.cache_dir' => __DIR__,
'kernel.root_dir' => $rootDir,
'kernel.project_dir' => __DIR__,
'kernel.charset' => 'UTF-8',
'kernel.debug' => false,
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ CHANGELOG
* added method `getProjectDir()` to `KernelInterface`
* removed methods `serialize` and `unserialize` from `DataCollector`, store the serialized state in the data property instead
* made `ProfilerStorageInterface` internal
* removed the second and third argument of `KernelInterface::locateResource`
* removed the second and third argument of `FileLocator::__construct`
* removed loading resources from `%kernel.root_dir%/Resources` and `%kernel.root_dir%` as
fallback directories.

4.4.0
-----
Expand Down
50 changes: 5 additions & 45 deletions src/Symfony/Component/HttpKernel/Config/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,11 @@ class FileLocator extends BaseFileLocator
{
private $kernel;

/**
* @deprecated since Symfony 4.4
*/
private $path;

public function __construct(KernelInterface $kernel/*, string $path = null, array $paths = [], bool $triggerDeprecation = true*/)
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;

if (2 <= \func_num_args()) {
$this->path = func_get_arg(1);
$paths = 3 <= \func_num_args() ? func_get_arg(2) : [];
if (null !== $this->path) {
$paths[] = $this->path;
}

if (4 !== \func_num_args() || func_get_arg(3)) {
@trigger_error(sprintf('Passing more than one argument to %s is deprecated since Symfony 4.4 and will be removed in 5.0.', __METHOD__), E_USER_DEPRECATED);
}
} else {
$paths = [];
}

parent::__construct($paths);
parent::__construct();
}

/**
Expand All @@ -55,32 +36,11 @@ public function __construct(KernelInterface $kernel/*, string $path = null, arra
public function locate(string $file, string $currentPath = null, bool $first = true)
{
if (isset($file[0]) && '@' === $file[0]) {
return $this->kernel->locateResource($file, $this->path, $first, false);
}

$locations = parent::locate($file, $currentPath, $first);
$resource = $this->kernel->locateResource($file);

if (isset($file[0]) && !(
'/' === $file[0] || '\\' === $file[0]
|| (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && ('\\' === $file[2] || '/' === $file[2]))
|| null !== parse_url($file, PHP_URL_SCHEME)
)) {
// no need to trigger deprecations when the loaded file is given as absolute path
foreach ($this->paths as $deprecatedPath) {
if (\is_array($locations)) {
foreach ($locations as $location) {
if (0 === strpos($location, $deprecatedPath) && (null === $currentPath || false === strpos($location, $currentPath))) {
@trigger_error(sprintf('Loading the file "%s" from the global resource directory "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $file, $deprecatedPath), E_USER_DEPRECATED);
}
}
} else {
if (0 === strpos($locations, $deprecatedPath) && (null === $currentPath || false === strpos($locations, $currentPath))) {
@trigger_error(sprintf('Loading the file "%s" from the global resource directory "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $file, $deprecatedPath), E_USER_DEPRECATED);
}
}
}
return $first ? $resource : [$resource];
}

return $locations;
return parent::locate($file, $currentPath, $first);
}
}
40 changes: 2 additions & 38 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,8 @@ public function getBundle(string $name)
/**
* {@inheritdoc}
*/
public function locateResource(string $name/*, $dir = null, $first = true, $triggerDeprecation = true*/)
public function locateResource(string $name)
{
if (2 <= \func_num_args()) {
$dir = func_get_arg(1);
$first = 3 <= \func_num_args() ? func_get_arg(2) : true;

if (4 !== \func_num_args() || func_get_arg(3)) {
@trigger_error(sprintf('Passing more than one argument to %s is deprecated since Symfony 4.4 and will be removed in 5.0.', __METHOD__), E_USER_DEPRECATED);
}
} else {
$dir = null;
$first = true;
}

if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
}
Expand All @@ -255,27 +243,10 @@ public function locateResource(string $name/*, $dir = null, $first = true, $trig
list($bundleName, $path) = explode('/', $bundleName, 2);
}

$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
$overridePath = substr($path, 9);
$bundle = $this->getBundle($bundleName);
$files = [];

if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
$files[] = $file;

// see https://symfony.com/doc/current/bundles/override.html on how to overwrite parts of a bundle
@trigger_error(sprintf('Overwriting the resource "%s" with "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $name, $file), E_USER_DEPRECATED);
}

if (file_exists($file = $bundle->getPath().'/'.$path)) {
if ($first && !$isResource) {
return $file;
}
$files[] = $file;
}

if (\count($files) > 0) {
return $first && $isResource ? $files[0] : $files;
return $file;
}

throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
Expand Down Expand Up @@ -574,14 +545,7 @@ protected function getKernelParameters()
];
}

$rootDir = new \ReflectionObject($this);
$rootDir = \dirname($rootDir->getFileName());

return [
/*
* @deprecated since Symfony 4.2, use kernel.project_dir instead
*/
'kernel.root_dir' => realpath($rootDir) ?: $rootDir,
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testLocate()
$kernel
->expects($this->atLeastOnce())
->method('locateResource')
->with('@BundleName/some/path', null, true)
->with('@BundleName/some/path')
->willReturn('/bundle-name/some/path');
$locator = new FileLocator($kernel);
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));
Expand All @@ -33,19 +33,4 @@ public function testLocate()
$this->expectException('LogicException');
$locator->locate('/some/path');
}

/**
* @group legacy
*/
public function testLocateWithGlobalResourcePath()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel
->expects($this->atLeastOnce())
->method('locateResource')
->with('@BundleName/some/path', '/global/resource/path', false);

$locator = new FileLocator($kernel, '/global/resource/path');
$locator->locate('@BundleName/some/path', null, false);
}
}
Empty file.
59 changes: 0 additions & 59 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
Expand Down Expand Up @@ -359,64 +358,6 @@ public function testLocateResourceReturnsTheFirstThatMatches()
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
}

/**
* @group legacy
*/
public function testLocateResourceIgnoresDirOnNonResource()
{
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))
;

$this->assertEquals(
__DIR__.'/Fixtures/Bundle1Bundle/foo.txt',
$kernel->locateResource('@Bundle1Bundle/foo.txt', __DIR__.'/Fixtures')
);
}

/**
* @group legacy
*/
public function testLocateResourceReturnsTheDirOneForResources()
{
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))
;

$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle/foo.txt',
$kernel->locateResource('@FooBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources')
);
}

/**
* @group legacy
*/
public function testLocateResourceOnDirectoriesWithOverwrite()
{
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->exactly(2))
->method('getBundle')
->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))
;

$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle/',
$kernel->locateResource('@FooBundle/Resources/', __DIR__.'/Fixtures/Resources')
);
$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle',
$kernel->locateResource('@FooBundle/Resources', __DIR__.'/Fixtures/Resources')
);
}

public function testLocateResourceOnDirectories()
{
$kernel = $this->getKernel(['getBundle']);
Expand Down