Repository navigation
Expand file tree
/
Copy pathEngineRepository.php
More file actions
86 lines (76 loc) · 2.27 KB
/
Copy pathEngineRepository.php
File metadata and controls
86 lines (76 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace SyncEngine\Repository\Abstract;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use SyncEngine\Entity\Abstract\EngineEntity;
use SyncEngine\Repository\Interface\Searchable;
use SyncEngine\Repository\Trait\Search;
use SyncEngine\Repository\Trait\Supervisor;
/**
* @template T of EngineEntity
*
* @extends ServiceEntityRepository<T>
*
* @method EngineEntity|null find( $id, $lockMode = null, $lockVersion = null )
* @method EngineEntity|null findOneBy( array $criteria, array $orderBy = null )
* @method EngineEntity[] findAll()
* @method EngineEntity[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
*/
abstract class EngineRepository extends ServiceEntityRepository implements Searchable
{
use Search;
use Supervisor;
/**
* @param T $entity
*/
public function save( EngineEntity $entity, bool $flush = false ): void
{
$this->getEntityManager()->persist( $entity );
if ( $flush ) {
$this->getEntityManager()->flush();
}
}
/**
* @param T $entity
*/
public function remove( EngineEntity $entity, bool $flush = false ): void
{
$this->getEntityManager()->remove( $entity );
if ( $flush ) {
$this->getEntityManager()->flush();
}
}
/**
* @return T|null $entity
*/
public function findOneByRef( $value ): ?EngineEntity
{
return $this->createQueryBuilder( 'd' )
->andWhere( 'd.ref = :val' )
->setParameter( 'val', $value )
->getQuery()
->getOneOrNullResult();
}
// /**
// * @return Connection[] Returns an array of Connection objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Connection
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}