Skip to content

Commit 832d081

Browse files
committed
Merge pull request #1043 from sylvaincombes/patch-1
Adding information for version functionality
2 parents 035cdc4 + d20e5f8 commit 832d081

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Resources/doc/format_listener.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,39 @@ The matched version is set as a Request attribute with the name ``version``,
124124
and when using JMS serializer it is also set as an exclusion strategy
125125
automatically in the ``ViewHandler``.
126126

127-
See `this JMS Serializer article`_ for details.
127+
To make the version mechanism working :
128+
129+
1 - The client must pass the requested version in his header like this :
130+
131+
.. code-block:: yaml
132+
133+
Accept:application/json;version=1.0
134+
135+
2 - You must have declared the version value in your config, otherwise it won't be catched :
136+
137+
.. code-block:: yaml
138+
139+
fos_rest:
140+
view:
141+
mime_types:
142+
json: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1']
143+
144+
3 - You should have tagged your entities with version information (@Since, @Until ...)
145+
146+
See `this JMS Serializer article`_ for details about versioning objects.
128147

129148
.. _`this JMS Serializer article`: http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies#versioning-objects
149+
150+
That's it, it should work now.
151+
152+
If you have to verify if the version is correctly catched you can use something like :
153+
154+
.. code-block:: php
155+
156+
if ($this->container->get('fos_rest.version_listener')) {
157+
print $this->container->get('fos_rest.version_listener')->getVersion();
158+
}
159+
160+
Note that this version mechanism is configurable by your own by changing the regular expression in the `media type version regex configuration`_.
161+
162+
.. _`media type version regex configuration`: http://symfony.com/doc/master/bundles/FOSRestBundle/format_listener.html#media-type-version-extraction

0 commit comments

Comments
 (0)