项目作者: Kocal

项目描述 :
Zend-Expressive subcomponent for database ORM
高级语言: PHP
项目地址: git://github.com/Kocal/zend-expressive-database.git
创建时间: 2017-08-05T20:55:36Z
项目社区:https://github.com/Kocal/zend-expressive-database

开源协议:

下载


Zend-Expressive Database

A Zend-Expressive subcomponent for easily unifying database ORM usage.

Current implementations

Usage

DatabaseFactoryInterface

This interface should be implemented by a class that will be invoked by Zend Expressive to initialize the ORM.

Example for Doctrine:

  1. <?php
  2. use Doctrine\ORM\EntityManager;
  3. use Kocal\Expressive\Database\DatabaseFactoryInterface;
  4. use Psr\Container\ContainerInterface;
  5. class EntityManagerFactory implements DatabaseFactoryInterface {
  6. public function __invoke(ContainerInterface $container) {
  7. $config = $container->get('config');
  8. // ...
  9. return EntityManager::create($foo, $bar);
  10. }
  11. }

DatabaseRepositoryInterface

This interface should be implemented by a repository.

Example:

  1. <?php
  2. use \Kocal\Expressive\Database\DatabaseRepository;
  3. class PostRepository implements DatabaseRepository {
  4. /**
  5. * Finds all Entities in the repository.
  6. * @return mixed
  7. */
  8. public function all() {
  9. }
  10. /**
  11. * Finds the first Entity in the repository.
  12. * @return mixed
  13. */
  14. public function first() {
  15. }
  16. /**
  17. * Finds the last Entity in the repository.
  18. * @return mixed
  19. */
  20. public function last() {
  21. }
  22. /**
  23. * Finds an Entity by its ID.
  24. * @param mixed $id
  25. * @return mixed
  26. */
  27. public function find($id) {
  28. }
  29. /**
  30. * Finds all Entities where `$field` value is equal `$value`.
  31. * @param string $field
  32. * @param mixed $value
  33. * @param array|null $orderBy
  34. * @return mixed
  35. */
  36. public function findByField($field, $value, $orderBy = null) {
  37. }
  38. /**
  39. * Finds all Entities depending on `$criteria`.
  40. * @param array $criteria
  41. * @param array|null $orderBy
  42. * @param int|null $limit
  43. * @param int|null $offset
  44. * @return mixed
  45. */
  46. public function findWhere(array $criteria, $orderBy = null, $limit = null, $offset = null) {
  47. }
  48. /**
  49. * Finds Entities where `$column` is in `$where` array.
  50. * @param string $column
  51. * @param array $where
  52. * @return mixed
  53. */
  54. public function findWhereIn($column, array $where) {
  55. }
  56. /**
  57. * Finds Entities where `$column` is not in `$where` array.
  58. * @param string $column
  59. * @param array $where
  60. * @return mixed
  61. */
  62. public function findWhereNotIn($column, array $where) {
  63. }
  64. /**
  65. * Save an Entity.
  66. * @param object $entity
  67. * @return void
  68. */
  69. public function save($entity) {
  70. }
  71. /**
  72. * Delete an Entity by its ID or by itself.
  73. * @param int|object $idOrEntity
  74. * @return void
  75. */
  76. public function delete($idOrEntity) {
  77. }
  78. }