|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the BenGorFile package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace BenGorFile\DoctrineORMBridge\Infrastructure\Persistence; |
|
14
|
|
|
|
|
15
|
|
|
use BenGorFile\File\Domain\Model\File; |
|
16
|
|
|
use BenGorFile\File\Domain\Model\FileId; |
|
17
|
|
|
use BenGorFile\File\Domain\Model\FileRepository; |
|
18
|
|
|
use Doctrine\ORM\EntityRepository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Doctrine ORM file repository class. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Beñat Espiña <[email protected]> |
|
24
|
|
|
* @author Gorka Laucirica <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class DoctrineORMFileRepository extends EntityRepository implements FileRepository |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function fileOfId(FileId $anId) |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->find($anId->id()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function query($aSpecification) |
|
40
|
|
|
{ |
|
41
|
|
|
return null === $aSpecification |
|
42
|
|
|
? $this->findAll() |
|
43
|
|
|
: $aSpecification->buildQuery($this->createQueryBuilder('f'))->getResult(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function singleResultQuery($aSpecification) |
|
50
|
|
|
{ |
|
51
|
|
|
return $aSpecification->buildQuery($this->getEntityManager()->createQueryBuilder())->getOneOrNullResult(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function length($aSpecification) |
|
58
|
|
|
{ |
|
59
|
|
|
if (null === $aSpecification) { |
|
60
|
|
|
$queryBuilder = $this->getEntityManager()->createQueryBuilder(); |
|
61
|
|
|
|
|
62
|
|
|
return (int) $queryBuilder |
|
63
|
|
|
->select($queryBuilder->expr()->count('f.id')) |
|
64
|
|
|
->getQuery() |
|
65
|
|
|
->getSingleScalarResult(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return (int) $aSpecification->buildCount( |
|
69
|
|
|
$this->createQueryBuilder('f') |
|
70
|
|
|
)->getSingleScalarResult(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function persist(File $aFile) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->getEntityManager()->persist($aFile); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritdoc} |
|
83
|
|
|
*/ |
|
84
|
|
|
public function remove(File $aFile) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->getEntityManager()->remove($aFile); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|