440944f3c2
This PR was merged into the 4.2-dev branch.
Discussion
----------
Trigger deprecation notices when inherited class calls parent method but misses adding new arguments
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
This Pull Request concern severals components, the purpose here is to notify in dev mode that in a case of inherit class, a function will have a new or severals arguments in Symfony 5.0, therefore not implement it is deprecated since Symfony 4.2
The function is made by these conditions :
1- ```(func_num_args() < $x)``` where [x] is the number of arguments we will have in Symfony 5.0
this check allow to verify that the arguments are missing
2- ```(__CLASS__ !== \get_class($this))```
this check allow to verify that the name of the class is different than the base class, therefore that we are in the child class
3- ```(__CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName())```
this check allow to verify that the class of the current function is different than the base class, therefore the function has been rewrote into the child class
Code exemple :
```
public function method(/* void $myNewArgument = null */)
{
if ((func_num_args() < 1) && (__CLASS__ !== \get_class($this)) && (__CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName())){
@trigger_error(sprintf('The "%s()" method will have one `void $myNewArgument = null` argument in version 5.0 and higher.Not defining it is deprecated since Symfony 4.2.', __METHOD__ ), E_USER_DEPRECATED);
}
// do something
}
```
The unit test are made by creating a child Class using for the tested function ```return parent::function()``` and by calling this child class and catching the expected depreciation message
Commits
-------
f75fffa997
Trigger deprecation notices when inherited class calls parent method but misses adding new arguments
210 lines
7.5 KiB
Markdown
210 lines
7.5 KiB
Markdown
UPGRADE FROM 4.1 to 4.2
|
|
=======================
|
|
|
|
BrowserKit
|
|
----------
|
|
|
|
* The `Client::submit()` method will have a new `$serverParameters` argument in version 5.0, not defining it is deprecated.
|
|
|
|
Cache
|
|
-----
|
|
|
|
* Deprecated `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead.
|
|
|
|
Config
|
|
------
|
|
|
|
* Deprecated constructing a `TreeBuilder` without passing root node information.
|
|
* Deprecated `FileLoaderLoadException`, use `LoaderLoadException` instead.
|
|
|
|
Console
|
|
-------
|
|
|
|
* Deprecated passing a command as a string to `ProcessHelper::run()`,
|
|
pass the command as an array of arguments instead.
|
|
|
|
Before:
|
|
```php
|
|
$processHelper->run($output, 'ls -l');
|
|
```
|
|
|
|
After:
|
|
```php
|
|
$processHelper->run($output, array('ls', '-l'));
|
|
|
|
// alternatively, when a shell wrapper is required
|
|
$processHelper->run($output, Process::fromShellCommandline('ls -l'));
|
|
```
|
|
|
|
DoctrineBridge
|
|
--------------
|
|
|
|
* The `lazy` attribute on `doctrine.event_listener` tags was removed.
|
|
Listeners are now lazy by default. So any `lazy` attributes can safely be removed from those tags.
|
|
|
|
DomCrawler
|
|
----------
|
|
|
|
* The `Crawler::children()` method will have a new `$selector` argument in version 5.0, not defining it is deprecated.
|
|
|
|
Finder
|
|
------
|
|
|
|
* The `Finder::sortByName()` method will have a new `$useNaturalSort` argument in version 5.0, not defining it is deprecated.
|
|
|
|
Form
|
|
----
|
|
|
|
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
|
|
Instead of expecting such calls to return empty strings, check if the field has already been rendered.
|
|
|
|
Before:
|
|
```twig
|
|
{% for field in fieldsWithPotentialDuplicates %}
|
|
{{ form_widget(field) }}
|
|
{% endfor %}
|
|
```
|
|
|
|
After:
|
|
```twig
|
|
{% for field in fieldsWithPotentialDuplicates if not field.rendered %}
|
|
{{ form_widget(field) }}
|
|
{% endfor %}
|
|
```
|
|
|
|
Process
|
|
-------
|
|
|
|
* Deprecated the `Process::setCommandline()` and the `PhpProcess::setPhpBinary()` methods.
|
|
* Deprecated passing commands as strings when creating a `Process` instance.
|
|
|
|
Before:
|
|
```php
|
|
$process = new Process('ls -l');
|
|
```
|
|
|
|
After:
|
|
```php
|
|
$process = new Process(array('ls', '-l'));
|
|
|
|
// alternatively, when a shell wrapper is required
|
|
$process = Process::fromShellCommandline('ls -l');
|
|
```
|
|
|
|
FrameworkBundle
|
|
---------------
|
|
|
|
* The `framework.router.utf8` configuration option has been added. If your app's charset
|
|
is UTF-8 (see kernel's `getCharset()` method), it is recommended to set it to `true`:
|
|
this will generate 404s for non-UTF-8 URLs, which are incompatible with you app anyway,
|
|
and will allow dumping optimized routers and using Unicode classes in requirements.
|
|
* Added support for the SameSite attribute for session cookies. It is highly recommended to set this setting (`framework.session.cookie_samesite`) to `lax` for increased security against CSRF attacks.
|
|
* The `Controller` class has been deprecated, use `AbstractController` instead.
|
|
* The Messenger encoder/decoder configuration has been changed for a unified Messenger serializer configuration.
|
|
|
|
Before:
|
|
```yaml
|
|
framework:
|
|
messenger:
|
|
encoder: your_encoder_service_id
|
|
decoder: your_decoder_service_id
|
|
```
|
|
|
|
After:
|
|
```yaml
|
|
framework:
|
|
messenger:
|
|
serializer:
|
|
id: your_messenger_service_id
|
|
```
|
|
* The `ContainerAwareCommand` class has been deprecated, use `Symfony\Component\Console\Command\Command`
|
|
with dependency injection instead.
|
|
|
|
Messenger
|
|
---------
|
|
|
|
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
|
|
* The `handle` method of the `Symfony\Component\Messenger\Middleware\ValidationMiddleware` and `Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware` middlewares now requires an `Envelope` object to be given (because they implement the `EnvelopeAwareInterface`). When using these middleware with the provided `MessageBus`, you will not have to do anything. If you use the middlewares any other way, you can use `Envelope::wrap($message)` to create an envelope for your message.
|
|
* `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
|
|
needs to be an associative array or the method name.
|
|
|
|
Before:
|
|
```php
|
|
return [
|
|
[FirstMessage::class, 0],
|
|
[SecondMessage::class, -10],
|
|
];
|
|
```
|
|
|
|
After:
|
|
```php
|
|
yield FirstMessage::class => ['priority' => 0];
|
|
yield SecondMessage::class => ['priority => -10];
|
|
```
|
|
|
|
Before:
|
|
```php
|
|
return [
|
|
SecondMessage::class => ['secondMessageMethod', 20],
|
|
];
|
|
```
|
|
|
|
After:
|
|
```php
|
|
yield SecondMessage::class => [
|
|
'method' => 'secondMessageMethod',
|
|
'priority' => 20,
|
|
];
|
|
```
|
|
* The `EncoderInterface` and `DecoderInterface` interfaces have been replaced by a unified `Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`.
|
|
Each interface method have been merged untouched into the `Serializer` interface, so you can simply merge your two implementations together and implement the new interface.
|
|
|
|
|
|
Monolog
|
|
-------
|
|
|
|
* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` will have a new `$request` argument in version 5.0, not defining it is deprecated.
|
|
|
|
Security
|
|
--------
|
|
|
|
* Using the `has_role()` function in security expressions is deprecated, use the `is_granted()` function instead.
|
|
* Not returning an array of 3 elements from `FirewallMapInterface::getListeners()` is deprecated, the 3rd element
|
|
must be an instance of `LogoutListener` or `null`.
|
|
* Passing custom class names to the
|
|
`Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver` to define
|
|
custom anonymous and remember me token classes is deprecated. To
|
|
use custom tokens, extend the existing `Symfony\Component\Security\Core\Authentication\Token\AnonymousToken`
|
|
or `Symfony\Component\Security\Core\Authentication\Token\RememberMeToken`.
|
|
* Accessing the user object that is not an instance of `UserInterface` from `Security::getUser()` is deprecated.
|
|
|
|
SecurityBundle
|
|
--------------
|
|
|
|
* Passing a `FirewallConfig` instance as 3rd argument to the `FirewallContext` constructor is deprecated,
|
|
pass a `LogoutListener` instance instead.
|
|
* Using the `security.authentication.trust_resolver.anonymous_class` and
|
|
`security.authentication.trust_resolver.rememberme_class` parameters to define
|
|
the token classes is deprecated. To use
|
|
custom tokens extend the existing AnonymousToken and RememberMeToken.
|
|
|
|
Serializer
|
|
----------
|
|
|
|
* Relying on the default value (false) of the "as_collection" option is deprecated.
|
|
You should set it to false explicitly instead as true will be the default value in 5.0.
|
|
* The `AbstractNormalizer::handleCircularReference()` method will have two new `$format` and `$context` arguments in version 5.0, not defining them is deprecated.
|
|
|
|
Translation
|
|
-----------
|
|
|
|
* The `TranslatorInterface` has been deprecated in favor of `Symfony\Contracts\Translation\TranslatorInterface`
|
|
* The `MessageSelector`, `Interval` and `PluralizationRules` classes have been deprecated, use `IdentityTranslator` instead
|
|
|
|
Validator
|
|
---------
|
|
|
|
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
|
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
|
|
* Deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`. Use `Type` instead or remove the constraint if the underlying model is type hinted to `\DateTimeInterface` already.
|