RemoveAliasSubscriber::preRemove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 2
eloc 3
c 3
b 1
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\Aliasing\Doctrine;
8
9
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
10
use Doctrine\ORM\Events;
11
12
/**
13
 * Remove an alias from the aliases
14
 */
15
class RemoveAliasSubscriber extends BaseSubscriber
16
{
17
    /**
18
     * @{inheritDoc}
19
     */
20
    public function getSubscribedEvents()
21
    {
22
        return array(
23
            Events::preRemove,
24
            Events::postFlush
25
        );
26
    }
27
28
29
    /**
30
     * Schedule an object's alias to be deleted.
31
     *
32
     * @param LifecycleEventArgs $e
33
     * @return void
34
     */
35
    public function preRemove($e)
36
    {
37
        $entity = $e->getObject();
38
39
        if ($entity instanceof $this->className) {
40
            // schedule alias removal (this needs to be done before the entity is removed and loses its id)
41
            $this->container->get($this->aliaserServiceId)->removeAlias($entity, true);
42
        }
43
    }
44
45
46
    /**
47
     * Remove the aliases for all removed records.
48
     *
49
     * @return void
50
     */
51
    public function postFlush()
52
    {
53
        $this->container->get($this->aliaserServiceId)->removeScheduledAliases();
54
    }
55
}
56