Skip to content

Commit 71bedb0

Browse files
committed
Merge branch '2.2' into 2.3
Conflicts: reference/constraints/Max.rst reference/constraints/MaxLength.rst reference/constraints/Min.rst reference/constraints/MinLength.rst
2 parents 8e1553e + bd63f26 commit 71bedb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+752
-327
lines changed

book/installation.rst

+13-25
Original file line numberDiff line numberDiff line change
@@ -225,48 +225,36 @@ If there are any issues, correct them now before moving on.
225225
line user, you can run the following commands just once in your project
226226
to ensure that permissions will be setup properly.
227227

228-
**Note that not all web servers run as the user** ``www-data`` as in the examples
229-
below. Instead, check which user *your* web server is being run as and
230-
use it in place of ``www-data``.
231-
232-
On a UNIX system, this can be done with one of the following commands:
233-
234-
.. code-block:: bash
235-
236-
$ ps aux | grep httpd
237-
238-
or
239-
240-
.. code-block:: bash
241-
242-
$ ps aux | grep apache
243-
244228
**1. Using ACL on a system that supports chmod +a**
245229

246230
Many systems allow you to use the ``chmod +a`` command. Try this first,
247-
and if you get an error - try the next method. Be sure to replace ``www-data``
248-
with your web server user on the first ``chmod`` command:
231+
and if you get an error - try the next method. This uses a command to
232+
try to determine your web server user and set is as ``APACHEUSER``:
249233

250234
.. code-block:: bash
251235
252236
$ rm -rf app/cache/*
253237
$ rm -rf app/logs/*
254238
255-
$ sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
256-
$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
239+
$ APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
240+
$ sudo chmod +a "$APACHEUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
241+
$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
242+
257243

258244
**2. Using Acl on a system that does not support chmod +a**
259245

260246
Some systems don't support ``chmod +a``, but do support another utility
261247
called ``setfacl``. You may need to `enable ACL support`_ on your partition
262-
and install setfacl before using it (as is the case with Ubuntu), like
263-
so:
248+
and install setfacl before using it (as is the case with Ubuntu). This
249+
uses a command to try to determine your web server user and set is as
250+
``APACHEUSER``:
264251

265252
.. code-block:: bash
266253
267-
$ sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
268-
$ sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
269-
254+
$ APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
255+
$ sudo setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
256+
$ sudo setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
257+
270258
**3. Without using ACL**
271259

272260
If you don't have access to changing the ACL of the directories, you will

book/templating.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ Debugging
13981398

13991399
When using PHP, you can use ``var_dump()`` if you need to quickly find the
14001400
value of a variable passed. This is useful, for example, inside your controller.
1401-
The same can be achieved when using Twig thanks to the the debug extension.
1401+
The same can be achieved when using Twig thanks to the debug extension.
14021402

14031403
Template parameters can then be dumped using the ``dump`` function:
14041404

book/translation.rst

+3
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ Symfony2 will discover these files and use them when translating either
470470
.. index::
471471
single: Translations; Message domains
472472

473+
474+
.. _using-message-domains:
475+
473476
Using Message Domains
474477
---------------------
475478

book/validation.rst

+128
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,134 @@ In this example, it will first validate all constraints in the group ``User``
930930
(which is the same as the ``Default`` group). Only if all constraints in
931931
that group are valid, the second group, ``Strict``, will be validated.
932932

933+
Group Sequence Providers
934+
~~~~~~~~~~~~~~~~~~~~~~~~
935+
936+
Imagine a ``User`` entity which can be a normal user or a premium user. When
937+
it's a premium user, some extra constraints should be added to the user entity
938+
(e.g. the credit card details). To dynamically determine which groups should
939+
be activated, you can create a Group Sequence Provider. First, create the
940+
entity and a new constraint group called ``Premium``:
941+
942+
.. configuration-block::
943+
944+
.. code-block:: php-annotations
945+
946+
// src/Acme/DemoBundle/Entity/User.php
947+
namespace Acme\DemoBundle\Entity;
948+
949+
use Symfony\Component\Validator\Constraints as Assert;
950+
951+
class User
952+
{
953+
// ...
954+
955+
/**
956+
* @Assert\NotBlank()
957+
*/
958+
private $name;
959+
960+
/**
961+
* @Assert\CardScheme(
962+
* schemes={"VISA"},
963+
* groups={"Premium"},
964+
* )
965+
*/
966+
private $creditCard;
967+
}
968+
969+
.. code-block:: yaml
970+
971+
# src/Acme/DemoBundle/Resources/config/validation.yml
972+
Acme\DemoBundle\Entity\User:
973+
properties:
974+
name:
975+
- NotBlank
976+
creditCard:
977+
- CardScheme
978+
schemes: [VISA]
979+
groups: [Premium]
980+
981+
.. code-block:: xml
982+
983+
<!-- src/Acme/DemoBundle/Resources/config/validation.xml -->
984+
<class name="Acme\DemoBundle\Entity\User">
985+
<property name="name">
986+
<constraint name="NotBlank" />
987+
</property>
988+
989+
<property name="creditCard">
990+
<constraint name="CardScheme">
991+
<option name="schemes">
992+
<value>VISA</value>
993+
</option>
994+
<option name="groups">
995+
<value>Premium</value>
996+
</option>
997+
</constraint>
998+
</property>
999+
</class>
1000+
1001+
.. code-block:: php
1002+
1003+
// src/Acme/DemoBundle/Entity/User.php
1004+
namespace Acme\DemoBundle\Entity;
1005+
1006+
use Symfony\Component\Validator\Constraints as Assert;
1007+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1008+
1009+
class User
1010+
{
1011+
private $name;
1012+
private $creditCard;
1013+
1014+
// ...
1015+
1016+
public static function loadValidatorMetadata(ClassMetadata $metadata)
1017+
{
1018+
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
1019+
$metadata->addPropertyConstraint('creditCard', new Assert\CardScheme(
1020+
'schemes' => array('VISA'),
1021+
'groups' => array('Premium'),
1022+
));
1023+
}
1024+
}
1025+
1026+
Now, change the ``User`` class to implement
1027+
:class:`Symfony\\Component\\Validation\\GroupSequenceProviderInterface` and
1028+
add the
1029+
:method:`Symfony\\Component\\Validation\\GroupSequenceProviderInterface::getGroupSequence`,
1030+
which should return an array of groups to use. Also, add the
1031+
``@Assert\GroupSequenceProvider`` annotation to the class. If you imagine
1032+
that a method called ``isPremium`` returns true if the user is a premium member,
1033+
then your code might look like this::
1034+
1035+
// src/Acme/DemoBundle/Entity/User.php
1036+
namespace Acme\DemoBundle\Entity;
1037+
1038+
// ...
1039+
use Symfony\Component\Validation\GroupSequenceProviderInterface;
1040+
1041+
/**
1042+
* @Assert\GroupSequenceProvider
1043+
* ...
1044+
*/
1045+
class User implements GroupSequenceProviderInterface
1046+
{
1047+
// ...
1048+
1049+
public function getGroupSequence()
1050+
{
1051+
$groups = array('User');
1052+
1053+
if ($this->isPremium()) {
1054+
$groups[] = 'Premium';
1055+
}
1056+
1057+
return $groups;
1058+
}
1059+
}
1060+
9331061
.. _book-validation-raw-values:
9341062

9351063
Validating Values and Arrays

components/console/introduction.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,4 @@ Learn More!
492492
* :doc:`/components/console/single_command_tool`
493493

494494
.. _Packagist: https://packagist.org/packages/symfony/console
495-
.. _ANSICON: http://adoxa.3eeweb.com/ansicon/
495+
.. _ANSICON: https://github.com/adoxa/ansicon/downloads

components/dom_crawler.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ and :phpclass:`DOMNode` objects:
205205
$crawler->addNode($node);
206206
$crawler->add($document);
207207
208-
.. component-dom-crawler-dumping:
208+
.. _component-dom-crawler-dumping:
209209

210210
.. sidebar:: Manipulating and Dumping a ``Crawler``
211211

components/http_kernel/introduction.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ For general information on adding listeners to the events below, see
128128

129129
**Typical Purposes**: To add more information to the ``Request``, initialize
130130
parts of the system, or return a ``Response`` if possible (e.g. a security
131-
layer that denies access)
131+
layer that denies access).
132132

133133
:ref:`Kernel Events Information Table<component-http-kernel-event-table>`
134134

components/security/firewall.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,28 @@ steps in the process of authenticating the user have been taken successfully,
1010
you can ask the security context if the authenticated user has access to a
1111
certain action or resource of the application::
1212

13-
use Symfony\Component\Security\SecurityContext;
13+
use Symfony\Component\Security\Core\SecurityContext;
1414
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
15+
16+
// instance of Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
17+
$authenticationManager = ...;
1518

16-
$securityContext = new SecurityContext();
19+
// instance of Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
20+
$accessDecisionManager = ...;
21+
22+
$securityContext = new SecurityContext($authenticationManager, $accessDecisionManager);
1723

1824
// ... authenticate the user
1925

2026
if (!$securityContext->isGranted('ROLE_ADMIN')) {
2127
throw new AccessDeniedException();
2228
}
2329

30+
.. note::
31+
32+
Read the dedicated sections to learn more about :doc:`/components/security/authentication`
33+
and :doc:`/components/security/authorization`.
34+
2435
.. _firewall:
2536

2637
A Firewall for HTTP Requests

cookbook/bundles/override.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Translations
129129

130130
Translations are not related to bundles, but to domains. That means that you
131131
can override the translations from any translation file, as long as it is in
132-
:ref:`the correct domain <translation-domains>`.
132+
:ref:`the correct domain <using-message-domains>`.
133133

134134
.. caution::
135135

cookbook/cache/varnish.rst

+31
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,36 @@ that will invalidate the cache for a given resource:
176176
}
177177
}
178178
179+
Routing and X-FORWARDED Headers
180+
-------------------------------
181+
182+
To ensure that the Symfony Router generates urls correctly with Varnish,
183+
proper ```X-Forwarded``` headers must be added so that Symfony is aware of
184+
the original port number of the request. Exactly how this is done depends
185+
on your setup. As a simple example, Varnish and your web server are on the
186+
same machine and that Varnish is listening on one port (e.g. 80) and Apache
187+
on another (e.g. 8080). In this situation, Varnish should add the ``X-Forwarded-Port``
188+
header so that the Symfony application knows that the original port number
189+
is 80 and not 8080.
190+
191+
If this header weren't set properly, Symfony may append ``8080`` when generating
192+
absolute URLs:
193+
194+
.. code-block:: text
195+
196+
sub vcl_recv {
197+
if (req.http.X-Forwarded-Proto == "https" ) {
198+
set req.http.X-Forwarded-Port = "443";
199+
} else {
200+
set req.http.X-Forwarded-Port = "80"
201+
}
202+
}
203+
204+
.. note::
205+
206+
Remember to configure :ref:`framework.trusted_proxies<reference-framework-trusted-proxies>`
207+
in the Symfony configuration so that Varnish is seen as a trusted proxy
208+
and the ``X-Forwarded-`` headers are used.
209+
179210
.. _`Edge Architecture`: http://www.w3.org/TR/edge-arch
180211
.. _`GZIP and Varnish`: https://www.varnish-cache.org/docs/3.0/phk/gzip.html

cookbook/form/dynamic_form_modification.rst

+2
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ The subscriber would now look like::
473473
use Symfony\Component\Form\FormFactoryInterface;
474474
use Doctrine\ORM\EntityManager;
475475
use Symfony\Component\Form\FormEvent;
476+
use Symfony\Component\Form\FormEvents;
477+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
476478

477479
class RegistrationSportListener implements EventSubscriberInterface
478480
{

cookbook/form/form_collections.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,12 @@ for the tags in the ``Task`` class::
423423
{
424424
// ...
425425

426-
public function addTag($tag)
426+
public function addTag(Tag $tag)
427427
{
428428
$this->tags->add($tag);
429429
}
430430

431-
public function removeTag($tag)
431+
public function removeTag(Tag $tag)
432432
{
433433
// ...
434434
}
@@ -534,7 +534,7 @@ we talk about next!).
534534
// src/Acme/TaskBundle/Entity/Task.php
535535

536536
// ...
537-
public function addTag(ArrayCollection $tag)
537+
public function addTag(Tag $tag)
538538
{
539539
$tag->addTask($this);
540540

@@ -588,7 +588,7 @@ Now, you need to put some code into the ``removeTag`` method of ``Task``::
588588
{
589589
// ...
590590

591-
public function removeTag($tag)
591+
public function removeTag(Tag $tag)
592592
{
593593
$this->tags->removeElement($tag);
594594
}

cookbook/security/custom_authentication_provider.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ set an authenticated token in the security context if successful.
144144
// ... you might log something here
145145
146146
// To deny the authentication clear the token. This will redirect to the login page.
147-
// $this->securityContext->setToken(null);
147+
// Make sure to only clear your token, not those of other authentication listeners.
148+
// $token = $this->securityContext->getToken();
149+
// if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
150+
// $this->securityContext->setToken(null);
151+
// }
148152
// return;
149153
150154
// Deny authentication with a '403 Forbidden' HTTP response

reference/configuration/framework.rst

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ services related to testing your application (e.g. ``test.client``) are loaded.
114114
This setting should be present in your ``test`` environment (usually via
115115
``app/config/config_test.yml``). For more information, see :doc:`/book/testing`.
116116

117+
.. _reference-framework-trusted-proxies:
118+
117119
trusted_proxies
118120
~~~~~~~~~~~~~~~
119121

0 commit comments

Comments
 (0)