Skip to content

Commit 2113424

Browse files
committed
Documentation for MongoDB
1 parent b2da160 commit 2113424

File tree

12 files changed

+262
-27
lines changed

12 files changed

+262
-27
lines changed

core/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ api_platform:
2424
# Specify a path name generator to use.
2525
path_segment_name_generator: 'api_platform.path_segment_name_generator.underscore'
2626

27+
doctrine:
28+
# To enable or disable Doctrine ORM support.
29+
enabled: true
30+
31+
doctrine_mongodb_odm:
32+
# To enable or disable Doctrine MongoDB ODM support.
33+
enabled: false
34+
2735
eager_loading:
2836
# To enable or disable eager loading.
2937
enabled: true

core/data-persisters.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ process](serialization.md).
77

88
A data persister using [Doctrine ORM](http://www.doctrine-project.org/projects/orm.html) is included with the library and
99
is enabled by default. It is able to persist and delete objects that are also mapped as [Doctrine entities](https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/basic-mapping.html).
10+
A [Doctrine MongoDB ODM](https://www.doctrine-project.org/projects/mongodb-odm.html) data persister is also included and can be enabled by following the [MongoDB documentation](mongodb.md).
1011

1112
However, you may want to:
1213

13-
* store data to other persistence layers (ElasticSearch, MongoDB, external web services...)
14+
* store data to other persistence layers (ElasticSearch, external web services...)
1415
* not publicly expose the internal model mapped with the database through the API
1516
* use a separate model for [read operations](data-providers.md) and for updates by implementing patterns such as [CQRS](https://martinfowler.com/bliki/CQRS.html)
1617

core/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ feature](http://symfony.com/doc/current/components/dependency_injection/autowiri
6868

6969
Alternatively, [the subscriber must be registered manually](http://symfony.com/doc/current/components/http_kernel/introduction.html#creating-an-event-listener).
7070

71-
[Doctrine events](http://doctrine-orm.readthedocs.org/en/latest/reference/events.html#reference-events-lifecycle-events)
71+
Doctrine events ([ORM](http://doctrine-orm.readthedocs.org/en/latest/reference/events.html#reference-events-lifecycle-events), [MongoDB ODM](https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/events.html#lifecycle-events))
7272
are also available (if you use it) if you want to hook at the object lifecycle events.
7373

7474
Built-in event listeners are:

core/extensions.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
API Platform Core provides a system to extend queries on items and collections.
44

5-
Extensions are specific to Doctrine and Elasticsearch-PHP, and therefore, the Doctrine ORM support or the Elasticsearch
5+
Extensions are specific to Doctrine and Elasticsearch-PHP, and therefore, the Doctrine ORM / MongoDB ODM support or the Elasticsearch
66
reading support must be enabled to use this feature. If you use custom providers it's up to you to implement your own
77
extension system or not.
88

@@ -152,6 +152,19 @@ security:
152152
- { path: ^/users, roles: IS_AUTHENTICATED_FULLY }
153153
```
154154

155+
## Custom Doctrine MongoDB ODM Extension
156+
157+
Creating custom extensions is the same as Doctrine ORM.
158+
159+
The interfaces are:
160+
* `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Extension\AggregationItemExtensionInterface` and `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Extension\AggregationCollectionExtensionInterface` to add stages to the [aggregation builder](https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/aggregation-builder.html).
161+
* `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Extension\AggregationResultItemExtensionInterface` and `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Extension\AggregationResultCollectionExtensionInterface` to return a result.
162+
163+
The tags are `api_platform.doctrine.mongodb.aggregation_extension.item` and `api_platform.doctrine.mongodb.aggregation_extension.collection`.
164+
165+
The custom extensions receive the [aggregation builder](https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/aggregation-builder.html),
166+
used to execute [complex operations on data](https://docs.mongodb.com/manual/aggregation/).
167+
155168
## Custom Elasticsearch Extension
156169

157170
Currently only extensions querying for a collection of items through a [search request](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html)

core/filters.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Filters
22

3-
API Platform Core provides a generic system to apply filters on collections. Useful filters for the Doctrine ORM are provided
4-
with the library. You can also create custom filters that would fit your specific needs.
3+
API Platform Core provides a generic system to apply filters on collections. Useful filters for the Doctrine ORM and
4+
MongoDB ODM are provided with the library. You can also create custom filters that would fit your specific needs.
55
You can also add filtering support to your custom [data providers](data-providers.md) by implementing interfaces provided
66
by the library.
77

@@ -10,7 +10,7 @@ By default, all filters are disabled. They must be enabled explicitly.
1010
When a filter is enabled, it is automatically documented as a `hydra:search` property in the collection response. It also
1111
automatically appears in the [NelmioApiDoc documentation](nelmio-api-doc.md) if it is available.
1212

13-
## Doctrine ORM Filters
13+
## Doctrine ORM and MongoDB ODM Filters
1414

1515
### Basic Knowledge
1616

@@ -117,10 +117,13 @@ Learn more on how the [ApiFilter annotation](filters.md#apifilter-annotation) wo
117117

118118
For the sake of consistency, we're using the annotation in the below documentation.
119119

120+
For MongoDB ODM, all the filters are in the namespace `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter`. The filter
121+
services all begin with `api_platform.doctrine_mongodb.odm`.
122+
120123
### Search Filter
121124

122-
If Doctrine ORM support is enabled, adding filters is as easy as registering a filter service in the `api/config/services.yaml`
123-
file and adding an attribute to your resource configuration.
125+
If Doctrine ORM or MongoDB ODM support is enabled, adding filters is as easy as registering a filter service in the
126+
`api/config/services.yaml` file and adding an attribute to your resource configuration.
124127

125128
The search filter supports `exact`, `partial`, `start`, `end`, and `word_start` matching strategies:
126129

@@ -330,7 +333,7 @@ It will return all offers with `sold` equals `1`.
330333

331334
### Range Filter
332335

333-
The range filter allows you to filter by a value Lower than, Greater than, Lower than or equal, Greater than or equal and between two values.
336+
The range filter allows you to filter by a value lower than, greater than, lower than or equal, greater than or equal and between two values.
334337

335338
Syntax: `?property[<lt|gt|lte|gte|between>]=value`
336339

@@ -622,7 +625,7 @@ class Tweet
622625

623626
#### Using a Custom Order Query Parameter Name
624627

625-
A conflict will occur if `order` is also the name of a property with the term filter enabled. Luckily, the query
628+
A conflict will occur if `order` is also the name of a property with the term filter enabled. Luckily, the query
626629
parameter name to use is configurable:
627630

628631
```yaml
@@ -810,21 +813,20 @@ If you want to include some properties of the nested "author" document, use: `/b
810813

811814
## Creating Custom Filters
812815

813-
Custom filters can be written by implementing the `ApiPlatform\Core\Api\FilterInterface`
814-
interface.
816+
Custom filters can be written by implementing the `ApiPlatform\Core\Api\FilterInterface` interface.
815817

816-
API Platform provides a convenient way to create Doctrine ORM filters. If you use [custom data providers](data-providers.md),
818+
API Platform provides a convenient way to create Doctrine ORM and MongoDB ODM filters. If you use [custom data providers](data-providers.md),
817819
you can still create filters by implementing the previously mentioned interface, but - as API Platform isn't aware of your
818820
persistence system's internals - you have to create the filtering logic by yourself.
819821

820822
### Creating Custom Doctrine ORM Filters
821823

822-
Doctrine filters have access to the HTTP request (Symfony's `Request` object) and to the `QueryBuilder` instance used to
824+
Doctrine ORM filters have access to the context created from the HTTP request and to the `QueryBuilder` instance used to
823825
retrieve data from the database. They are only applied to collections. If you want to deal with the DQL query generated
824-
to retrieve items, or don't need to access the HTTP request, [extensions](extensions.md) are the way to go.
826+
to retrieve items, [extensions](extensions.md) are the way to go.
825827

826828
A Doctrine ORM filter is basically a class implementing the `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\FilterInterface`.
827-
API Platform includes a convenient abstract class implementing this interface and providing utility methods: `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractFilter`
829+
API Platform includes a convenient abstract class implementing this interface and providing utility methods: `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractFilter`.
828830

829831
In the following example, we create a class to filter a collection by applying a regexp to a property. The `REGEXP` DQL
830832
function used in this example can be found in the [`DoctrineExtensions`](https://github.com/beberlei/DoctrineExtensions)
@@ -902,7 +904,7 @@ it can also be enabled for some properties:
902904
# api/config/services.yaml
903905
services:
904906
'App\Filter\RegexpFilter':
905-
arguments: [ '@doctrine', '@request_stack', '@?logger', { email: ~, anOtherProperty: ~ } ]
907+
arguments: [ '@doctrine', ~, '@?logger', { email: ~, anOtherProperty: ~ } ]
906908
# Uncomment only if autoconfiguration isn't enabled
907909
#tags: [ 'api_platform.filter' ]
908910
```
@@ -952,6 +954,15 @@ class Offer
952954
You can now enable this filter using URLs like `http://example.com/offers?regexp_email=^[FOO]`. This new filter will also
953955
appear in Swagger and Hydra documentations.
954956

957+
### Creating Custom Doctrine MongoDB ODM Filters
958+
959+
Doctrine MongoDB ODM filters have access to the context created from the HTTP request and to the [aggregation builder](https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/aggregation-builder.html)
960+
instance used to retrieve data from the database and to execute [complex operations on data](https://docs.mongodb.com/manual/aggregation/).
961+
They are only applied to collections. If you want to deal with the aggregation pipeline generated to retrieve items, [extensions](extensions.md) are the way to go.
962+
963+
A Doctrine MongoDB ODM filter is basically a class implementing the `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\FilterInterface`.
964+
API Platform includes a convenient abstract class implementing this interface and providing utility methods: `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\AbstractFilter`.
965+
955966
### Creating Custom Elasticsearch Filters
956967

957968
Elasticsearch filters have access to the context created from the HTTP request and to the Elasticsearch query clause.
@@ -963,9 +974,9 @@ A constant score query filter is basically a class implementing the `ApiPlatform
963974
and the `ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\Filter\FilterInterface`. API Platform includes a convenient
964975
abstract class implementing this last interface and providing utility methods: `ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\Filter\AbstractFilter`.
965976

966-
### Using Doctrine Filters
977+
### Using Doctrine ORM Filters
967978

968-
Doctrine features [a filter system](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/filters.html) that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated (e.g. from a DQL query, or by loading associated entities).
979+
Doctrine ORM features [a filter system](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/filters.html) that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated (e.g. from a DQL query, or by loading associated entities).
969980
These are applied on collections and items, so are incredibly useful.
970981

971982
The following information, specific to Doctrine filters in Symfony, is based upon [a great article posted on Michaël Perrin's blog](http://blog.michaelperrin.fr/2014/12/05/doctrine-filters/).

core/fosuser-bundle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ api_platform:
3939
## Creating a `User` Entity with Serialization Groups
4040

4141
Here's an example of declaration of a [Doctrine ORM User class](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#a-doctrine-orm-user-class).
42+
There's also an example for a [Doctrine MongoDB ODM](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#b-mongodb-user-class).
4243
You need to use serialization groups to hide some properties like `plainPassword` (only in read) and `password`. The properties
4344
shown are handled with the [`normalization_context`](serialization.md#normalization), while the properties
4445
you can modify are handled with [`denormalization_context`](serialization.md#denormalization).

core/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ If you are starting a new project, the easiest way to get API Platform up is to
66
It ships with the API Platform Core library integrated with [the Symfony framework](https://symfony.com), [the schema generator](../schema-generator/),
77
[Doctrine ORM](http://www.doctrine-project.org), [Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html),
88
[NelmioCorsBundle](https://github.com/nelmio/NelmioCorsBundle) and [Behat](http://behat.org).
9+
[Doctrine MongoDB ODM](https://www.doctrine-project.org/projects/mongodb-odm.html) can also be enabled by following the [MongoDB documentation](mongodb.md).
910
Basically, it is a Symfony edition packaged with the best tools to develop a REST API and sensible default settings.
1011

1112
Alternatively, you can use [Composer](http://getcomposer.org) to install the standalone bundle in an existing Symfony Flex

core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Here is the fully featured REST API you'll get in minutes:
2222
* [Automatic CRUD](operations.md)
2323
* Hypermedia (JSON-LD and HAL)
2424
* Machine-readable documentation of the API in the Hydra and [Swagger/Open API](swagger.md) formats,
25-
guessed from PHPDoc, Serializer, Validator and Doctrine ORM metadata
25+
guessed from PHPDoc, Serializer, Validator and Doctrine ORM / MongoDB ODM metadata
2626
* Nice human-readable documentation built with Swagger UI (including a sandbox) and/or ReDoc
2727
* [Pagination](pagination.md)
2828
* A bunch of [filters](filters.md)

0 commit comments

Comments
 (0)