diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookSubdefEventSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookSubdefEventSubscriber.php index d3c06cdd72..ca5d88b2ab 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookSubdefEventSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookSubdefEventSubscriber.php @@ -7,19 +7,16 @@ use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreatedEvent; use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationFailedEvent; use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreatedEvent; use Alchemy\Phrasea\Model\Entities\WebhookEvent; -use Alchemy\Phrasea\Model\Manipulator\WebhookEventManipulator; +use Silex\Application; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class WebhookSubdefEventSubscriber implements EventSubscriberInterface { - /** - * @var WebhookEventManipulator - */ - private $webhookManipulator; + private $app; - public function __construct(WebhookEventManipulator $manipulator) + public function __construct(Application $app) { - $this->webhookManipulator = $manipulator; + $this->app = $app; } public function onSubdefCreated(SubDefinitionCreatedEvent $event) @@ -30,7 +27,7 @@ class WebhookSubdefEventSubscriber implements EventSubscriberInterface 'subdef' => $event->getSubDefinitionName() ]; - $this->webhookManipulator->create( + $this->app['manipulator.webhook-event']->create( WebhookEvent::RECORD_SUBDEF_CREATED, WebhookEvent::RECORD_SUBDEF_TYPE, $eventData @@ -45,7 +42,7 @@ class WebhookSubdefEventSubscriber implements EventSubscriberInterface 'subdef' => $event->getSubDefinitionName() ]; - $this->webhookManipulator->create( + $this->app['manipulator.webhook-event']->create( WebhookEvent::RECORD_SUBDEF_FAILED, WebhookEvent::RECORD_SUBDEF_TYPE, $eventData @@ -60,7 +57,7 @@ class WebhookSubdefEventSubscriber implements EventSubscriberInterface 'subdef_count' => count($event->getMedia()) ]; - $this->webhookManipulator->create( + $this->app['manipulator.webhook-event']->create( WebhookEvent::RECORD_SUBDEFS_CREATED, WebhookEvent::RECORD_SUBDEF_TYPE, $eventData diff --git a/lib/Alchemy/Phrasea/Core/Provider/WebhookServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/WebhookServiceProvider.php index 968ec607e1..43a5aeafa4 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/WebhookServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/WebhookServiceProvider.php @@ -11,7 +11,7 @@ use Alchemy\Worker\CallableWorkerFactory; use Alchemy\Worker\TypeBasedWorkerResolver; use Silex\Application; use Silex\ServiceProviderInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; class WebhookServiceProvider implements ServiceProviderInterface { @@ -60,6 +60,14 @@ class WebhookServiceProvider implements ServiceProviderInterface return $resolver; } ); + + $app['dispatcher'] = $app->share( + $app->extend('dispatcher', function (EventDispatcher $dispatcher, Application $app) { + $dispatcher->addSubscriber(new WebhookSubdefEventSubscriber($app)); + + return $dispatcher; + }) + ); } private function createAlias(Application $app, $alias, $targetServiceKey) @@ -71,12 +79,6 @@ class WebhookServiceProvider implements ServiceProviderInterface public function boot(Application $app) { - $app['dispatcher'] = $app->share( - $app->extend('dispatcher', function (EventDispatcherInterface $dispatcher) use ($app) { - $dispatcher->addSubscriber(new WebhookSubdefEventSubscriber($app['manipulator.webhook-event'])); - return $dispatcher; - }) - ); } }