remove deprecated global resource dir and kernel.root_dir

This commit is contained in:
Tobias Schultze 2019-08-21 18:32:56 +02:00
parent 9e88855f31
commit 9ffa2e3a67
15 changed files with 19 additions and 177 deletions

View File

@ -254,7 +254,7 @@ TXT
public function testDebugTemplateNameWithChainLoader() 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]); $ret = $tester->execute(['name' => 'base.html.twig'], ['decorated' => false]);
$this->assertEquals(0, $ret, 'Returns 0 in case of success'); $this->assertEquals(0, $ret, 'Returns 0 in case of success');
@ -264,7 +264,7 @@ TXT
public function testWithGlobals() public function testWithGlobals()
{ {
$message = '<error>foo</error>'; $message = '<error>foo</error>';
$tester = $this->createCommandTester([], [], null, null, false, ['message' => $message]); $tester = $this->createCommandTester([], [], null, false, ['message' => $message]);
$tester->execute([], ['decorated' => true]); $tester->execute([], ['decorated' => true]);
$display = $tester->getDisplay(); $display = $tester->getDisplay();
$this->assertStringContainsString(json_encode($message), $display); $this->assertStringContainsString(json_encode($message), $display);
@ -273,7 +273,7 @@ TXT
public function testWithGlobalsJson() public function testWithGlobalsJson()
{ {
$globals = ['message' => '<error>foo</error>']; $globals = ['message' => '<error>foo</error>'];
$tester = $this->createCommandTester([], [], null, null, false, $globals); $tester = $this->createCommandTester([], [], null, false, $globals);
$tester->execute(['--format' => 'json'], ['decorated' => true]); $tester->execute(['--format' => 'json'], ['decorated' => true]);
$display = $tester->getDisplay(); $display = $tester->getDisplay();
$display = json_decode($display, true); $display = json_decode($display, true);
@ -292,7 +292,7 @@ TXT
$this->assertNotSame($display1, $display2); $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'; $projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
$loader = new FilesystemLoader([], $projectDir); $loader = new FilesystemLoader([], $projectDir);
@ -314,7 +314,7 @@ TXT
} }
$application = new Application(); $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'); $command = $application->find('debug:twig');
return new CommandTester($command); return new CommandTester($command);

View File

@ -87,11 +87,6 @@
<service id="file_locator" class="Symfony\Component\HttpKernel\Config\FileLocator"> <service id="file_locator" class="Symfony\Component\HttpKernel\Config\FileLocator">
<argument type="service" id="kernel" /> <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>
<service id="Symfony\Component\HttpKernel\Config\FileLocator" alias="file_locator" /> <service id="Symfony\Component\HttpKernel\Config\FileLocator" alias="file_locator" />

View File

@ -171,8 +171,6 @@ class TranslationDebugCommandTest extends TestCase
->willReturn([]); ->willReturn([]);
$container = new Container(); $container = new Container();
$container->setParameter('kernel.root_dir', $this->translationDir);
$kernel $kernel
->expects($this->any()) ->expects($this->any())
->method('getContainer') ->method('getContainer')

View File

@ -160,7 +160,6 @@ class TranslationUpdateCommandTest extends TestCase
->willReturn([]); ->willReturn([]);
$container = new Container(); $container = new Container();
$container->setParameter('kernel.root_dir', $this->translationDir);
$kernel $kernel
->expects($this->any()) ->expects($this->any())
->method('getContainer') ->method('getContainer')

View File

@ -1391,7 +1391,6 @@ abstract class FrameworkExtensionTest extends TestCase
'kernel.debug' => false, 'kernel.debug' => false,
'kernel.environment' => 'test', 'kernel.environment' => 'test',
'kernel.name' => 'kernel', 'kernel.name' => 'kernel',
'kernel.root_dir' => __DIR__,
'kernel.container_class' => 'testContainer', 'kernel.container_class' => 'testContainer',
'container.build_hash' => 'Abc1234', 'container.build_hash' => 'Abc1234',
'container.build_id' => hash('crc32', 'Abc123423456789'), 'container.build_id' => hash('crc32', 'Abc123423456789'),

View File

@ -125,7 +125,6 @@ class AddSessionDomainConstraintPassTest extends TestCase
$container->setParameter('kernel.container_class', 'cc'); $container->setParameter('kernel.container_class', 'cc');
$container->setParameter('kernel.debug', true); $container->setParameter('kernel.debug', true);
$container->setParameter('kernel.project_dir', __DIR__); $container->setParameter('kernel.project_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->setParameter('kernel.secret', __DIR__); $container->setParameter('kernel.secret', __DIR__);
if (null !== $sessionStorageOptions) { if (null !== $sessionStorageOptions) {
$container->setParameter('session.storage.options', $sessionStorageOptions); $container->setParameter('session.storage.options', $sessionStorageOptions);

View File

@ -346,7 +346,6 @@ class SecurityExtensionTest extends TestCase
$container->registerExtension(new FrameworkExtension()); $container->registerExtension(new FrameworkExtension());
$container->setParameter('kernel.bundles_metadata', []); $container->setParameter('kernel.bundles_metadata', []);
$container->setParameter('kernel.project_dir', __DIR__); $container->setParameter('kernel.project_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->setParameter('kernel.cache_dir', __DIR__); $container->setParameter('kernel.cache_dir', __DIR__);
$container->loadFromExtension('security', [ $container->loadFromExtension('security', [

View File

@ -262,11 +262,10 @@ class TwigExtensionTest extends TestCase
$this->assertEquals('foo', $args['FooClass']->getValues()[0]); $this->assertEquals('foo', $args['FooClass']->getValues()[0]);
} }
private function createContainer(string $rootDir = __DIR__.'/Fixtures') private function createContainer()
{ {
$container = new ContainerBuilder(new ParameterBag([ $container = new ContainerBuilder(new ParameterBag([
'kernel.cache_dir' => __DIR__, 'kernel.cache_dir' => __DIR__,
'kernel.root_dir' => $rootDir,
'kernel.project_dir' => __DIR__, 'kernel.project_dir' => __DIR__,
'kernel.charset' => 'UTF-8', 'kernel.charset' => 'UTF-8',
'kernel.debug' => false, 'kernel.debug' => false,

View File

@ -22,6 +22,10 @@ CHANGELOG
* added method `getProjectDir()` to `KernelInterface` * added method `getProjectDir()` to `KernelInterface`
* removed methods `serialize` and `unserialize` from `DataCollector`, store the serialized state in the data property instead * removed methods `serialize` and `unserialize` from `DataCollector`, store the serialized state in the data property instead
* made `ProfilerStorageInterface` internal * 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 4.4.0
----- -----

View File

@ -23,30 +23,11 @@ class FileLocator extends BaseFileLocator
{ {
private $kernel; private $kernel;
/** public function __construct(KernelInterface $kernel)
* @deprecated since Symfony 4.4
*/
private $path;
public function __construct(KernelInterface $kernel/*, string $path = null, array $paths = [], bool $triggerDeprecation = true*/)
{ {
$this->kernel = $kernel; $this->kernel = $kernel;
if (2 <= \func_num_args()) { parent::__construct();
$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);
} }
/** /**
@ -55,32 +36,11 @@ class FileLocator extends BaseFileLocator
public function locate(string $file, string $currentPath = null, bool $first = true) public function locate(string $file, string $currentPath = null, bool $first = true)
{ {
if (isset($file[0]) && '@' === $file[0]) { if (isset($file[0]) && '@' === $file[0]) {
return $this->kernel->locateResource($file, $this->path, $first, false); $resource = $this->kernel->locateResource($file);
return $first ? $resource : [$resource];
} }
$locations = parent::locate($file, $currentPath, $first); return parent::locate($file, $currentPath, $first);
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 $locations;
} }
} }

View File

@ -227,20 +227,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/** /**
* {@inheritdoc} * {@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]) { if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name)); throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
} }
@ -255,28 +243,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
list($bundleName, $path) = explode('/', $bundleName, 2); list($bundleName, $path) = explode('/', $bundleName, 2);
} }
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
$overridePath = substr($path, 9);
$bundle = $this->getBundle($bundleName); $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 (file_exists($file = $bundle->getPath().'/'.$path)) {
if ($first && !$isResource) {
return $file; return $file;
} }
$files[] = $file;
}
if (\count($files) > 0) {
return $first && $isResource ? $files[0] : $files;
}
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name)); throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
} }
@ -574,14 +545,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
]; ];
} }
$rootDir = new \ReflectionObject($this);
$rootDir = \dirname($rootDir->getFileName());
return [ 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.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment, 'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug, 'kernel.debug' => $this->debug,

View File

@ -22,7 +22,7 @@ class FileLocatorTest extends TestCase
$kernel $kernel
->expects($this->atLeastOnce()) ->expects($this->atLeastOnce())
->method('locateResource') ->method('locateResource')
->with('@BundleName/some/path', null, true) ->with('@BundleName/some/path')
->willReturn('/bundle-name/some/path'); ->willReturn('/bundle-name/some/path');
$locator = new FileLocator($kernel); $locator = new FileLocator($kernel);
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path')); $this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));
@ -33,19 +33,4 @@ class FileLocatorTest extends TestCase
$this->expectException('LogicException'); $this->expectException('LogicException');
$locator->locate('/some/path'); $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);
}
} }

View File

@ -21,7 +21,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass; use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest; use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
@ -359,64 +358,6 @@ EOF;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt')); $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() public function testLocateResourceOnDirectories()
{ {
$kernel = $this->getKernel(['getBundle']); $kernel = $this->getKernel(['getBundle']);