PHPackages                             zfcampus/zf-apigility-doctrine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zfcampus/zf-apigility-doctrine

Abandoned → [laminas-api-tools/api-tools-doctrine](/?search=laminas-api-tools%2Fapi-tools-doctrine)ArchivedLibrary[Database &amp; ORM](/categories/database)

zfcampus/zf-apigility-doctrine
==============================

Apigility Doctrine module

2.3.0(7y ago)111454.0k—1.1%48[3 PRs](https://github.com/zfcampus/zf-apigility-doctrine/pulls)10BSD-3-ClausePHPPHP ^5.6 || ^7.0

Since Nov 5Pushed 6y ago33 watchersCompare

[ Source](https://github.com/zfcampus/zf-apigility-doctrine)[ Packagist](https://packagist.org/packages/zfcampus/zf-apigility-doctrine)[ Docs](http://apigility.org/)[ RSS](/packages/zfcampus-zf-apigility-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (34)Used By (10)Security (1)

Doctrine in Apigility
=====================

[](#doctrine-in-apigility)

> ## Repository abandoned 2019-12-31
>
> [](#repository-abandoned-2019-12-31)
>
> This repository has moved to [laminas-api-tools/api-tools-doctrine](https://github.com/laminas-api-tools/api-tools-doctrine).

[![Build Status](https://camo.githubusercontent.com/a88e84a8b746b17ef07006e93972432fd8bc987caabf9f42e296b29a0588c3d8/68747470733a2f2f7472617669732d63692e6f72672f7a6663616d7075732f7a662d61706967696c6974792d646f637472696e652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zfcampus/zf-apigility-doctrine)[![Coverage Status](https://camo.githubusercontent.com/56018c2168c8ec00ec83c9ebb57eeee16d75f3671c70059142542cb17293151c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7a6663616d7075732f7a662d61706967696c6974792d646f637472696e652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/zfcampus/zf-apigility-doctrine?branch=master)[![Total Downloads](https://camo.githubusercontent.com/ec58248b57a25e5c7704df095a28f84c1118790738b8f8a89a39a7b5c2d1429d/68747470733a2f2f706f7365722e707567782e6f72672f7a6663616d7075732f7a662d61706967696c6974792d646f637472696e652f646f776e6c6f616473)](https://packagist.org/packages/zfcampus/zf-apigility-doctrine)

This module provides the classes for integrating Doctrine with Apigility.

Installation
------------

[](#installation)

Installation of this module uses composer. For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/).

```
$ composer require zfcampus/zf-apigility-doctrine
```

This library provides two modules. The first, `ZF\Apigility\Doctrine\Server` provides the classes to serve data created by the second, `ZF\Apigility\Doctrine\Admin`. The *Admin* module is used to create apigility resources and the Server serves those created resources. Generally you would include *Admin* in your `config/development.config.php`and *Server* in your `config/application.config.php`.

`ZF\Apigility\Doctrine\Server` has a dependency with `Phpro\DoctrineHydrationModule` to handle entity hydration. See [documentation and instructions](https://github.com/phpro/zf-doctrine-hydration-module)on how to set up this module.

> ### zend-component-installer
>
> [](#zend-component-installer)
>
> If you use [zend-component-installer](https://github.com/zendframework/zend-component-installer), that plugin will install zf-apigility-doctrine, and all modules it depends on, as a module in your application configuration for you.

For Apache installations it is recommended the [AllowEncodedSlashes-directive is set to On](http://httpd.apache.org/docs/2.4/mod/core.html#allowencodedslashes)so the configuration can be read.

API Resources
-------------

[](#api-resources)

**NOTE!** This section was/is intended for the authors of [zf-apigility-admin-ui](https://github.com/zfcampus/zf-apigility-admin-ui). While it is possible to use these instructions to manually create Apigility Doctrine resources it is strongly recommended to use the UI.

`/apigility/api/doctrine[/:object_manager_alias]/metadata[/:name]`

This will return metadata for the named entity which is a member of the named object manager. Querying without a name will return all metadata for the object manager.

`/apigility/api/module[/:name]/doctrine[/:controller_service_name]`

This is a Doctrine resource route *like* Apigility Rest `/apigility/api/module[/:name]/rest[/:controller_service_name]`To create a resource do not include `[/:controller_service_name]`

POST Parameters

```
{
    "objectManager": "doctrine.entitymanager.orm_default",
    "serviceName": "Artist",
    "entityClass": "Db\\Entity\\Artist",
    "routeIdentifierName": "artist_id",
    "entityIdentifierName": "id",
    "routeMatch": "/api/artist",
    "pageSizeParam": "limit", // optional, default null
    "hydratorName": "DbApi\\V1\\Rest\\Artist\\ArtistHydrator", // optional, default generated
    "hydrateByValue": true // optional, default true
}
```

Hydrating Entities by Value or Reference
----------------------------------------

[](#hydrating-entities-by-value-or-reference)

By default the admin tool hydrates entities by reference by setting `$config['doctrine-hydrator']['hydrator_class']['by_value']` to `false`.

Custom Events
=============

[](#custom-events)

It is possible to hook in on specific doctrine events of the type `DoctrineResourceEvent`. This way, it is possible to alter the doctrine entities or collections before or after a specific action is performed.

Supported events:

```
EVENT_FETCH_PRE = 'fetch.pre';
EVENT_FETCH_POST = 'fetch.post';
EVENT_FETCH_ALL_PRE = 'fetch-all.pre';
EVENT_FETCH_ALL_POST = 'fetch-all.post';
EVENT_CREATE_PRE = 'create.pre';
EVENT_CREATE_POST = 'create.post';
EVENT_UPDATE_PRE = 'update.pre';
EVENT_UPDATE_POST = 'update.post';
EVENT_PATCH_PRE = 'patch.pre';
EVENT_PATCH_POST = 'patch.post';
EVENT_PATCH_LIST_PRE = 'patch-all.pre';
EVENT_PATCH_LIST_POST = 'patch-all.post';
EVENT_DELETE_PRE = 'delete.pre';
EVENT_DELETE_POST = 'delete.post';
EVENT_DELETE_LIST_PRE = 'delete-list.pre';
EVENT_DELETE_LIST_POST = 'delete-list.post';

```

Attach to events through the *Shared Event Manager*:

```
use ZF\Apigility\Doctrine\Server\Event\DoctrineResourceEvent;

$sharedEvents = $this->getApplication()->getEventManager()->getSharedManager();

$sharedEvents->attach(
    'ZF\Apigility\Doctrine\DoctrineResource',
    DoctrineResourceEvent::EVENT_CREATE_PRE,
    function(DoctrineResourceEvent $e) {
        $e->stopPropagation();
        return new ApiProblem(400, 'Stop API Creation');
    }
);
```

It is also possible to add custom event listeners to the configuration of a single doctrine-connected resource:

```
'zf-apigility' => [
    'doctrine-connected' => [
        'Api\\V1\\Rest\\User\\UserResource' => [
            // ...
            'listeners' => [
                'key.of.aggregate.listener.in.service_manager',
            ],
        ],
    ],
],
```

Querying Single Entities
========================

[](#querying-single-entities)

Multi-keyed entities
--------------------

[](#multi-keyed-entities)

You may delimit multi keys through the route parameter. The default delimiter is a period `.` (e.g. `1.2.3`). You may change the delimiter by setting the `DoctrineResource::setMultiKeyDelimiter($value)`.

Complex queries through route parameters
----------------------------------------

[](#complex-queries-through-route-parameters)

**NO LONGER SUPPORTED.** As of version 2.0.4 this functionality has been removed from this module. The intended use of this module is a 1:1 mapping of entities to resources and using subroutes is not in the spirit of this intention. It is STRONGLY recommended you use [zfcampus/zf-doctrine-querybuilder](https://github.com/zfcampus/zf-doctrine-querybuilder)for complex query-ability.

Query Providers
===============

[](#query-providers)

Query Providers are available for all find operations. The find query provider is used to fetch an entity before it is acted upon for all *DoctrineResource* methods except create.

A query provider returns a *QueryBuilder* object. By using a custom query provider you may inject conditions specific to the resource or user without modifying the resource. For instance, you may add a `$queryBuilder->andWhere('user = ' . $event->getIdentity());`in your query provider before returning the *QueryBuilder* created therein. Other uses include soft deletes so the end user can only see the active records.

A custom plugin manager is available to register your own query providers. This can be done through this configuration:

```
'zf-apigility-doctrine-query-provider' => [
    'aliases' => [
        'entity_name_fetch_all' => \Application\Query\Provider\EntityName\FetchAll::class,
    ],
    'factories' => [
        \Application\Query\Provider\EntityName\FetchAll::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
    ],
],
```

When the query provider is registered attach it to the doctrine-connected resource configuration. The default query provider is used if no specific query provider is set. You may set query providers for these keys:

- default
- fetch
- fetch\_all
- update
- patch
- delete

```
'zf-apigility' => [
    'doctrine-connected' => [
        'Api\\V1\\Rest\\....' => [
            'query_providers' => [
                'default' => 'default_orm',
                'fetch_all' => 'entity_name_fetch_all',
                // or fetch, update, patch, delete
            ],
        ],
    ],
],
```

Query Create Filters
====================

[](#query-create-filters)

In order to filter or change data sent to a create statement before it is used to hydrate the entity you may use a query create filter. Create filters are very similar to *Query Providers* in their implementation.

Create filters take the data as a parameter and return the data, modified or filtered.

A custom plugin manager is available to register your own create filters. This can be done through following configuration:

```
'zf-apigility-doctrine-query-create-filter' => [
    'aliases' => [
        'entity_name' => \Application\Query\CreateFilter\EntityName::class,
    ],
    'factories' => [
        \Application\Query\CreateFilter\EntityName::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
    ],
],
```

Register your Query Create Filter as:

```
'zf-apigility' => [
    'doctrine-connected' => [
        'Api\\V1\\Rest\\....' => [
            'query_create_filter' => 'entity_name',
            ...
        ],
    ],
],
```

Using Entity Factories
======================

[](#using-entity-factories)

By default, Doctrine entities are instantiated by FQCN without arguments. If you need anything different than that, for example if your entities require arguments in their constructors, you may specify the name of a `Doctrine\Instantiator\InstantiatorInterface` factory registered in the Service Manager in order to delegate instantiation to that service. Currently this can only be done by directly editing the config for your resources as follows:

```
'zf-apigility' => [
    'doctrine-connected' => [
        'Api\\V1\\Rest\\...Resource' => [
            'entity_factory' => 'key_in_service_manager',
            ...
        ],
    ],
],
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community40

Growing community involvement

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~233 days

Total

32

Last Release

2671d ago

Major Versions

0.3.4 → 1.0.02015-04-16

0.4.0 → 1.0.12015-04-27

0.4.1 → 1.0.22015-06-11

1.1.1 → 2.0.02015-12-08

PHP version history (4 changes)0.1.0PHP &gt;=5.4

0.3.0PHP &gt;=5.3

2.0.4-betaPHP &gt;=5.4 || ^7.0

2.1.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/296074?v=4)[Zend Framework](/maintainers/zendframework)[@zendframework](https://github.com/zendframework)

---

Top Contributors

[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (195 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (140 commits)")[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (63 commits)")[![veewee](https://avatars.githubusercontent.com/u/1618158?v=4)](https://github.com/veewee "veewee (42 commits)")[![jguittard](https://avatars.githubusercontent.com/u/5320213?v=4)](https://github.com/jguittard "jguittard (17 commits)")[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (6 commits)")[![gsomoza](https://avatars.githubusercontent.com/u/106219?v=4)](https://github.com/gsomoza "gsomoza (6 commits)")[![Hounddog](https://avatars.githubusercontent.com/u/1188248?v=4)](https://github.com/Hounddog "Hounddog (6 commits)")[![neeckeloo](https://avatars.githubusercontent.com/u/1768645?v=4)](https://github.com/neeckeloo "neeckeloo (3 commits)")[![ildanno](https://avatars.githubusercontent.com/u/8035078?v=4)](https://github.com/ildanno "ildanno (3 commits)")[![bartbrinkman](https://avatars.githubusercontent.com/u/8309358?v=4)](https://github.com/bartbrinkman "bartbrinkman (3 commits)")[![Thinkscape](https://avatars.githubusercontent.com/u/270528?v=4)](https://github.com/Thinkscape "Thinkscape (3 commits)")[![akomm](https://avatars.githubusercontent.com/u/2409779?v=4)](https://github.com/akomm "akomm (2 commits)")[![baptistemanson](https://avatars.githubusercontent.com/u/5444992?v=4)](https://github.com/baptistemanson "baptistemanson (2 commits)")[![Maks3w](https://avatars.githubusercontent.com/u/1301698?v=4)](https://github.com/Maks3w "Maks3w (2 commits)")[![matwright](https://avatars.githubusercontent.com/u/4989280?v=4)](https://github.com/matwright "matwright (2 commits)")[![pietervogelaar](https://avatars.githubusercontent.com/u/1067483?v=4)](https://github.com/pietervogelaar "pietervogelaar (2 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (2 commits)")[![takethefake](https://avatars.githubusercontent.com/u/3123354?v=4)](https://github.com/takethefake "takethefake (2 commits)")[![datasage](https://avatars.githubusercontent.com/u/826651?v=4)](https://github.com/datasage "datasage (1 commits)")

---

Tags

apidoctrineZendFrameworkzfapigility

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zfcampus-zf-apigility-doctrine/health.svg)

```
[![Health](https://phpackages.com/badges/zfcampus-zf-apigility-doctrine/health.svg)](https://phpackages.com/packages/zfcampus-zf-apigility-doctrine)
```

###  Alternatives

[sylius/grid-bundle

Amazing grids with support of filters and custom fields integrated into Symfony.

1358.3M44](/packages/sylius-grid-bundle)[ecodev/graphql-doctrine

Declare GraphQL types from Doctrine entities and attributes

102147.9k4](/packages/ecodev-graphql-doctrine)[laminas-api-tools/api-tools-doctrine

Laminas API Tools Doctrine module

10633.9k5](/packages/laminas-api-tools-api-tools-doctrine)[zfc-datagrid/zfc-datagrid

Laminas Module that provides a datagrid for different datasources and output formats

1223.2k](/packages/zfc-datagrid-zfc-datagrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
