Skip to content

Commit

Permalink
fix `Calling the "Symfony\Component\EventDispatcher\EventDispatcherIn…
Browse files Browse the repository at this point in the history
…terface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3`
  • Loading branch information
kiy0taka committed Sep 14, 2021
1 parent eb75f5c commit 9cb95d7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ services:
$orderPurchaseFlow: '@eccube.purchase.flow.order'
$_orderStateMachine: '@state_machine.order'

event_dispatcher:
class: Eccube\Event\EventDispatcherWrapper
public: true

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
35 changes: 35 additions & 0 deletions src/Eccube/Event/EventDispatcherWrapper.php
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\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;

class EventDispatcherWrapper extends EventDispatcher
{
public function dispatch($event)
{
$eventName = 1 < \func_num_args() ? func_get_arg(1) : null;

if (\is_object($event)) {
$eventName = $eventName ?? \get_class($event);
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof \Symfony\Contracts\EventDispatcher\Event || $eventName instanceof Event)) {
$swap = $event;
$event = $eventName ?? new Event();
$eventName = $swap;
}

return parent::dispatch($event, $eventName);
}

}

0 comments on commit 9cb95d7

Please sign in to comment.