1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Black\Page\Infrastructure\Persistence; |
4
|
|
|
|
5
|
|
|
use Black\Bridge\Doctrine\Common\Persistence\ORMRepository; |
6
|
|
|
use Black\Page\Domain\Model\WebPage; |
7
|
|
|
use Black\Page\Domain\Model\WebPageId; |
8
|
|
|
use Black\Page\Domain\Model\WebPageRepository; |
9
|
|
|
use Doctrine\ORM\NoResultException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DoctrineORMRepository |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
class DoctrineORMRepository extends ORMRepository implements WebPageRepository |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param mixed $id |
18
|
|
|
* @return mixed |
19
|
|
|
* @throws \Doctrine\ORM\NoResultException |
20
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
21
|
|
|
*/ |
22
|
|
|
public function find(WebPageId $id) |
23
|
|
|
{ |
24
|
|
|
$query = $this->getQueryBuilder() |
25
|
|
|
->where('p.webPageId.value = :id') |
26
|
|
|
->setParameter('id', $id->getValue()) |
27
|
|
|
->getQuery(); |
28
|
|
|
|
29
|
|
|
try { |
30
|
|
|
return $query->getSingleResult(); |
31
|
|
|
} catch (NoResultException $exception) { |
|
|
|
|
32
|
|
|
return null; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $slug |
38
|
|
|
* @return mixed|null |
39
|
|
|
*/ |
40
|
|
|
public function findBySlug($slug) |
41
|
|
|
{ |
42
|
|
|
$query = $this->getQueryBuilder() |
43
|
|
|
->where('p.slug = :slug') |
44
|
|
|
->setParameter('slug', $slug) |
45
|
|
|
->getQuery(); |
46
|
|
|
|
47
|
|
|
try { |
48
|
|
|
return $query->getSingleResult(); |
49
|
|
|
} catch (NoResultException $exception) { |
|
|
|
|
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function findAll() |
58
|
|
|
{ |
59
|
|
|
return $this->getQueryBuilder()->getQuery()->execute(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param WebPage $webpage |
64
|
|
|
*/ |
65
|
|
|
public function add(WebPage $webpage) |
66
|
|
|
{ |
67
|
|
|
$this->manager->persist($webpage); |
68
|
|
|
$this->update($webpage); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param WebPage $webpage |
73
|
|
|
*/ |
74
|
|
|
public function remove(WebPage $webpage) |
75
|
|
|
{ |
76
|
|
|
$this->manager->remove($webpage); |
77
|
|
|
$this->update($webpage); |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function update(WebPage $webpage) |
82
|
|
|
{ |
83
|
|
|
$this->manager->flush(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|