1212 * limitations under the License.
1313 **/
1414
15+ use Doctrine \Common \Collections \AbstractLazyCollection ;
1516use Doctrine \Common \Collections \Criteria ;
17+ use Doctrine \Common \Collections \Selectable ;
1618use Doctrine \ORM \EntityManager ;
1719use Doctrine \ORM \EntityRepository ;
1820use Doctrine \ORM \LazyCriteriaCollection ;
19- use Doctrine \ORM \NativeQuery ;
2021use Doctrine \ORM \Query ;
2122use Doctrine \ORM \QueryBuilder ;
2223use LaravelDoctrine \ORM \Facades \Registry ;
@@ -41,7 +42,7 @@ abstract class DoctrineRepository extends EntityRepository implements IBaseRepos
4142 /**
4243 * @return EntityManager
4344 */
44- protected function getEntityManager ()
45+ protected function getEntityManager (): \ Doctrine \ ORM \ EntityManagerInterface
4546 {
4647 return Registry::getManager ($ this ->manager_name );
4748 }
@@ -171,11 +172,11 @@ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Ord
171172 *
172173 * @return QueryBuilder
173174 */
174- public function createQueryBuilder ($ alias , $ indexBy = null )
175+ public function createQueryBuilder ($ alias , $ indexBy = null ): QueryBuilder
175176 {
176177 return $ this ->getEntityManager ()->createQueryBuilder ()
177178 ->select ($ alias )
178- ->from ($ this ->_entityName , $ alias , $ indexBy );
179+ ->from ($ this ->getEntityName () , $ alias , $ indexBy );
179180 }
180181
181182 /**
@@ -187,50 +188,22 @@ public function createQueryBuilder($alias, $indexBy = null)
187188 *
188189 * @return Query\ResultSetMappingBuilder
189190 */
190- public function createResultSetMappingBuilder ($ alias )
191+ public function createResultSetMappingBuilder ($ alias ): Query \ ResultSetMappingBuilder
191192 {
192193 $ rsm = new Query \ResultSetMappingBuilder ($ this ->getEntityManager (), ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT );
193- $ rsm ->addRootEntityFromClassMetadata ($ this ->_entityName , $ alias );
194+ $ rsm ->addRootEntityFromClassMetadata ($ this ->getEntityName () , $ alias );
194195
195196 return $ rsm ;
196197 }
197198
198- /**
199- * Creates a new Query instance based on a predefined metadata named query.
200- *
201- * @param string $queryName
202- *
203- * @return Query
204- */
205- public function createNamedQuery ($ queryName )
206- {
207- return $ this ->getEntityManager ()->createQuery ($ this ->_class ->getNamedQuery ($ queryName ));
208- }
209-
210- /**
211- * Creates a native SQL query.
212- *
213- * @param string $queryName
214- *
215- * @return NativeQuery
216- */
217- public function createNativeNamedQuery ($ queryName )
218- {
219- $ queryMapping = $ this ->_class ->getNamedNativeQuery ($ queryName );
220- $ rsm = new Query \ResultSetMappingBuilder ($ this ->getEntityManager ());
221- $ rsm ->addNamedNativeQueryMapping ($ this ->_class , $ queryMapping );
222-
223- return $ this ->getEntityManager ()->createNativeQuery ($ queryMapping ['query ' ], $ rsm );
224- }
225-
226199 /**
227200 * Clears the repository, causing all managed entities to become detached.
228201 *
229202 * @return void
230203 */
231- public function clear ()
204+ public function clear (): void
232205 {
233- $ this ->getEntityManager ()->clear ($ this ->_class ->rootEntityName );
206+ $ this ->getEntityManager ()->clear ($ this ->getClassMetadata () ->rootEntityName );
234207 }
235208
236209 /**
@@ -244,9 +217,9 @@ public function clear()
244217 *
245218 * @return object|null The entity instance or NULL if the entity can not be found.
246219 */
247- public function find ($ id , $ lockMode = null , $ lockVersion = null )
220+ public function find ($ id , $ lockMode = null , $ lockVersion = null ): ? object
248221 {
249- return $ this ->getEntityManager ()->find ($ this ->_entityName , $ id , $ lockMode , $ lockVersion );
222+ return $ this ->getEntityManager ()->find ($ this ->getEntityName () , $ id , $ lockMode , $ lockVersion );
250223 }
251224
252225 /**
@@ -259,10 +232,9 @@ public function find($id, $lockMode = null, $lockVersion = null)
259232 *
260233 * @return array The objects.
261234 */
262- public function findBy (array $ criteria , array $ orderBy = null , $ limit = null , $ offset = null )
235+ public function findBy (array $ criteria , array $ orderBy = null , $ limit = null , $ offset = null ): array
263236 {
264- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
265-
237+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName ());
266238 return $ persister ->loadAll ($ criteria , $ orderBy , $ limit , $ offset );
267239 }
268240
@@ -274,9 +246,9 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
274246 *
275247 * @return object|null The entity instance or NULL if the entity can not be found.
276248 */
277- public function findOneBy (array $ criteria , array $ orderBy = null )
249+ public function findOneBy (array $ criteria , array $ orderBy = null ): ? object
278250 {
279- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
251+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () );
280252
281253 return $ persister ->load ($ criteria , null , null , [], null , 1 , $ orderBy );
282254 }
@@ -290,23 +262,22 @@ public function findOneBy(array $criteria, array $orderBy = null)
290262 *
291263 * @return int The cardinality of the objects that match the given criteria.
292264 */
293- public function count (array $ criteria)
265+ public function count (array $ criteria = []): int
294266 {
295- return $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName )->count ($ criteria );
267+ return $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () )->count ($ criteria );
296268 }
297269
298270 /**
299271 * Select all elements from a selectable that match the expression and
300272 * return a new collection containing these elements.
301273 *
302- * @param \Doctrine\Common\Collections\ Criteria $criteria
274+ * @param Criteria $criteria
303275 *
304- * @return \Doctrine\Common\Collections\Collection
276+ * @return AbstractLazyCollection&Selectable
305277 */
306- public function matching (Criteria $ criteria )
278+ public function matching (Criteria $ criteria ): AbstractLazyCollection & Selectable
307279 {
308- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
309-
280+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName ());
310281 return new LazyCriteriaCollection ($ persister , $ criteria );
311282 }
312283}
0 commit comments