1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2017 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2017 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\EventListener; |
18
|
|
|
|
19
|
|
|
use Doctrine\Common\EventSubscriber; |
20
|
|
|
use Doctrine\ORM\Event\LifecycleEventArgs; |
21
|
|
|
use Doctrine\ORM\Events; |
22
|
|
|
use SWP\Bundle\ContentBundle\ArticleEvents; |
23
|
|
|
use SWP\Bundle\ContentBundle\Event\ArticleEvent; |
24
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
25
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
26
|
|
|
|
27
|
|
|
final class ArticleSubscriber implements EventSubscriber |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var EventDispatcherInterface |
31
|
|
|
*/ |
32
|
|
|
protected $eventDispatcher; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* TenantSubscriber constructor. |
36
|
|
|
* |
37
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
38
|
|
|
*/ |
39
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher) |
40
|
|
|
{ |
41
|
|
|
$this->eventDispatcher = $eventDispatcher; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function getSubscribedEvents() |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
Events::postPersist, |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param LifecycleEventArgs $args |
56
|
|
|
*/ |
57
|
|
|
public function postPersist(LifecycleEventArgs $args) |
58
|
|
|
{ |
59
|
|
|
$entity = $args->getEntity(); |
60
|
|
|
|
61
|
|
|
if ($entity instanceof ArticleInterface) { |
62
|
|
|
$this->eventDispatcher->dispatch(ArticleEvents::POST_CREATE, new ArticleEvent($entity)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|