This commit is contained in:
aynsix
2019-09-26 18:05:03 +04:00
parent 5fc4d85aef
commit 56c44a1b3f
2 changed files with 16 additions and 17 deletions

View File

@@ -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

View File

@@ -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;
})
);
}
}