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