1
1
.. index ::
2
2
single: Path Providers; RoutingAutoBundle
3
3
4
- Path Providers
5
- --------------
4
+ Token Providers
5
+ ---------------
6
6
7
- Path providers specify a target path which is used by the subsequent path
8
- actions to provide the actual route documents.
9
-
10
- **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
12
- directly to an existing path, i.e. they have an absolute reference.
13
-
14
- specified (base provider)
15
- ~~~~~~~~~~~~~~~~~~~~~~~~~
16
-
17
- This is the most basic path provider and allows you to specify an exact
18
- (fixed) path.
19
-
20
- Options
21
- .......
22
-
23
- * ``path `` - **required ** The path to provide.
24
-
25
- .. configuration-block ::
26
-
27
- .. code-block :: yaml
28
-
29
- provider : [specified, { path: this/is/a/path }]
30
-
31
- .. code-block :: xml
32
-
33
- <provider name =" specified" >
34
- <option name =" path" value =" this/is/a/path" />
35
- </provider >
36
-
37
- .. code-block :: php
38
-
39
- array(
40
- // ...
41
- 'provider' => array('specified', array('path' => 'this/is/a/path')),
42
- );
43
-
44
- .. caution ::
45
-
46
- You should never specifiy absolute paths in the auto route system. If the
47
- builder unit is the first content path chain it is understood that it is
48
- the base of an absolute path.
49
-
50
- content_object (base provider)
51
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
-
53
- The content object provider will try and provide a path from an object
54
- implementing ``RouteReferrersInterface `` provided by a designated method on the
55
- content document. For example, if you have a ``Topic `` class, which has a
56
- ``getCategory `` method, using this provider you can tell the ``Topic `` auto route
57
- to use the route of the category as a base.
58
-
59
- So basically, if your category document has a path of ``/this/is/my/category ``,
60
- you can use this path as the base of your ``Category `` auto-route.
61
-
62
- Options
63
- .......
64
-
65
- - ``method ``: **required ** Method used to return the document whose route path you wish to use.
66
-
67
- .. configuration-block ::
68
-
69
- .. code-block :: yaml
70
-
71
- provider : [content_object, { method: getCategory }]
72
-
73
- .. code-block :: xml
74
-
75
- <provider name =" content_object" >
76
- <option name =" method" value =" getCategory" />
77
- </provider >
78
-
79
- .. code-block :: php
80
-
81
- array(
82
- // ...
83
- 'provider' => array('content_object', array('method' => 'getCategory')),
84
- );
85
-
86
- .. note ::
87
-
88
- At the time of writing translated objects are not supported. But a patch
89
- is already created for this feature.
7
+ Token providers provide values for the tokens specified in the URL schemas.
90
8
91
9
content_method
92
10
~~~~~~~~~~~~~~
93
11
94
12
The ``content_method `` provider allows the content object (e.g. a forum
95
13
``Topic ``) to specify a path using one of its methods. This is quite a powerful
96
14
method as it allows the content document to do whatever it can to produce the
97
- route, the disadvantage is that your content document will have extra code in
98
- it.
15
+ route.
99
16
100
17
Options
101
18
.......
@@ -107,94 +24,104 @@ Options
107
24
108
25
.. code-block :: yaml
109
26
110
- provider : [content_method, { method: getTitle }]
111
-
112
- .. code-block :: xml
113
-
114
- <provider name =" content_method" >
115
- <option name =" method" value =" getTitle" />
116
- </provider >
27
+ # src/Acme/ForumBundle/Resources/config/routing_auto.yml
28
+ Acme\ForumBundle\Document\Topic :
29
+ url_schema : /my-forum/{title}
30
+ token_providers :
31
+ title : [content_method, {method: getTitle} ]
117
32
118
- .. code-block :: php
33
+ .. code-block: xml
119
34
120
- array(
121
- // ...
122
- 'provider' => array('content_method', array('method' => 'getTitle')),
123
- );
35
+ <?xml version="1.0" ?>
36
+ <!-- src/Acme/ForumBundle/Resources/config/routing_auto.xml -->
37
+ <auto-mapping xmlns="http://cmf.symfony.com/schema/routing_auto">
38
+ <mapping class="Acme\ForumBundle\Document\Topic" url-schema="/my-forum/{title}">
39
+ <token-provider token="category" name="content_method">
40
+ <option name="method">getCategoryName</option>
41
+ </token-provider>
42
+ </mapping>
43
+ </auto-mapping>
124
44
125
45
This example will use the existing method "getTitle" of the ``Topic `` document
126
46
to retrieve the title. By default all strings are *slugified *.
127
47
128
- The method can return the path either as a single string, an array of path
129
- elements or an object which can be converted into a string, as shown in the
130
- following example::
131
-
132
- class Topic
133
- {
134
- /* Using a string */
135
- public function getTitle()
136
- {
137
- return "This is a topic";
138
- }
139
-
140
- /* Using an array */
141
- public function getPathElements()
142
- {
143
- return array('this', 'is', 'a', 'path');
144
- }
145
-
146
- /* Using an object */
147
- public function getStringObject()
148
- {
149
- $object = ...; // an object which has a __toString() method
150
-
151
- return $object;
152
- }
153
- }
48
+ Options
49
+ .......
50
+
51
+ * ``method ``: **required ** Method used to return the route name/path/path
52
+ elements.
53
+ * ``slugify ``: If the return value should be slugified, default is ``true ``.
154
54
155
55
content_datetime
156
56
~~~~~~~~~~~~~~~~
157
57
158
- The ``content_datettime `` provider will provide a path from a ``DateTime ``
58
+ The ``content_datetime `` provider will provide a path from a ``DateTime ``
159
59
object provided by a designated method on the content document.
160
60
161
61
.. configuration-block ::
162
62
163
63
.. code-block :: yaml
164
64
165
- provider : [content_datetime, { method: getDate, date_format: Y/m/d }]
65
+ # src/Acme/ForumBundle/Resources/config/routing_auto.yml
66
+ Acme\ForumBundle\Document\Topic :
67
+ url_schema : /blog/{date}/my-post
68
+ token_providers :
69
+ date : [content_datetime, {method: getDate} ]
70
+
71
+ .. code-block: xml
166
72
167
- .. code-block :: xml
73
+ <?xml version="1.0" ?>
74
+ <!-- src/Acme/ForumBundle/Resources/config/routing_auto.xml -->
75
+ <auto-mapping xmlns="http://cmf.symfony.com/schema/routing_auto">
76
+ <mapping class="Acme\ForumBundle\Document\Topic" url-schema="/blog/{date}/my-post">
77
+ <token-provider token="date" name="content_datetime">
78
+ <option name="method">getDate</option>
79
+ </token-provider>
80
+ </mapping>
81
+ </auto-mapping>
168
82
169
- <provider name =" content_datetime" >
170
- <option name =" method" value =" getDate" />
171
- <option name =" date_format" value =" Y/m/d" />
172
- </provider >
83
+ Options
84
+ .......
173
85
174
- .. code-block :: php
86
+ * ``method ``: **required ** Method used to return the route name/path/path
87
+ elements.
88
+ * ``slugify ``: If the return value should be slugified, default is ``true ``.
89
+ * ``date_format ``: Any date format accepted by the `DateTime ` class, default
90
+ ``Y-m-d ``.
175
91
176
- array(
177
- // ...
178
- 'provider' => array('content_datetime', array(
179
- 'method' => 'getDate',
180
- 'date_format' => 'Y/m/d',
181
- )),
182
- );
92
+ content_locale
93
+ ~~~~~~~~~~~~~~
183
94
184
- .. note ::
95
+ The ``content_locale `` provider will provide the locale (e.g. ``fr ``, ``de ``,
96
+ etc) from the subject object. It ultimately it determines the locale from the
97
+ storage specific adapter - so it is dependent upon the adapter supporting this
98
+ feature.
185
99
186
- This method extends `content_method `_ and inherits the slugify feature.
187
- Internally, it returns a string using the `DateTime->format() ` method. This
188
- means that you can specify your date in anyway you like and it will be
189
- automatically slugified. Also, by adding path separators in the
190
- ``date_format `` you are effectively creating routes for each date component
191
- as slugify applies to **each element ** of the path.
100
+ .. configuration-block ::
101
+
102
+ .. code-block :: yaml
103
+
104
+ # src/Acme/ForumBundle/Resources/config/routing_auto.yml
105
+ Acme\ForumBundle\Document\Topic :
106
+ url_schema : /blog/{locale}/my-post
107
+ token_providers :
108
+ locale : [content_locale ]
109
+
110
+ .. code-block: xml
111
+
112
+ <?xml version="1.0" ?>
113
+ <!-- src/Acme/ForumBundle/Resources/config/routing_auto.xml -->
114
+ <auto-mapping xmlns="http://cmf.symfony.com/schema/routing_auto">
115
+ <mapping class="Acme\ForumBundle\Document\Topic" url-schema="/blog/{locale}/my-post">
116
+ <token-provider token="locale" name="content_locale" />
117
+ </mapping>
118
+ </auto-mapping>
192
119
193
120
Options
194
121
.......
195
122
196
123
* ``method ``: **required ** Method used to return the route name/path/path
197
124
elements.
198
125
* ``slugify ``: If the return value should be slugified, default is ``true ``.
199
- * ``date_format ``: Any date format accepted by the `DateTime ` class, default
126
+ * ``locale_format ``: Any locale format accepted by the `DateTime ` class, default
200
127
``Y-m-d ``.
0 commit comments