Skip to content

Commit d2faada

Browse files
committed
Merge branch '2.4'
Conflicts: book/security.rst cookbook/security/firewall_restriction.rst cookbook/security/host_restriction.rst
2 parents c062d81 + b123484 commit d2faada

File tree

6 files changed

+91
-30
lines changed

6 files changed

+91
-30
lines changed

book/forms.rst

+13-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ learning the most important features of the form library along the way.
1313

1414
The Symfony Form component is a standalone library that can be used outside
1515
of Symfony2 projects. For more information, see the `Symfony2 Form component`_
16-
on Github.
16+
on GitHub.
1717

1818
.. index::
1919
single: Forms; Create a simple form
@@ -39,6 +39,7 @@ going to need to build a form. But before you begin, first focus on the generic
3939
{
4040
return $this->task;
4141
}
42+
4243
public function setTask($task)
4344
{
4445
$this->task = $task;
@@ -48,7 +49,7 @@ going to need to build a form. But before you begin, first focus on the generic
4849
{
4950
return $this->dueDate;
5051
}
51-
52+
5253
public function setDueDate(\DateTime $dueDate = null)
5354
{
5455
$this->dueDate = $dueDate;
@@ -172,7 +173,7 @@ helper functions:
172173

173174
That's it! By printing ``form(form)``, each field in the form is rendered, along
174175
with a label and error message (if there is one). The ``form`` function also
175-
surrounds everything in the necessary HTML ``form`` tag. As easy as this is,
176+
surrounds everything in the necessary HTML ``<form>`` tag. As easy as this is,
176177
it's not very flexible (yet). Usually, you'll want to render each form field
177178
individually so you can control how the form looks. You'll learn how to do
178179
that in the ":ref:`form-rendering-template`" section.
@@ -267,7 +268,8 @@ possible paths:
267268
.. note::
268269

269270
Redirecting a user after a successful form submission prevents the user
270-
from being able to hit "refresh" and re-post the data.
271+
from being able to hit the "Refresh" button of their browser and re-post
272+
the data.
271273

272274
.. index::
273275
single: Forms; Multiple Submit Buttons
@@ -566,7 +568,7 @@ First, we need to add the two buttons to the form::
566568

567569
Then, we configure the button for returning to the previous step to run
568570
specific validation groups. In this example, we want it to suppress validation,
569-
so we set its ``validation_groups`` options to false::
571+
so we set its ``validation_groups`` option to false::
570572

571573
$form = $this->createFormBuilder($task)
572574
// ...
@@ -979,10 +981,10 @@ to the ``form()`` or the ``form_start()`` helper:
979981
.. note::
980982

981983
If the form's method is not GET or POST, but PUT, PATCH or DELETE, Symfony2
982-
will insert a hidden field with the name "_method" that stores this method.
984+
will insert a hidden field with the name ``_method`` that stores this method.
983985
The form will be submitted in a normal POST request, but Symfony2's router
984-
is capable of detecting the "_method" parameter and will interpret the
985-
request as PUT, PATCH or DELETE request. Read the cookbook chapter
986+
is capable of detecting the ``_method`` parameter and will interpret it as
987+
a PUT, PATCH or DELETE request. Read the cookbook chapter
986988
":doc:`/cookbook/routing/method_parameters`" for more information.
987989

988990
.. index::
@@ -1076,7 +1078,8 @@ the choice is ultimately up to you.
10761078

10771079
public function buildForm(FormBuilderInterface $builder, array $options)
10781080
{
1079-
$builder->add('task')
1081+
$builder
1082+
->add('task')
10801083
->add('dueDate', null, array('mapped' => false))
10811084
->add('save', 'submit');
10821085
}
@@ -1316,8 +1319,7 @@ the ``cascade_validation`` option to ``TaskType``::
13161319
));
13171320
}
13181321
1319-
Render the ``Category`` fields in the same way
1320-
as the original ``Task`` fields:
1322+
Render the ``Category`` fields in the same way as the original ``Task`` fields:
13211323
13221324
.. configuration-block::
13231325

book/routing.rst

+26-13
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,10 @@ Generating URLs
12101210
---------------
12111211

12121212
The routing system should also be used to generate URLs. In reality, routing
1213-
is a bi-directional system: mapping the URL to a controller+parameters and
1213+
is a bidirectional system: mapping the URL to a controller+parameters and
12141214
a route+parameters back to a URL. The
12151215
:method:`Symfony\\Component\\Routing\\Router::match` and
1216-
:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bi-directional
1216+
:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bidirectional
12171217
system. Take the ``blog_show`` example route from earlier::
12181218

12191219
$params = $this->get('router')->match('/blog/my-blog-post');
@@ -1244,12 +1244,25 @@ route. With this information, any URL can easily be generated::
12441244

12451245
.. note::
12461246

1247-
In controllers that extend Symfony's base
1247+
In controllers that don't extend Symfony's base
12481248
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`,
1249-
you can use the
1250-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl`
1251-
method, which calls the router service's
1252-
:method:`Symfony\\Component\\Routing\\Router::generate` method.
1249+
you can use the ``router`` service's
1250+
:method:`Symfony\\Component\\Routing\\Router::generate` method::
1251+
1252+
use Symfony\Component\DependencyInjection\ContainerAware;
1253+
1254+
class MainController extends ContainerAware
1255+
{
1256+
public function showAction($slug)
1257+
{
1258+
// ...
1259+
1260+
$url = $this->container->get('router')->generate(
1261+
'blog_show',
1262+
array('slug' => 'my-blog-post')
1263+
);
1264+
}
1265+
}
12531266

12541267
In an upcoming section, you'll learn how to generate URLs from inside templates.
12551268

@@ -1338,19 +1351,19 @@ to ``generateUrl()``:
13381351

13391352
.. note::
13401353

1341-
The host that's used when generating an absolute URL is the host of
1342-
the current ``Request`` object. This is detected automatically. But if
1343-
you generate absolute URLs for scripts run from the command line, this
1344-
won't work. But don't worry! Just see :doc:`/cookbook/console/sending_emails`
1345-
for details.
1354+
The host that's used when generating an absolute URL is automatically
1355+
detected using the current ``Request`` object. When generating absolute
1356+
URLs from outside the web context (for instance in a console command) this
1357+
doesn't work. See :doc:`/cookbook/console/sending_emails` to learn how to
1358+
solve this problem.
13461359

13471360
Summary
13481361
-------
13491362

13501363
Routing is a system for mapping the URL of incoming requests to the controller
13511364
function that should be called to process the request. It both allows you
13521365
to specify beautiful URLs and keeps the functionality of your application
1353-
decoupled from those URLs. Routing is a two-way mechanism, meaning that it
1366+
decoupled from those URLs. Routing is a bidirectional mechanism, meaning that it
13541367
should also be used to generate URLs.
13551368

13561369
Learn more from the Cookbook

book/security.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ can access ``/foo`` without being prompted to authenticate.
183183

184184
.. tip::
185185

186-
You can also match a request against other details of the request (e.g. host, method). For more
187-
information and examples read :doc:`/cookbook/security/firewall_restriction`.
186+
You can also match a request against other details of the request (e.g.
187+
host, method). For more information and examples read
188+
:doc:`/cookbook/security/firewall_restriction`.
188189

189190
.. image:: /images/book/security_anonymous_user_access.png
190191
:align: center

components/console/helpers/dialoghelper.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ method::
107107
'Please enter the name of the bundle',
108108
function ($answer) {
109109
if ('Bundle' !== substr($answer, -6)) {
110-
throw new \RunTimeException(
110+
throw new \RuntimeException(
111111
'The name of the bundle should be suffixed with \'Bundle\''
112112
);
113113
}

components/serializer.rst

+31
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ method on the normalizer definition::
181181
As a final result, the deserializer uses the ``first_name`` attribute as if
182182
it were ``firstName`` and uses the ``getFirstName`` and ``setFirstName`` methods.
183183

184+
Using Callbacks to Serialize Properties with Object Instances
185+
-------------------------------------------------------------
186+
187+
When serializing, you can set a callback to format a specific object property::
188+
189+
use Acme\Person;
190+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
191+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
192+
use Symfony\Component\Serializer\Serializer;
193+
194+
$encoder = new JsonEncoder();
195+
$normalizer = new GetSetMethodNormalizer();
196+
197+
$callback = function ($dateTime) {
198+
return $dateTime instanceof \DateTime
199+
? $dateTime->format(\DateTime::ISO8601)
200+
: '';
201+
}
202+
203+
$normalizer->setCallbacks(array('createdAt' => $callback));
204+
205+
$serializer = new Serializer(array($normalizer), array($encoder));
206+
207+
$person = new Person();
208+
$person->setName('cordoval');
209+
$person->setAge(34);
210+
$person->setCreatedAt(new \DateTime('now'));
211+
212+
$serializer->serialize($person, 'json');
213+
// Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}
214+
184215
JMSSerializer
185216
-------------
186217

reference/dic_tags.rst

+17-3
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,23 @@ To register your warmer with Symfony, give it the ``kernel.cache_warmer`` tag:
477477
->addTag('kernel.cache_warmer', array('priority' => 0))
478478
;
479479
480-
The ``priority`` value is optional, and defaults to 0. This value can be
481-
from -255 to 255, and the warmers will be executed in the order of their
482-
priority.
480+
.. note::
481+
482+
The ``priority`` value is optional, and defaults to 0.
483+
The higher the priority, the sooner it gets executed.
484+
485+
Core Cache Warmers
486+
~~~~~~~~~~~~~~~~~~
487+
488+
+-------------------------------------------------------------------------------------------+-----------+
489+
| Cache Warmer Class Name | Priority |
490+
+-------------------------------------------------------------------------------------------+-----------+
491+
| :class:`Symfony\\Bundle\\FrameworkBundle\\CacheWarmer\\TemplatePathsCacheWarmer` | 20 |
492+
+-------------------------------------------------------------------------------------------+-----------+
493+
| :class:`Symfony\\Bundle\\FrameworkBundle\\CacheWarmer\\RouterCacheWarmer` | 0 |
494+
+-------------------------------------------------------------------------------------------+-----------+
495+
| :class:`Symfony\\Bundle\\TwigBundle\\CacheWarmer\\TemplateCacheCacheWarmer` | 0 |
496+
+-------------------------------------------------------------------------------------------+-----------+
483497
484498
.. _dic-tags-kernel-event-listener:
485499

0 commit comments

Comments
 (0)