Skip to content

Commit 8afe1fd

Browse files
committed
added bc layer for new event dispatcher interface
1 parent 6b18b0c commit 8afe1fd

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ dist: trusty
55
sudo: false
66

77
php:
8-
- 7.2
9-
- 7.3
8+
- '7.2'
9+
- '7.3'
1010

1111
cache:
1212
yarn: true

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ parameters:
1919

2020
ignoreErrors:
2121
- '/Parameter #1 $configuration of method Symfony\Component\DependencyInjection\Extension\Extension::processConfiguration() expects Symfony\Component\Config\Definition\ConfigurationInterface, Symfony\Component\Config\Definition\ConfigurationInterface|null given./'
22+
- '/Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface\:\:dispatch\(\) invoked with 2 parameters, 1 required\./'
23+
- '/Parameter \#1 \$event of method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface\:\:dispatch\(\) expects object, string given\./'

src/EventListener/AddToCartSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public function track(): void
7575
->setItemPrice($this->moneyFormatter->format($item->getDiscountedUnitPrice()))
7676
;
7777

78-
$this->eventDispatcher->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $item));
78+
$this->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $item));
7979

8080
$builder->addContent($contentBuilder);
8181
}
8282

83-
$this->eventDispatcher->dispatch(AddToCartBuilder::EVENT_NAME, new BuilderEvent($builder, $order));
83+
$this->dispatch(AddToCartBuilder::EVENT_NAME, new BuilderEvent($builder, $order));
8484

8585
$this->tagBag->add(new FbqTag(
8686
Tags::TAG_ADD_TO_CART,

src/EventListener/PurchaseSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function track(ResourceControllerEvent $event): void
5656
->setQuantity($orderItem->getQuantity())
5757
;
5858

59-
$this->eventDispatcher->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $orderItem));
59+
$this->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $orderItem));
6060

6161
$builder->addContent($contentBuilder);
6262
}
6363

64-
$this->eventDispatcher->dispatch(PurchaseBuilder::EVENT_NAME, new BuilderEvent($builder, $order));
64+
$this->dispatch(PurchaseBuilder::EVENT_NAME, new BuilderEvent($builder, $order));
6565

6666
$this->tagBag->add(new FbqTag(
6767
Tags::TAG_PURCHASE,

src/EventListener/TagSubscriber.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Setono\TagBagBundle\TagBag\TagBagInterface;
1111
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1212
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1314

1415
abstract class TagSubscriber implements EventSubscriberInterface
1516
{
@@ -31,7 +32,7 @@ abstract class TagSubscriber implements EventSubscriberInterface
3132
/**
3233
* @var EventDispatcherInterface
3334
*/
34-
protected $eventDispatcher;
35+
private $eventDispatcher;
3536

3637
/**
3738
* @var MoneyFormatter
@@ -40,6 +41,15 @@ abstract class TagSubscriber implements EventSubscriberInterface
4041

4142
public function __construct(TagBagInterface $tagBag, PixelContextInterface $pixelContext, EventDispatcherInterface $eventDispatcher)
4243
{
44+
if (class_exists(LegacyEventDispatcherProxy::class)) {
45+
/**
46+
* It could return null only if we pass null, but we pass not null in any case
47+
*
48+
* @var EventDispatcherInterface
49+
*/
50+
$eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
51+
}
52+
4353
$this->tagBag = $tagBag;
4454
$this->pixelContext = $pixelContext;
4555
$this->eventDispatcher = $eventDispatcher;
@@ -59,4 +69,13 @@ protected function getPixels(): array
5969

6070
return $this->pixels;
6171
}
72+
73+
protected function dispatch(string $eventName, $event): void
74+
{
75+
if (class_exists(LegacyEventDispatcherProxy::class)) {
76+
$this->eventDispatcher->dispatch($event, $eventName);
77+
} else {
78+
$this->eventDispatcher->dispatch($eventName, $event);
79+
}
80+
}
6281
}

src/EventListener/ViewContentSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public function track(ResourceControllerEvent $event): void
4747
->setQuantity(1)
4848
;
4949

50-
$this->eventDispatcher->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $product));
50+
$this->dispatch(ContentBuilder::EVENT_NAME, new BuilderEvent($contentBuilder, $product));
5151

5252
$builder->addContent($contentBuilder);
5353

54-
$this->eventDispatcher->dispatch(ViewContentBuilder::EVENT_NAME, new BuilderEvent($builder, $product));
54+
$this->dispatch(ViewContentBuilder::EVENT_NAME, new BuilderEvent($builder, $product));
5555

5656
$this->tagBag->add(new FbqTag(
5757
Tags::TAG_VIEW_CONTENT,

0 commit comments

Comments
 (0)