{"id":16590405,"url":"https://github.com/kocal/zend-expressive-doctrinedatabase","last_synced_at":"2026-04-22T10:02:28.247Z","repository":{"id":57007902,"uuid":"99447361","full_name":"Kocal/zend-expressive-doctrinedatabase","owner":"Kocal","description":"Use Doctrine ORM in Zend-Expressive","archived":false,"fork":false,"pushed_at":"2017-08-05T21:43:42.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T23:07:41.674Z","etag":null,"topics":["database","doctrine-orm","zend-expressive","zend-expressive-database"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kocal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-05T20:56:03.000Z","updated_at":"2020-03-10T08:09:00.000Z","dependencies_parsed_at":"2022-08-21T12:40:35.172Z","dependency_job_id":null,"html_url":"https://github.com/Kocal/zend-expressive-doctrinedatabase","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kocal%2Fzend-expressive-doctrinedatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kocal%2Fzend-expressive-doctrinedatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kocal%2Fzend-expressive-doctrinedatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kocal%2Fzend-expressive-doctrinedatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kocal","download_url":"https://codeload.github.com/Kocal/zend-expressive-doctrinedatabase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242213358,"owners_count":20090693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","doctrine-orm","zend-expressive","zend-expressive-database"],"created_at":"2024-10-11T23:12:50.730Z","updated_at":"2026-04-22T10:02:28.211Z","avatar_url":"https://github.com/Kocal.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Zend-Expressive Doctrine Database\n=================================\n\n# Installation\n\n## Composer\nRun `composer require kocal/zend-expressive-doctrinedatabase`\n\n## Zend-Expressive configuration\n\nIn a Zend-Expressive configuration file (e.g.: `config/autoload/database.global.php` if you used Zend-Expressive app generator):\n\n```php\n\u003c?php\n\nuse Doctrine\\ORM\\EntityManager;\nuse Kocal\\Expressive\\Database\\Doctrine\\EntityManagerFactory;\n\nreturn [\n    'dependencies' =\u003e [\n        'factories' =\u003e [\n            // Use EntityManagerFactory for using Doctrine EntityManager:\n            EntityManager::class =\u003e EntityManagerFactory::class\n        ]\n    ],\n\n    'doctrine' =\u003e [\n        // DBAL configuration. More at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html\n        'driver' =\u003e 'pdo_sqlite',\n        'path' =\u003e __DIR__ . '/../../database/database.sqlite',\n        'charset' =\u003e 'utf8',\n        'collation' =\u003e 'utf8_unicode_ci',\n    ],\n\n    'entities_path' =\u003e [\n        // Path to Entity, e.g.: `/path/to/project/src/App/Entity`\n    ],\n];\n```\n\nNow let's create an Entity and its Repository.\n\n## Usage\n\n### Creating an Entity\n\nLet's say our Entities are located in `src/App/Entity` folder.\n\nExample of a `Post` Entity:\n\n```php\n\u003c?php\n\nnamespace App\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity(repositoryClass=\"App\\Repository\\PostRepository\")\n * @ORM\\Table(name=\"posts\") \n */\nclass Post {\n    /**\n     * @ORM\\Id()\n     * @ORM\\Column(type=\"integer\")\n     * @ORM\\GeneratedValue()\n     */\n    private $id;\n\n    /**\n     * @var string\n     * @ORM\\Column(name=\"title\", type=\"string\")\n     */\n    private $title;\n\n    /**\n     * @var string\n     * @ORM\\Column(name=\"content\", type=\"text\")\n     */\n    private $content;\n\n    /**\n     * Post constructor.\n     * @param string $title\n     * @param string $content\n     */\n    public function __construct($title, $content)\n    {\n        $this-\u003etitle = $title;\n        $this-\u003econtent = $content;\n    }\n\n    /**\n     * @return mixed\n     */\n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n\n    /**\n     * @param mixed $id\n     */\n    public function setId($id)\n    {\n        $this-\u003eid = $id;\n    }\n\n    /**\n     * @return string\n     */\n    public function getTitle()\n    {\n        return $this-\u003etitle;\n    }\n\n    /**\n     * @param string $title\n     */\n    public function setTitle($title)\n    {\n        $this-\u003etitle = $title;\n    }\n\n    /**\n     * @return string\n     */\n    public function getContent()\n    {\n        return $this-\u003econtent;\n    }\n\n    /**\n     * @param string $content\n     */\n    public function setContent($content)\n    {\n        $this-\u003econtent = $content;\n    }\n}\n\n```\n\n### Creating a Repository\n\nA Repository should extends from [`DoctrineRepository`](./src/DoctrineRepository.php) class, which implements [`DatabaseRepositoryInterface`](https://github.com/Kocal/zend-expressive-database/blob/master/src/DatabaseRepositoryInterface.php)\n\n```php\n\u003c?php\n\nnamespace App\\Repository;\n\nuse App\\Entity\\Post;\nuse Kocal\\Expressive\\Database\\Doctrine\\DoctrineRepository;\n\n/**\n * Class PostRepository\n */\nclass PostRepository extends DoctrineRepository\n{\n    // Some methods are already implemented.\n    // Do not hesitate to read `DoctrineRepository.php`!\n    \n    // You can add custom methods\n    \n    /**\n     * @return Post[]\n     */\n    public function getTwoLastPosts()\n    {\n        return $this-\u003ecreateQueryBuilder('p')\n            -\u003eselect('p')\n            -\u003esetMaxResults(2)\n            -\u003eorderBy('p.id', 'DESC')\n            -\u003egetQuery()\n            -\u003egetResult();\n    }\n}\n\n```\n\n### Using a Repository:\n\n```php\n\u003c?php\n\nuse App\\Entity\\Post;\nuse Doctrine\\ORM\\EntityManager;\n\n// Retrieve EntityManager in the Container \n$em = $container-\u003eget(EntityManager::class);\n\n// Retrieve PostRepository\n$postRepository = $em-\u003egetRepository(Post::class);\n\n// Use it!\n$allPosts = $postRepository-\u003eall();\n$firstPost = $postRepository-\u003efirst();\n$lastPost = $postRepository-\u003elast();\n\n$post = new Post('Hello world!', 'Lorem ispum dolor sit amet...');\n$postRepository-\u003esave($post);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkocal%2Fzend-expressive-doctrinedatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkocal%2Fzend-expressive-doctrinedatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkocal%2Fzend-expressive-doctrinedatabase/lists"}