Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 1cb898a

Browse files
committed
Rewrote providers article
1 parent 84f8829 commit 1cb898a

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

bundles/routing_auto/providers.rst

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Path providers specify a target path which is used by the subsequent path
88
actions to provide the actual route documents.
99

1010
**Base** providers must be the first configured as the first builder in the
11-
content path chain. This is because the paths that they provide correspond
11+
content path chain. This is because the paths that they provide correspond
1212
directly to an existing path, i.e. they have an absolute reference.
1313

1414
specified (base provider)
@@ -17,6 +17,14 @@ specified (base provider)
1717
This is the most basic path provider and allows you to specify an exact
1818
(fixed) path.
1919

20+
Options
21+
.......
22+
23+
* ``path`` - **required** The path to provide.
24+
25+
Example
26+
.......
27+
2028
.. configuration-block::
2129

2230
.. code-block:: yaml
@@ -36,68 +44,73 @@ This is the most basic path provider and allows you to specify an exact
3644
'provider' => array('specified', array('path' => 'this/is/a/path')),
3745
);
3846
39-
Options:
47+
.. caution::
4048

41-
* ``path`` - **required** The path to provide.
42-
43-
.. note::
44-
45-
You never specifiy absolute paths in the auto route system. If the builder
46-
unit is the first content path chain it is understood that it is the base
47-
of an absolute path.
49+
You should never specifiy absolute paths in the auto route system. If the
50+
builder unit is the first content path chain it is understood that it is
51+
the base of an absolute path.
4852

4953
content_object (base provider)
5054
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5155

5256
The content object provider will try and provide a path from an object
5357
implementing ``RouteReferrersInterface`` provided by a designated method on the
54-
content document. For example, if you have a ``Post`` class, which has a
55-
``getBlog`` method, using this provider you can tell the ``Post`` auto route
56-
to use the route of the blog as a base.
58+
content document. For example, if you have a ``Topic`` class, which has a
59+
``getCategory`` method, using this provider you can tell the ``Topic`` auto route
60+
to use the route of the category as a base.
61+
62+
So basically, if your category document has a path of ``/this/is/my/category``,
63+
you can use this path as the base of your ``Category`` auto-route.
5764

58-
So basically, if your blog content has a path of ``/this/is/my/blog`` you can
59-
use this path as the base of your ``Post`` auto-route.
65+
Options
66+
.......
6067

61-
Example:
68+
- ``method``: **required** Method used to return the document whose route path you wish to use.
69+
70+
Example
71+
.......
6272

6373
.. configuration-block::
6474

6575
.. code-block:: yaml
6676
67-
provider: [content_object, { method: getBlog }]
77+
provider: [content_object, { method: getCategory }]
6878
6979
.. code-block:: xml
7080
7181
<provider name="content_object">
72-
<option name="method" value="getBlog" />
82+
<option name="method" value="getCategory" />
7383
</provider>
7484
7585
.. code-block:: php
7686
7787
array(
7888
// ...
79-
'provider' => array('content_object', array('method' => 'getBlog')),
89+
'provider' => array('content_object', array('method' => 'getCategory')),
8090
);
8191
8292
.. note::
8393

84-
At the time of writing translated objects are not supported. This isn't hard to do, but well, I just
85-
havn't done it yet.
86-
87-
Options:
88-
89-
- ``method``: **required** Method used to return the document whose route path we wish to use.
94+
At the time of writing translated objects are not supported. But a patch
95+
is already created for this feature.
9096

9197
content_method
9298
~~~~~~~~~~~~~~
9399

94-
The ``content_method`` provider allows the content object (e.g. a blog
95-
``Post``) to specify a path using one of its methods. This is quite a powerful
100+
The ``content_method`` provider allows the content object (e.g. a forum
101+
``Topic``) to specify a path using one of its methods. This is quite a powerful
96102
method as it allows the content document to do whatever it can to produce the
97103
route, the disadvantage is that your content document will have extra code in
98104
it.
99105

100-
**Example 1**:
106+
Options
107+
.......
108+
109+
* ``method``: **required** Method used to return the route name/path/path elements.
110+
* ``slugify``: If the return value should be slugified, default is ``true``.
111+
112+
Example
113+
.......
101114

102115
.. configuration-block::
103116

@@ -118,58 +131,44 @@ it.
118131
'provider' => array('content_method', array('method' => 'getTitle')),
119132
);
120133
121-
This example will use the existing method "getTitle" of the ``Post`` document
134+
This example will use the existing method "getTitle" of the ``Topic`` document
122135
to retrieve the title. By default all strings are *slugified*.
123136

124-
The method can return the path either as a single string or an array of path
125-
elements as shown in the following example::
137+
The method can return the path either as a single string, an array of path
138+
elements or an object which can be converted into a string, as shown in the
139+
following example::
126140

127-
class Post
141+
class Topic
128142
{
129-
public function getTitle()
130-
{
131-
return "This is a post";
132-
}
133-
134-
public function getPathElements()
135-
{
136-
return array('this', 'is', 'a', 'path');
137-
}
143+
/* Using a string */
144+
public function getTitle()
145+
{
146+
return "This is a topic";
147+
}
148+
149+
/* Using an array */
150+
public function getPathElements()
151+
{
152+
return array('this', 'is', 'a', 'path');
153+
}
154+
155+
/* Using an object */
156+
public function getStringObject()
157+
{
158+
$object = ...; // an object which has a __toString() method
159+
160+
return $object;
161+
}
138162
}
139163

140-
Options:
141-
142-
* ``method``: **required** Method used to return the route name/path/path elements.
143-
* ``slugify``: If we should use the slugifier, default is ``true``.
144-
145164
content_datetime
146165
~~~~~~~~~~~~~~~~
147166

148167
The ``content_datettime`` provider will provide a path from a ``DateTime``
149168
object provided by a designated method on the content document.
150169

151-
**Example 1**:
152-
153-
.. configuration-block::
154-
155-
.. code-block:: yaml
156-
157-
provider: [content_datetime, { method: getDate }]
158-
159-
.. code-block:: xml
160-
161-
<provider name="content_datetime">
162-
<option name="method" value="getDate" />
163-
</provider>
164-
165-
.. code-block:: php
166-
167-
array(
168-
// ...
169-
'provider' => array('content_datetime', array('method' => 'getDate')),
170-
);
171-
172-
**Example 2**:
170+
Example
171+
.......
173172

174173
.. configuration-block::
175174

@@ -196,17 +195,18 @@ object provided by a designated method on the content document.
196195
197196
.. note::
198197

199-
This method extends `content_method` and inherits the slugify feature.
200-
Internally we return a string using the `DateTime->format()` method. This
198+
This method extends `content_method`_ and inherits the slugify feature.
199+
Internally, it returns a string using the `DateTime->format()` method. This
201200
means that you can specify your date in anyway you like and it will be
202-
automatically slugified, also, by adding path separators in the
203-
`date_format` you are effectively creating routes for each date component
201+
automatically slugified. Also, by adding path separators in the
202+
``date_format`` you are effectively creating routes for each date component
204203
as slugify applies to **each element** of the path.
205204

206-
Options:
205+
Options
206+
.......
207207

208208
* ``method``: **required** Method used to return the route name/path/path
209209
elements.
210-
* ``slugify``: If we should use the slugifier, default is ``true``.
210+
* ``slugify``: If the return value should be slugified, default is ``true``.
211211
* ``date_format``: Any date format accepted by the `DateTime` class, default
212212
``Y-m-d``.

0 commit comments

Comments
 (0)