|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoS\ResourceBundle\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
|
6
|
|
|
use Doctrine\ORM\EntityManager; |
|
7
|
|
|
use DoS\ResourceBundle\Doctrine\RepositoryInterface; |
|
8
|
|
|
use DoS\ResourceBundle\Factory\FactoryInterface; |
|
9
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author liverbool <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class AbstractProvider implements ProviderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var EntityManager|DocumentManager |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $manager; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $dataClass; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var RepositoryInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $repository; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var FactoryInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $factory; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(RepositoryInterface $repository, FactoryInterface $factory) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->repository = $repository; |
|
39
|
|
|
$this->factory = $factory; |
|
40
|
|
|
$this->manager = $repository->getManager(); |
|
|
|
|
|
|
41
|
|
|
$this->dataClass = $repository->getEntityName(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return ResourceInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
public function createNew() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->factory->createNew(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ResourceInterface $resource |
|
54
|
|
|
*/ |
|
55
|
|
|
public function persist(ResourceInterface $resource) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->manager->persist($resource); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param ResourceInterface|null $resource |
|
62
|
|
|
*/ |
|
63
|
|
|
public function flush(ResourceInterface $resource = null) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->manager->flush($resource); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param ResourceInterface $resource |
|
70
|
|
|
* @param bool $single |
|
71
|
|
|
*/ |
|
72
|
|
|
public function save(ResourceInterface $resource, $single = false) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->manager->persist($resource); |
|
75
|
|
|
$this->manager->flush($single ? $resource : null); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param ResourceInterface $resource |
|
80
|
|
|
*/ |
|
81
|
|
|
public function detach(ResourceInterface $resource) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->manager->detach($resource); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param ResourceInterface $resource |
|
88
|
|
|
*/ |
|
89
|
|
|
public function remove(ResourceInterface $resource) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->manager->remove($resource); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param null $objectName |
|
96
|
|
|
*/ |
|
97
|
|
|
public function clear($objectName = null) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->manager->clear($objectName); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param $id |
|
104
|
|
|
* |
|
105
|
|
|
* @return ResourceInterface |
|
106
|
|
|
*/ |
|
107
|
|
|
public function find($id) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->repository->find($id); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return ResourceInterface[] |
|
114
|
|
|
*/ |
|
115
|
|
|
public function findAll() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->repository->findAll(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param array $criteria |
|
122
|
|
|
* @param array|null $orderBy |
|
123
|
|
|
* @param null $limit |
|
124
|
|
|
* @param null $offset |
|
125
|
|
|
* |
|
126
|
|
|
* @return ResourceInterface[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param array $criteria |
|
135
|
|
|
* |
|
136
|
|
|
* @return ResourceInterface[] |
|
137
|
|
|
*/ |
|
138
|
|
|
public function findOneBy(array $criteria) |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->repository->findOneBy($criteria); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..