RedirectRouteManager::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tadcka\Bundle\RoutingBundle\Doctrine\EntityManager;
13
14
use Doctrine\ORM\EntityManager;
15
use Doctrine\ORM\EntityRepository;
16
use Tadcka\Component\Routing\Model\Manager\RedirectRouteManager as BaseRedirectRouteManager;
17
use Tadcka\Component\Routing\Model\RedirectRouteInterface;
18
19
/**
20
 * @author Tadas Gliaubicas <[email protected]>
21
 *
22
 * @since 8/28/14 2:31 PM
23
 */
24
class RedirectRouteManager extends BaseRedirectRouteManager
25
{
26
    /**
27
     * @var EntityManager
28
     */
29
    protected $em;
30
31
    /**
32
     * @var EntityRepository
33
     */
34
    protected $repository;
35
36
    /**
37
     * @var string
38
     */
39
    protected $class;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param EntityManager $em
45
     * @param string $class
46
     */
47
    public function __construct(EntityManager $em, $class)
48
    {
49
        $this->em = $em;
50
        $this->repository = $em->getRepository($class);
51
        $this->class = $em->getClassMetadata($class)->name;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function findByName($name)
58
    {
59
        return $this->repository->findOneBy(array('name' => $name));
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function add(RedirectRouteInterface $redirectRoute, $save = false)
66
    {
67
        $this->em->persist($redirectRoute);
68
        if (true === $save) {
69
            $this->save();
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function remove(RedirectRouteInterface $redirectRoute, $save = false)
77
    {
78
        $this->em->remove($redirectRoute);
79
        if (true === $save) {
80
            $this->save();
81
        }
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function save()
88
    {
89
        $this->em->flush();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function clear()
96
    {
97
        $this->em->clear($this->getClass());
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function getClass()
104
    {
105
        return $this->class;
106
    }
107
}
108