feature #33152 Mark all dispatched event classes as final (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

Mark all dispatched event classes as final

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

I think we should mark all our Event classes as final. There is no point in people extending them as the libraries that use the event, will only dispatch this event. So extending events in user-land achieves nothing as the subclasses won't be dispatched.
I'm not talking about the base events that are meant to be extended like KernelEvent, but the leaf events like ExceptionEvent, ResponseEvent etc.
Then we can also make them real final in 5.0 as the events are value objects that should not be mocked.

Commits
-------

4bb38eec89 Mark all dispatched event classes as final
This commit is contained in:
Nicolas Grekas 2019-08-21 17:50:31 +02:00
commit f2e2df6a0c
40 changed files with 77 additions and 7 deletions

View File

@ -7,6 +7,7 @@ CHANGELOG
* added `Question::setTrimmable` default to true to allow the answer to be trimmed
* added method `preventRedrawFasterThan()` and `forceRedrawSlowerThan()` on `ProgressBar`
* `Application` implements `ResetInterface`
* marked all dispatched event classes as `@final`
4.3.0
-----

View File

@ -15,6 +15,8 @@ namespace Symfony\Component\Console\Event;
* Allows to do things before the command is executed, like skipping the command or changing the input.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class ConsoleCommandEvent extends ConsoleEvent
{

View File

@ -19,6 +19,8 @@ use Symfony\Component\Console\Output\OutputInterface;
* Allows to manipulate the exit code of a command after its execution.
*
* @author Francesco Levorato <git@flevour.net>
*
* @final since Symfony 4.4
*/
class ConsoleTerminateEvent extends ConsoleEvent
{

View File

@ -10,6 +10,7 @@ CHANGELOG
* deprecated using `int` or `float` as data for the `NumberType` when the `input` option is set to `string`
* The type guesser guesses the HTML accept attribute when a mime type is configured in the File or Image constraint.
* Overriding the methods `FormIntegrationTestCase::setUp()`, `TypeTestCase::setUp()` and `TypeTestCase::tearDown()` without the `void` return-type is deprecated.
* marked all dispatched event classes as `@final`
4.3.0
-----

View File

@ -17,6 +17,8 @@ use Symfony\Component\Form\FormEvent;
* This event is dispatched at the end of the Form::setData() method.
*
* This event is mostly here for reading data after having pre-populated the form.
*
* @final since Symfony 4.4
*/
class PostSetDataEvent extends FormEvent
{

View File

@ -18,6 +18,8 @@ use Symfony\Component\Form\FormEvent;
* once the model and view data have been denormalized.
*
* It can be used to fetch data after denormalization.
*
* @final since Symfony 4.4
*/
class PostSubmitEvent extends FormEvent
{

View File

@ -19,6 +19,8 @@ use Symfony\Component\Form\FormEvent;
* It can be used to:
* - Modify the data given during pre-population;
* - Modify a form depending on the pre-populated data (adding or removing fields dynamically).
*
* @final since Symfony 4.4
*/
class PreSetDataEvent extends FormEvent
{

View File

@ -19,6 +19,8 @@ use Symfony\Component\Form\FormEvent;
* It can be used to:
* - Change data from the request, before submitting the data to the form.
* - Add or remove form fields, before submitting the data to the form.
*
* @final since Symfony 4.4
*/
class PreSubmitEvent extends FormEvent
{

View File

@ -18,6 +18,8 @@ use Symfony\Component\Form\FormEvent;
* transforms back the normalized data to the model and view data.
*
* It can be used to change data from the normalized representation of the data.
*
* @final since Symfony 4.4
*/
class SubmitEvent extends FormEvent
{

View File

@ -12,6 +12,7 @@ CHANGELOG
fallback directories. Resources like service definitions are usually loaded relative to the
current directory or with a glob pattern. The fallback directories have never been advocated
so you likely do not use those in any app based on the SF Standard or Flex edition.
* Marked all dispatched event classes as `@final`
4.3.0
-----

View File

@ -22,6 +22,8 @@ namespace Symfony\Component\HttpKernel\Event;
* controller.
*
* @author Christophe Coevoet <stof@notk.org>
*
* @final since Symfony 4.4
*/
class ControllerArgumentsEvent extends FilterControllerArgumentsEvent
{

View File

@ -21,6 +21,8 @@ namespace Symfony\Component\HttpKernel\Event;
* Controllers should be callables.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
*/
class ControllerEvent extends FilterControllerEvent
{

View File

@ -23,6 +23,8 @@ namespace Symfony\Component\HttpKernel\Event;
* event.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
*/
class ExceptionEvent extends GetResponseForExceptionEvent
{

View File

@ -15,6 +15,8 @@ namespace Symfony\Component\HttpKernel\Event;
* Triggered whenever a request is fully processed.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*
* @final since Symfony 4.4
*/
class FinishRequestEvent extends KernelEvent
{

View File

@ -19,6 +19,8 @@ namespace Symfony\Component\HttpKernel\Event;
* browser.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
*/
class ResponseEvent extends FilterResponseEvent
{

View File

@ -18,6 +18,8 @@ namespace Symfony\Component\HttpKernel\Event;
* will always return the value of `HttpKernelInterface::MASTER_REQUEST`.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*
* @final since Symfony 4.4
*/
class TerminateEvent extends PostResponseEvent
{

View File

@ -19,6 +19,8 @@ namespace Symfony\Component\HttpKernel\Event;
* response is set.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
*/
class ViewEvent extends GetResponseForControllerResultEvent
{

View File

@ -19,6 +19,7 @@ CHANGELOG
`Symfony\Component\Mailer\Transport\TransportFactoryInterface` and tagging with `mailer.transport_factory` tag in DI.
* Added `Symfony\Component\Mailer\Test\TransportFactoryTestCase` to ease testing custom transport factories.
* Added `SentMessage::getDebug()` and `TransportExceptionInterface::getDebug` to help debugging
* Made `MessageEvent` final
4.3.0
-----

View File

@ -20,7 +20,7 @@ use Symfony\Component\Mime\RawMessage;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class MessageEvent extends Event
final class MessageEvent extends Event
{
private $message;
private $envelope;

View File

@ -8,6 +8,7 @@ CHANGELOG
pass a `RoutableMessageBus` instance instead.
* Added support for auto trimming of Redis streams.
* `InMemoryTransport` handle acknowledged and rejected messages.
* Made all dispatched worker event classes final.
4.3.0
-----

View File

@ -24,7 +24,7 @@ use Symfony\Component\Messenger\Envelope;
*
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
class SendMessageToTransportsEvent
final class SendMessageToTransportsEvent
{
private $envelope;

View File

@ -18,7 +18,7 @@ use Symfony\Component\Messenger\Envelope;
*
* The event name is the class name.
*/
class WorkerMessageFailedEvent extends AbstractWorkerMessageEvent
final class WorkerMessageFailedEvent extends AbstractWorkerMessageEvent
{
private $throwable;
private $willRetry;

View File

@ -16,6 +16,6 @@ namespace Symfony\Component\Messenger\Event;
*
* The event name is the class name.
*/
class WorkerMessageHandledEvent extends AbstractWorkerMessageEvent
final class WorkerMessageHandledEvent extends AbstractWorkerMessageEvent
{
}

View File

@ -16,7 +16,7 @@ namespace Symfony\Component\Messenger\Event;
*
* The event name is the class name.
*/
class WorkerMessageReceivedEvent extends AbstractWorkerMessageEvent
final class WorkerMessageReceivedEvent extends AbstractWorkerMessageEvent
{
private $shouldHandle = true;

View File

@ -16,6 +16,6 @@ namespace Symfony\Component\Messenger\Event;
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class WorkerStoppedEvent
final class WorkerStoppedEvent
{
}

View File

@ -10,6 +10,7 @@ CHANGELOG
* Added and implemented `PasswordUpgraderInterface`, for opportunistic password migrations
* Added `Guard\PasswordAuthenticatedInterface`, an optional interface
for "guard" authenticators that deal with user passwords
* Marked all dispatched event classes as `@final`
4.3.0
-----

View File

@ -18,6 +18,8 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException;
* This event is dispatched on authentication failure.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @final since Symfony 4.4
*/
class AuthenticationFailureEvent extends AuthenticationEvent
{

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Security\Core\Event;
/**
* @final since Symfony 4.4
*/
class AuthenticationSuccessEvent extends AuthenticationEvent
{
}

View File

@ -21,7 +21,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
*
* @internal
*/
class VoteEvent extends Event
final class VoteEvent extends Event
{
private $voter;
private $subject;

View File

@ -18,6 +18,8 @@ use Symfony\Contracts\EventDispatcher\Event;
* Deauthentication happens in case the user has changed when trying to refresh the token.
*
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
*
* @final since Symfony 4.4
*/
class DeauthenticatedEvent extends Event
{

View File

@ -17,6 +17,8 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class InteractiveLoginEvent extends Event
{

View File

@ -20,6 +20,8 @@ use Symfony\Component\Security\Core\User\UserInterface;
* SwitchUserEvent.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class SwitchUserEvent extends Event
{

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.4.0
-----
* Marked all dispatched event classes as `@final`
4.3.0
-----

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class AnnounceEvent extends Event
{
}

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class CompletedEvent extends Event
{
}

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class EnterEvent extends Event
{
}

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class EnteredEvent extends Event
{
}

View File

@ -19,6 +19,8 @@ use Symfony\Component\Workflow\TransitionBlockerList;
/**
* @author Fabien Potencier <fabien@symfony.com>
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final since Symfony 4.4
*/
class GuardEvent extends Event
{

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class LeaveEvent extends Event
{
}

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Workflow\Event;
/**
* @final since Symfony 4.4
*/
class TransitionEvent extends Event
{
private $context;