remove deprecated global resource dir and kernel.root_dir
This commit is contained in:
parent
9e88855f31
commit
9ffa2e3a67
@ -254,7 +254,7 @@ TXT
|
||||
|
||||
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');
|
||||
@ -264,7 +264,7 @@ TXT
|
||||
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);
|
||||
@ -273,7 +273,7 @@ TXT
|
||||
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);
|
||||
@ -292,7 +292,7 @@ TXT
|
||||
$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);
|
||||
@ -314,7 +314,7 @@ TXT
|
||||
}
|
||||
|
||||
$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);
|
||||
|
@ -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" />
|
||||
|
||||
|
@ -171,8 +171,6 @@ class TranslationDebugCommandTest extends TestCase
|
||||
->willReturn([]);
|
||||
|
||||
$container = new Container();
|
||||
$container->setParameter('kernel.root_dir', $this->translationDir);
|
||||
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('getContainer')
|
||||
|
@ -160,7 +160,6 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
->willReturn([]);
|
||||
|
||||
$container = new Container();
|
||||
$container->setParameter('kernel.root_dir', $this->translationDir);
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('getContainer')
|
||||
|
@ -1391,7 +1391,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
'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'),
|
||||
|
@ -125,7 +125,6 @@ class AddSessionDomainConstraintPassTest extends TestCase
|
||||
$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);
|
||||
|
@ -346,7 +346,6 @@ class SecurityExtensionTest extends TestCase
|
||||
$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', [
|
||||
|
@ -262,11 +262,10 @@ class TwigExtensionTest extends TestCase
|
||||
$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,
|
||||
|
@ -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
|
||||
-----
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,32 +36,11 @@ class FileLocator extends BaseFileLocator
|
||||
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);
|
||||
$resource = $this->kernel->locateResource($file);
|
||||
|
||||
return $first ? $resource : [$resource];
|
||||
}
|
||||
|
||||
$locations = 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;
|
||||
return parent::locate($file, $currentPath, $first);
|
||||
}
|
||||
}
|
||||
|
@ -227,20 +227,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
/**
|
||||
* {@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));
|
||||
}
|
||||
@ -255,27 +243,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
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));
|
||||
@ -574,14 +545,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
];
|
||||
}
|
||||
|
||||
$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,
|
||||
|
@ -22,7 +22,7 @@ class FileLocatorTest extends TestCase
|
||||
$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'));
|
||||
@ -33,19 +33,4 @@ class FileLocatorTest extends TestCase
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
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;
|
||||
@ -359,64 +358,6 @@ EOF;
|
||||
$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']);
|
||||
|
Reference in New Issue
Block a user