-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EventDispatcher] Adding a few new things and working on docs (#202)
## Description ## Checklist - [x] Updated CHANGELOG files - [x] Updated Documentation - [x] Unit Tests Created - [x] php-cs-fixer
- Loading branch information
1 parent
b24d817
commit 9cd723e
Showing
11 changed files
with
259 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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
15 changes: 15 additions & 0 deletions
15
src/SonsOfPHP/Component/EventDispatcher/AbstractStoppableEvent.php
This file contains 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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\EventDispatcher; | ||
|
||
use Psr\EventDispatcher\StoppableEventInterface; | ||
|
||
/** | ||
* @author Joshua Estes <joshua@sonsofphp.com> | ||
*/ | ||
abstract class AbstractStoppableEvent implements StoppableEventInterface | ||
{ | ||
use StoppableEventTrait; | ||
} |
This file contains 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 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
10 changes: 0 additions & 10 deletions
10
src/SonsOfPHP/Component/EventDispatcher/ListenerInterface.php
This file was deleted.
Oops, something went wrong.
This file contains 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
26 changes: 26 additions & 0 deletions
26
src/SonsOfPHP/Component/EventDispatcher/StoppableEventTrait.php
This file contains 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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\EventDispatcher; | ||
|
||
/** | ||
* @author Joshua Estes <joshua@sonsofphp.com> | ||
*/ | ||
trait StoppableEventTrait | ||
{ | ||
private bool $isStopped = false; | ||
|
||
public function isPropagationStopped(): bool | ||
{ | ||
return $this->isStopped; | ||
} | ||
|
||
/** | ||
* Makes `isPropagationStopped` return true | ||
*/ | ||
public function stopPropagation(): void | ||
{ | ||
$this->isStopped = true; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/SonsOfPHP/Component/EventDispatcher/Tests/AbstractStoppableEventTest.php
This file contains 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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\EventDispatcher\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psr\EventDispatcher\StoppableEventInterface; | ||
use SonsOfPHP\Component\EventDispatcher\AbstractStoppableEvent; | ||
|
||
/** | ||
* @coversDefaultClass \SonsOfPHP\Component\EventDispatcher\AbstractStoppableEvent | ||
* | ||
* @uses \SonsOfPHP\Component\EventDispatcher\AbstractStoppableEvent | ||
*/ | ||
final class AbstractStoppableEventTest extends TestCase | ||
{ | ||
/** | ||
* @coversNothing | ||
*/ | ||
public function testItHasTheCorrectInterface(): void | ||
{ | ||
$event = new class () extends AbstractStoppableEvent {}; | ||
|
||
$this->assertInstanceOf(StoppableEventInterface::class, $event); | ||
} | ||
|
||
/** | ||
* @covers ::isPropagationStopped | ||
* @covers ::stopPropagation | ||
*/ | ||
public function testItCanStopPropagation(): void | ||
{ | ||
$event = new class () extends AbstractStoppableEvent {}; | ||
$this->assertFalse($event->isPropagationStopped()); | ||
|
||
$event->stopPropagation(); | ||
$this->assertTrue($event->isPropagationStopped()); | ||
} | ||
} |
This file contains 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