-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[EventDispatcher] Added EventTrait #21827
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,34 +25,7 @@ | |
* @author Roman Borschel <[email protected]> | ||
* @author Bernhard Schussek <[email protected]> | ||
*/ | ||
class Event | ||
class Event implements EventInterface | ||
{ | ||
/** | ||
* @var bool Whether no further event listeners should be triggered | ||
*/ | ||
private $propagationStopped = false; | ||
|
||
/** | ||
* Returns whether further event listeners should be triggered. | ||
* | ||
* @see Event::stopPropagation() | ||
* | ||
* @return bool Whether propagation was already stopped for this event | ||
*/ | ||
public function isPropagationStopped() | ||
{ | ||
return $this->propagationStopped; | ||
} | ||
|
||
/** | ||
* Stops the propagation of the event to further event listeners. | ||
* | ||
* If multiple event listeners are connected to the same event, no | ||
* further event listener will be triggered once any trigger calls | ||
* stopPropagation(). | ||
*/ | ||
public function stopPropagation() | ||
{ | ||
$this->propagationStopped = true; | ||
} | ||
use EventTrait; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\EventDispatcher; | ||
|
||
|
||
interface EventInterface | ||
{ | ||
/** | ||
* Returns whether further event listeners should be triggered. | ||
* | ||
* @see EventInterface::stopPropagation() | ||
* | ||
* @return bool Whether propagation was already stopped for this event | ||
*/ | ||
public function isPropagationStopped(); | ||
|
||
/** | ||
* Stops the propagation of the event to further event listeners. | ||
* | ||
* If multiple event listeners are connected to the same event, no | ||
* further event listener will be triggered once any trigger calls | ||
* stopPropagation(). | ||
*/ | ||
public function stopPropagation(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\EventDispatcher; | ||
|
||
|
||
trait EventTrait | ||
{ | ||
/** | ||
* @var bool Whether no further event listeners should be triggered | ||
*/ | ||
private $propagationStopped = false; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isPropagationStopped() | ||
{ | ||
return $this->propagationStopped; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function stopPropagation() | ||
{ | ||
$this->propagationStopped = true; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gadelat In fact, changing the type hint here is a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? Users pass the event class here, which implements this interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every class implementing this interface must be updated too (see the fatal error you will get otherwise: https://3v4l.org/CQgFB).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true :( Are the downvotes then only because of this BC, or is there something else? Would you be more keen to merge this at least in 4.0?