8000 Merge branch '2.3' · craue/symfony-docs@030a6f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 030a6f8

Browse files
committed
Merge branch '2.3'
2 parents 4c06860 + bf67517 commit 030a6f8

25 files changed

+372
-103
lines changed

book/controller.rst

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -687,23 +687,19 @@ the ``notice`` message:
687687

688688
.. code-block:: html+jinja
689689

690-
{% if app.session.started %}
691-
{% for flashMessage in app.session.flashbag.get('notice') %}
692-
<div class="flash-notice">
693-
{{ flashMessage }}
694-
</div>
695-
{% endfor %}
696-
{% endif %}
690+
{% for flashMessage in app.session.flashbag.get('notice') %}
691+
<div class="flash-notice">
692+
{{ flashMessage }}
693+
</div>
694+
{% endfor %}
697695

698696
.. code-block:: html+php
699697

700-
<?php if ($view['session']->isStarted()): ?>
701-
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
702-
<div class="flash-notice">
703-
<?php echo "<div class='flash-error'>$message</div>" ?>
704-
</div>
705-
<?php endforeach; ?>
706-
<?php endif; ?>
698+
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
699+
<div class="flash-notice">
700+
<?php echo "<div class='flash-error'>$message</div>" ?>
701+
</div>
702+
<?php endforeach; ?>
707703

708704
By design, flash messages are meant to live for exactly one request (they're
709705
"gone in a flash"). They're designed to be used across redirects exactly as

book/doctrine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ and ``nullable``. Take a few examples:
14621462
<!--
14631463
A string field length 255 that cannot be null
14641464
(reflecting the default values for the "length" and *nullable* options)
1465-
type attribute is necessary in yaml definitions
1465+
type attribute is necessary in xml definitions
14661466
-->
14671467
<field name="name" type="string" />
14681468
<field name="email"

book/forms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ In this example, you've added two fields to your form - ``task`` and ``dueDate``
126126
corresponding to the ``task`` and ``dueDate`` properties of the ``Task`` class.
127127
You've also assigned each a "type" (e.g. ``text``, ``date``), which, among
128128
other things, determines which HTML form tag(s) is rendered for that field.
129-
At Finally, you added a submit button for submitting the form to the server.
129+
Finally, you added a submit button for submitting the form to the server.
130130

131131
.. versionadded:: 2.3
132132
Support for submit buttons was added in Symfony 2.3. Before that, you had

book/from_flat_php_to_symfony2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ content:
433433
434434
{
435435
"require": {
436-
"symfony/symfony": "2.2.*"
436+
"symfony/symfony": "2.3.*"
437437
},
438438
"autoload": {
439439
"files": ["model.php","controllers.php"]

book/http_cache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ possible.
975975

976976
.. tip::
977977

978-
The listener listener only responds to local IP addresses or trusted
978+
The listener only responds to local IP addresses or trusted
979979
proxies.
980980

981981
.. note::

book/templating.rst

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,43 +1381,9 @@ in a JavaScript string, use the ``js`` context:
13811381
Debugging
13821382
---------
13831383

1384-
.. versionadded:: 2.0.9
1385-
This feature is available as of Twig ``1.5.x``, which was first shipped
1386-
with Symfony 2.0.9.
1387-
13881384
When using PHP, you can use ``var_dump()`` if you need to quickly find the
13891385
value of a variable passed. This is useful, for example, inside your controller.
1390-
The same can be achieved when using Twig by using the debug extension. This
1391-
needs to be enabled in the config:
1392-
1393-
.. configuration-block::
1394-
1395-
.. code-block:: yaml
1396-
1397-
# app/config/config.yml
1398-
services:
1399-
acme_hello.twig.extension.debug:
1400-
class: Twig_Extension_Debug
1401-
tags:
1402-
- { name: 'twig.extension' }
1403-
1404-
.. code-block:: xml
1405-
1406-
<!-- app/config/config.xml -->
1407-
<services>
1408-
<service id="acme_hello.twig.extension.debug" class="Twig_Extension_Debug">
1409-
<tag name="twig.extension" />
1410-
</service>
1411-
</services>
1412-
1413-
.. code-block:: php
1414-
1415-
// app/config/config.php
1416-
use Symfony\Component\DependencyInjection\Definition;
1417-
1418-
$definition = new Definition('Twig_Extension_Debug');
1419-
$definition->addTag('twig.extension');
1420-
$container->setDefinition('acme_hello.twig.extension.debug', $definition);
1386+
The same can be achieved when using Twig thanks to the the debug extension.
14211387

14221388
Template parameters can then be dumped using the ``dump`` function:
14231389

book/validation.rst

Lines changed: 128 additions & 0 deletions
F438
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 F987 @@ With this configuration, there are two validation groups:
779779

780780
* ``Default`` - contains the constraints not assigned to any other group;
781781

782+
* ``User`` - contains the constraints that belongs to group ``Default``
783+
(this group is useful for :ref:`book-validation-group-sequence`);
784+
782785
* ``registration`` - contains the constraints on the ``email`` and ``password``
783786
fields only.
784787

@@ -787,13 +790,138 @@ as the second argument to the ``validate()`` method::
787790

788791
$errors = $validator->validate($author, array('registration'));
789792

793+
If no groups are specified, all constraints that belong in group ``Default``
794+
will be applied.
795+
790796
Of course, you'll usually work with validation indirectly through the form
791797
library. For information on how to use validation groups inside forms, see
792798
:ref:`book-forms-validation-groups`.
793799

794800
.. index::
795801
single: Validation; Validating raw values
796802

803+
.. _book-validation-group-sequence:
804+
805+
Group Sequence
806+
--------------
807+
808+
In some cases, you want to validate your groups by steps. To do this, you can
809+
use the ``GroupSequence`` feature. In the case, an object defines a group sequence,
810+
and then the groups in the group sequence are validated in order.
811+
812+
.. tip::
813+
814+
Group sequences cannot contain the group ``Default``, as this would create
815+
a loop. Instead, use the group ``{ClassName}`` (e.g. ``User``) instead.
816+
817+
For example, suppose you have a ``User`` class and want to validate that the
818+
username and the password are different only if all other validation passes
819+
(in order to avoid multiple error messages).
820+
821+
.. configuration-block::
822+
823+
.. code-block:: yaml
824+
825+
# src/Acme/BlogBundle/Resources/config/validation.yml
826+
Acme\BlogBundle\Entity\User:
827+
group_sequence:
828+
- User
829+
- Strict
830+
getters:
831+
passwordLegal:
832+
- "True":
833+
message: "The password cannot match your username"
834+
groups: [Strict]
835+
properties:
836+
username:
837+
- NotBlank: ~
838+
password:
839+
- NotBlank: ~
840+
841+
.. code-block:: php-annotations
842+
843+
// src/Acme/BlogBundle/Entity/User.php
844+
namespace Acme\BlogBundle\Entity;
845+
846+
use Symfony\Component\Security\Core\User\UserInterface;
847+
use Symfony\Component\Validator\Constraints as Assert;
848+
849+
/**
850+
* @Assert\GroupSequence({"Strict", "User"})
851+
*/
852+
class User implements UserInterface
853+
{
854+
/**
855+
* @Assert\NotBlank
856+
*/
857+
private $username;
858+
859+
/**
860+
* @Assert\NotBlank
861+
*/
862+
private $password;
863+
864+
/**
865+
* @Assert\True(message="The password cannot match your username", groups={"Strict"})
866+
*/
867+
public function isPasswordLegal()
868+
{
869+
return ($this->username !== $this->password);
870+
}
871+
}
872+
873+
.. code-block:: xml
874+
875+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
876+
<class name="Acme\BlogBundle\Entity\User">
877+
<property name="username">
878+
<constraint name="NotBlank" />
879+
</property>
880+
<property name="password">
881+
<constraint name="NotBlank" />
882+
</property>
883+
<getter property="passwordLegal">
884+
<constraint name="True">
885+
<option name="message">The password cannot match your username</option>
886+
<option name="groups">
887+
<value>Strict</value>
888+
</option>
889+
</constraint>
890+
</getter>
891+
<group-sequence>
892+
<value>User</value>
893+
<value>Strict</value>
894+
</group-sequence>
895+
</class>
896+
897+
.. code-block:: php
898+
899+
// src/Acme/BlogBundle/Entity/User.php
900+
namespace Acme\BlogBundle\Entity;
901+
902+
use Symfony\Component\Validator\Mapping\ClassMetadata;
903+
use Symfony\Component\Validator\Constraints as Assert;
904+
905+
class User
906+
{
907+
public static function loadValidatorMetadata(ClassMetadata $metadata)
908+
{
909+
$metadata->addPropertyConstraint('username', new Assert\NotBlank());
910+
$metadata->addPropertyConstraint('password', new Assert\NotBlank());
911+
912+
$metadata->addGetterConstraint('passwordLegal', new Assert\True(array(
913+
'message' => 'The password cannot match your first name',
914+
'groups' => array('Strict'),
915+
)));
916+
917+
$metadata->setGroupSequence(array('User', 'Strict'));
918+
}
919+
}
920+
921+
In this example, it will first validate all constraints in the group ``User``
922+
(which is the same as the ``Default`` group). Only if all constraints in
923+
that group are valid, the second group, ``Strict``, will be validated.
924+
797925
.. _book-validation-raw-values:
798926

799927
Validating Values and Arrays

components/config/definition.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ and sometimes only:
443443
444444
By default ``connection`` would be an array in the first case and a string
445445
in the second making it difficult to validate. You can ensure it is always
446-
an array with with ``fixXmlConfig``.
446+
an array with ``fixXmlConfig``.
447447

448448
You can further control the normalization process if you need to. For example,
449449
you may want to allow a string to be set and used as a particular key or several

components/event_dispatcher/container_aware_dispatcher.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Adding Subscriber Services
5656
``EventSubscribers`` can be added using the
5757
:method:`Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher::addSubscriberService`
5858
method where the first argument is the service ID of the subscriber service,
59-
and the second argument is the the service's class name (which must implement
59+
and the second argument is the service's class name (which must implement
6060
:class:`Symfony\\Component\\EventDispatcher\\EventSubscriberInterface`) as follows::
6161

6262
$dispatcher->addSubscriberService(

components/http_foundation/session_configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ examples if you wish to write your own.
7979
Example usage::
8080

8181
use Symfony\Component\HttpFoundation\Session\Session;
82-
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
82+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
8383
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
8484

8585
$storage = new NativeSessionStorage(array(), new PdoSessionHandler());

components/http_foundation/sessions.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,3 @@ Compact method to process display all flashes at once::
329329
echo "<div class='flash-$type'>$message</div>\n";
330330
}
331331
}
332-
333-
.. caution::
334-
335-
As flash messages use a session to store the messages from one request to
336-
the next one, a session will be automatically started when you read the
337-
flash messages even if none already exists. To avoid that default
338-
behavior, test if there is an existing session first::
339-
340-
if ($session->isStarted()) {
341-
foreach ($session->getFlashBag()->get('warning', array()) as $message) {
342-
echo "<div class='flash-warning'>$message</div>";
343-
}
344-
}

components/intl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ expose them manually by adding the following lines to your autoload code::
137137
Writing and Reading Resource Bundles
138138
------------------------------------
139139

140-
The :phpclass:`ResourceBundle` class is not currently supporting by this component.
140+
The :phpclass:`ResourceBundle` class is not currently supported by this component.
141141
Instead, it includes a set of readers and writers for reading and writing
142142
arrays (or array-like objects) from/to resource bundle files. The following
143143
classes are supported:

0 commit comments

Comments
 (0)
0