Skip to content

Remove deprecated code paths that trigger a runtime notice #31957

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
Jun 9, 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
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field, throws an exception; pass `null` instead
* not explicitly passing an instance of `IdReader` to `DoctrineChoiceLoader` when it can optimize single id field, will not apply any optimization
* `DoctrineExtractor` now requires an `EntityManagerInterface` on instantiation

4.4.0
-----
Expand Down
15 changes: 2 additions & 13 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\PropertyInfo;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManagerInterface;
Expand All @@ -33,19 +32,9 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
private $entityManager;
private $classMetadataFactory;

/**
* @param EntityManagerInterface $entityManager
*/
public function __construct($entityManager)
public function __construct(EntityManagerInterface $entityManager)
{
if ($entityManager instanceof EntityManagerInterface) {
$this->entityManager = $entityManager;
} elseif ($entityManager instanceof ClassMetadataFactory) {
@trigger_error(sprintf('Injecting an instance of "%s" in "%s" is deprecated since Symfony 4.2, inject an instance of "%s" instead.', ClassMetadataFactory::class, __CLASS__, EntityManagerInterface::class), E_USER_DEPRECATED);
$this->classMetadataFactory = $entityManager;
} else {
throw new \TypeError(sprintf('$entityManager must be an instance of "%s", "%s" given.', EntityManagerInterface::class, \is_object($entityManager) ? \get_class($entityManager) : \gettype($entityManager)));
}
$this->entityManager = $entityManager;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class DoctrineExtractorTest extends TestCase
{
private function createExtractor(bool $legacy = false)
private function createExtractor()
{
$config = Setup::createAnnotationMetadataConfiguration([__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'], true);
$entityManager = EntityManager::create(['driver' => 'pdo_sqlite'], $config);
Expand All @@ -34,20 +34,10 @@ private function createExtractor(bool $legacy = false)
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('custom_foo', 'foo');
}

return new DoctrineExtractor($legacy ? $entityManager->getMetadataFactory() : $entityManager);
return new DoctrineExtractor($entityManager);
}

public function testGetProperties()
{
$this->doTestGetProperties(false);
}

public function testLegacyGetProperties()
{
$this->doTestGetProperties(true);
}

private function doTestGetProperties(bool $legacy)
{
$this->assertEquals(
[
Expand All @@ -69,21 +59,11 @@ private function doTestGetProperties(bool $legacy)
'indexedBar',
'indexedFoo',
],
$this->createExtractor($legacy)->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
$this->createExtractor()->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
);
}

public function testTestGetPropertiesWithEmbedded()
{
$this->doTestGetPropertiesWithEmbedded(false);
}

public function testLegacyTestGetPropertiesWithEmbedded()
{
$this->doTestGetPropertiesWithEmbedded(true);
}

private function doTestGetPropertiesWithEmbedded(bool $legacy)
{
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
Expand All @@ -94,7 +74,7 @@ private function doTestGetPropertiesWithEmbedded(bool $legacy)
'id',
'embedded',
],
$this->createExtractor($legacy)->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded')
$this->createExtractor()->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded')
);
}

Expand All @@ -103,33 +83,10 @@ private function doTestGetPropertiesWithEmbedded(bool $legacy)
*/
public function testExtract($property, array $type = null)
{
$this->doTestExtract(false, $property, $type);
}

/**
* @dataProvider typesProvider
*/
public function testLegacyExtract($property, array $type = null)
{
$this->doTestExtract(true, $property, $type);
}

private function doTestExtract(bool $legacy, $property, array $type = null)
{
$this->assertEquals($type, $this->createExtractor($legacy)->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, []));
$this->assertEquals($type, $this->createExtractor()->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, []));
}

public function testExtractWithEmbedded()
{
$this->doTestExtractWithEmbedded(false);
}

public function testLegacyExtractWithEmbedded()
{
$this->doTestExtractWithEmbedded(true);
}

private function doTestExtractWithEmbedded(bool $legacy)
{
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
Expand All @@ -141,7 +98,7 @@ private function doTestExtractWithEmbedded(bool $legacy)
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable'
)];

$actualTypes = $this->createExtractor($legacy)->getTypes(
$actualTypes = $this->createExtractor()->getTypes(
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded',
'embedded',
[]
Expand Down Expand Up @@ -197,32 +154,12 @@ public function typesProvider()

public function testGetPropertiesCatchException()
{
$this->doTestGetPropertiesCatchException(false);
}

public function testLegacyGetPropertiesCatchException()
{
$this->doTestGetPropertiesCatchException(true);
}

private function doTestGetPropertiesCatchException(bool $legacy)
{
$this->assertNull($this->createExtractor($legacy)->getProperties('Not\Exist'));
$this->assertNull($this->createExtractor()->getProperties('Not\Exist'));
}

public function testGetTypesCatchException()
{
return $this->doTestGetTypesCatchException(false);
}

public function testLegacyGetTypesCatchException()
{
return $this->doTestGetTypesCatchException(true);
}

private function doTestGetTypesCatchException(bool $legacy)
{
$this->assertNull($this->createExtractor($legacy)->getTypes('Not\Exist', 'baz'));
$this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz'));
}

public function testGeneratedValueNotWritable()
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/PhpUnit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.0.0
-----

* removed `weak_vendor` mode, use `max[self]=0` instead

4.3.0
-----

Expand Down
12 changes: 0 additions & 12 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
*/
class DeprecationErrorHandler
{
/**
* @deprecated since Symfony 4.3, use max[self]=0 instead
*/
const MODE_WEAK_VENDORS = 'weak_vendors';

const MODE_DISABLED = 'disabled';
const MODE_WEAK = 'max[total]=999999&verbose=0';
const MODE_STRICT = 'max[total]=0';
Expand Down Expand Up @@ -227,13 +222,6 @@ private function getConfiguration()
if ('weak' === $mode) {
return $this->configuration = Configuration::inWeakMode();
}
if (self::MODE_WEAK_VENDORS === $mode) {
++$this->deprecations['remaining directCount'];
$msg = sprintf('Setting SYMFONY_DEPRECATIONS_HELPER to "%s" is deprecated in favor of "max[self]=0"', $mode);
$ref = &$this->deprecations['remaining direct'][$msg]['count'];
++$ref;
$mode = 'max[self]=0';
}
if (isset($mode[0]) && '/' === $mode[0]) {
return $this->configuration = Configuration::fromRegex($mode);
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* removed `TwigEngine` class, use `\Twig\Environment` instead.
* removed `transChoice` filter and token
* `HttpFoundationExtension` requires a `UrlHelper` on instantiation

4.4.0
-----
Expand Down
29 changes: 2 additions & 27 deletions src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\UrlHelper;
use Symfony\Component\Routing\RequestContext;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

Expand All @@ -27,32 +25,9 @@ class HttpFoundationExtension extends AbstractExtension
{
private $urlHelper;

/**
* @param UrlHelper $urlHelper
*/
public function __construct($urlHelper)
public function __construct(UrlHelper $urlHelper)
{
if ($urlHelper instanceof UrlHelper) {
$this->urlHelper = $urlHelper;

return;
}

if (!$urlHelper instanceof RequestStack) {
throw new \TypeError(sprintf('The first argument must be an instance of "%s" or an instance of "%s".', UrlHelper::class, RequestStack::class));
}

@trigger_error(sprintf('Passing a "%s" instance as the first argument to the "%s" constructor is deprecated since Symfony 4.3, pass a "%s" instance instead.', RequestStack::class, __CLASS__, UrlHelper::class), E_USER_DEPRECATED);

$requestContext = null;
if (2 === \func_num_args()) {
$requestContext = \func_get_arg(1);
if (null !== $requestContext && !$requestContext instanceof RequestContext) {
throw new \TypeError(sprintf('The second argument must be an instance of "%s".', RequestContext::class));
}
}

$this->urlHelper = new UrlHelper($urlHelper, $requestContext);
$this->urlHelper = $urlHelper;
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.2
* @final
*/
class TranslationExtension extends AbstractExtension
{
Expand All @@ -40,10 +40,7 @@ public function __construct(TranslatorInterface $translator = null, NodeVisitorI
$this->translationNodeVisitor = $translationNodeVisitor;
}

/**
* @return TranslatorInterface|null
*/
public function getTranslator()
public function getTranslator(): ?TranslatorInterface
{
if (null === $this->translator) {
if (!interface_exists(TranslatorInterface::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
use Symfony\Bridge\Twig\Extension\HttpFoundationExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\UrlHelper;
use Symfony\Component\Routing\RequestContext;

/**
* @group legacy
*/
class HttpFoundationExtensionTest extends TestCase
{
/**
Expand All @@ -29,7 +27,7 @@ public function testGenerateAbsoluteUrl($expected, $path, $pathinfo)
{
$stack = new RequestStack();
$stack->push(Request::create($pathinfo));
$extension = new HttpFoundationExtension($stack);
$extension = new HttpFoundationExtension(new UrlHelper($stack));

$this->assertEquals($expected, $extension->generateAbsoluteUrl($path));
}
Expand Down Expand Up @@ -67,7 +65,7 @@ public function testGenerateAbsoluteUrlWithRequestContext($path, $baseUrl, $host
}

$requestContext = new RequestContext($baseUrl, 'GET', $host, $scheme, $httpPort, $httpsPort, $path);
$extension = new HttpFoundationExtension(new RequestStack(), $requestContext);
$extension = new HttpFoundationExtension(new UrlHelper(new RequestStack(), $requestContext));

$this->assertEquals($expected, $extension->generateAbsoluteUrl($path));
}
Expand All @@ -81,7 +79,7 @@ public function testGenerateAbsoluteUrlWithoutRequestAndRequestContext($path)
$this->markTestSkipped('The Routing component is needed to run tests that depend on its request context.');
}

$extension = new HttpFoundationExtension(new RequestStack());
$extension = new HttpFoundationExtension(new UrlHelper(new RequestStack()));

$this->assertEquals($path, $extension->generateAbsoluteUrl($path));
}
Expand All @@ -107,7 +105,7 @@ public function testGenerateAbsoluteUrlWithScriptFileName()

$stack = new RequestStack();
$stack->push($request);
$extension = new HttpFoundationExtension($stack);
$extension = new HttpFoundationExtension(new UrlHelper($stack));

$this->assertEquals(
'http://localhost/app/web/bundles/framework/css/structure.css',
Expand All @@ -126,7 +124,7 @@ public function testGenerateRelativePath($expected, $path, $pathinfo)

$stack = new RequestStack();
$stack->push(Request::create($pathinfo));
$extension = new HttpFoundationExtension($stack);
$extension = new HttpFoundationExtension(new UrlHelper($stack));

$this->assertEquals($expected, $extension->generateRelativePath($path));
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CHANGELOG
* Removed the `cache.app.simple` service and its corresponding PSR-16 autowiring alias
* Removed cache-related compiler passes and `RequestDataCollector`
* Removed the `translator.selector` and `session.save_listener` services
* Removed `SecurityUserValueResolver`, use `UserValueResolver` instead

4.4.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class ControllerResolver extends ContainerControllerResolver
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
</call>

<tag name="console.command" command="messenger:consume" />
<tag name="console.command" command="messenger:consume-messages" />
<tag name="monolog.logger" channel="messenger" />
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class DelegatingLoader extends BaseDelegatingLoader
{
Expand Down
Loading