ObjectRepository.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Doctrine\Persistence;
  3. use UnexpectedValueException;
  4. /**
  5. * Contract for a Doctrine persistence layer ObjectRepository class to implement.
  6. *
  7. * @template T
  8. */
  9. interface ObjectRepository
  10. {
  11. /**
  12. * Finds an object by its primary key / identifier.
  13. *
  14. * @param mixed $id The identifier.
  15. *
  16. * @return object|null The object.
  17. *
  18. * @psalm-return T|null
  19. */
  20. public function find($id);
  21. /**
  22. * Finds all objects in the repository.
  23. *
  24. * @return array<int, object> The objects.
  25. *
  26. * @psalm-return T[]
  27. */
  28. public function findAll();
  29. /**
  30. * Finds objects by a set of criteria.
  31. *
  32. * Optionally sorting and limiting details can be passed. An implementation may throw
  33. * an UnexpectedValueException if certain values of the sorting or limiting details are
  34. * not supported.
  35. *
  36. * @param mixed[] $criteria
  37. * @param string[]|null $orderBy
  38. * @param int|null $limit
  39. * @param int|null $offset
  40. *
  41. * @return object[] The objects.
  42. *
  43. * @throws UnexpectedValueException
  44. *
  45. * @psalm-return T[]
  46. */
  47. public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);
  48. /**
  49. * Finds a single object by a set of criteria.
  50. *
  51. * @param mixed[] $criteria The criteria.
  52. *
  53. * @return object|null The object.
  54. *
  55. * @psalm-return T|null
  56. */
  57. public function findOneBy(array $criteria);
  58. /**
  59. * Returns the class name of the object managed by the repository.
  60. *
  61. * @return string
  62. */
  63. public function getClassName();
  64. }