-
Notifications
You must be signed in to change notification settings - Fork 4
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 #54 from kiy0taka/next/dev/event-dispatcher
Symfony/EventDispatcher
- Loading branch information
Showing
10 changed files
with
170 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.ec-cube.co.jp/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eccube\EventDispatcher; | ||
|
||
class Event | ||
{ | ||
private object $event; | ||
|
||
public function __construct(object $event) | ||
{ | ||
$this->event = $event; | ||
} | ||
|
||
/** | ||
* @return object | ||
*/ | ||
public function getEvent(): object | ||
{ | ||
return $this->event; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.ec-cube.co.jp/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eccube\EventDispatcher; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
class EventDispatcher | ||
{ | ||
private EventDispatcherInterface $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public function dispatch(object $event, string $eventName = null): object | ||
{ | ||
return $this->eventDispatcher->dispatch($event, $eventName); | ||
} | ||
|
||
public function addListener(string $eventName, $listener, int $priority = 0): void | ||
{ | ||
$this->eventDispatcher->addListener($eventName, $listener, $priority); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/framework/Eccube/EventDispatcher/EventDispatcherDecorator.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,36 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.ec-cube.co.jp/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eccube\EventDispatcher; | ||
|
||
use Psr\EventDispatcher\StoppableEventInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class EventDispatcherDecorator extends EventDispatcher | ||
{ | ||
protected function callListeners(iterable $listeners, string $eventName, object $event) | ||
{ | ||
$stoppable = $event instanceof StoppableEventInterface; | ||
|
||
foreach ($listeners as $listener) { | ||
if ($stoppable && $event->isPropagationStopped()) { | ||
break; | ||
} | ||
if (is_array($listener) && $listener[0] instanceof EventSubscriberInterface) { | ||
$listener(new Event($event), $eventName, $this); | ||
continue; | ||
} | ||
$listener($event, $eventName, $this); | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/framework/Eccube/EventDispatcher/EventSubscriberInterface.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,18 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.ec-cube.co.jp/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eccube\EventDispatcher; | ||
|
||
interface EventSubscriberInterface extends \Symfony\Component\EventDispatcher\EventSubscriberInterface | ||
{ | ||
|
||
} |
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,27 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.ec-cube.co.jp/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eccube; | ||
|
||
use Symfony\Component\HttpKernel\KernelEvents as SymfonyKernelEvents; | ||
|
||
class KernelEvents | ||
{ | ||
public const REQUEST = SymfonyKernelEvents::REQUEST; | ||
public const EXCEPTION = SymfonyKernelEvents::EXCEPTION; | ||
public const CONTROLLER = SymfonyKernelEvents::CONTROLLER; | ||
public const CONTROLLER_ARGUMENTS = SymfonyKernelEvents::CONTROLLER_ARGUMENTS; | ||
public const VIEW = SymfonyKernelEvents::VIEW; | ||
public const RESPONSE = SymfonyKernelEvents::RESPONSE; | ||
public const FINISH_REQUEST = SymfonyKernelEvents::FINISH_REQUEST; | ||
public const TERMINATE = SymfonyKernelEvents::TERMINATE; | ||
} |