-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from tienvx/dispatch-subject-init-event
Dispatch subject init event
- Loading branch information
Showing
28 changed files
with
298 additions
and
256 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
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
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,36 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Entity; | ||
|
||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait TimestampableTrait | ||
{ | ||
/** | ||
* @ORM\Column(name="created_at", type="datetime", nullable=true) | ||
*/ | ||
protected $createdAt; | ||
|
||
/** | ||
* @ORM\Column(name="updated_at", type="datetime", nullable=true) | ||
*/ | ||
protected $updatedAt; | ||
|
||
/** | ||
* @ORM\PrePersist | ||
*/ | ||
public function prePersist(): void | ||
{ | ||
$this->createdAt = new DateTime(); | ||
$this->updatedAt = new DateTime(); | ||
} | ||
|
||
/** | ||
* @ORM\PreUpdate | ||
*/ | ||
public function preUpdate(): void | ||
{ | ||
$this->updatedAt = new DateTime(); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Event; | ||
|
||
use Symfony\Contracts\EventDispatcher\Event; | ||
use Tienvx\Bundle\MbtBundle\Model\SubjectInterface; | ||
|
||
class SubjectInitEvent extends Event | ||
{ | ||
public const NAME = 'mbtbundle.subject.init'; | ||
|
||
/** | ||
* @var SubjectInterface | ||
*/ | ||
protected $subject; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $trying; | ||
|
||
public function __construct(SubjectInterface $subject, bool $trying = false) | ||
{ | ||
$this->subject = $subject; | ||
$this->trying = $trying; | ||
} | ||
|
||
public function getSubject(): SubjectInterface | ||
{ | ||
return $this->subject; | ||
} | ||
|
||
public function isTrying(): bool | ||
{ | ||
return $this->trying; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Tienvx\Bundle\MbtBundle\Event\SubjectInitEvent; | ||
use Tienvx\Bundle\MbtBundle\Model\Subject\SetUpInterface; | ||
|
||
class SubjectSubscriber implements EventSubscriberInterface | ||
{ | ||
public function onInit(SubjectInitEvent $event): void | ||
{ | ||
if ($event->getSubject() instanceof SetUpInterface) { | ||
$event->getSubject()->setUp($event->isTrying()); | ||
} | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
SubjectInitEvent::class => 'onInit', | ||
]; | ||
} | ||
} |
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
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
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
Oops, something went wrong.