Completed
Push — master ( 3ef484...ea5778 )
by Paweł
08:46
created

ArticleSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A postPersist() 0 8 2
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