Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f83193

Browse files
committed
Merge branch '4.2'
* 4.2: [Flex] Replace `SYMFONY_*` env vars with `APP_*` [Validator] Added documentation for Traverse constraint added requirements for {_format}
2 parents337a9e2 +765d692 commit3f83193

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

‎reference/constraints/Traverse.rst‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Traverse
2+
========
3+
4+
Objects do not validate nested objects by default unless explicitly using
5+
this constraint.
6+
If only specific nested objects should be validated by cascade, consider
7+
using the:doc:`references/constraints/Valid` instead.
8+
9+
+----------------+-------------------------------------------------------------------------------------+
10+
| Applies to|:ref:`class<validation-class-target>`|
11+
+----------------+-------------------------------------------------------------------------------------+
12+
| Options| - `payload`_|
13+
+----------------+-------------------------------------------------------------------------------------+
14+
| Class|:class:`Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\Traverse`|
15+
+----------------+-------------------------------------------------------------------------------------+
16+
17+
Basic Usage
18+
-----------
19+
20+
In the following example, create three classes ``Book``, ``Author`` and
21+
``Editor`` that all have constraints on their properties. Furthermore,
22+
``Book`` stores an ``Author`` and an ``Editor`` instance that must be
23+
valid too. Instead of adding the ``Valid`` constraint to both fields,
24+
configure the ``Traverse`` constraint on the ``Book`` class.
25+
26+
..configuration-block::
27+
28+
..code-block::php-annotations
29+
30+
// src/AppBundle/Entity/Book.php
31+
namespace AppBundle\Entity;
32+
33+
use Symfony\Component\Validator\Constraints as Assert;
34+
use Doctrine\ORM\Mapping as ORM;
35+
36+
/**
37+
* @ORM\Entity
38+
* @Assert\Traverse
39+
*/
40+
class Book
41+
{
42+
/**
43+
* @var Author
44+
*
45+
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Author")
46+
*/
47+
protected $author;
48+
49+
/**
50+
* @var Editor
51+
*
52+
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Editor")
53+
*/
54+
protected $editor;
55+
56+
// ...
57+
}
58+
59+
..code-block::yaml
60+
61+
# src/AppBundle/Resources/config/validation.yml
62+
AppBundle\Entity\Book:
63+
constraints:
64+
-Symfony\Component\Validator\Constraints\Traverse:~
65+
66+
..code-block::xml
67+
68+
<!-- src/AppBundle/Resources/config/validation.xml-->
69+
<?xml version="1.0" encoding="UTF-8" ?>
70+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
71+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
73+
74+
<classname="AppBundle\Entity\Book">
75+
<constraintname="Symfony\Component\Validator\Constraints\Traverse"/>
76+
</class>
77+
</constraint-mapping>
78+
79+
..code-block::php
80+
81+
// src/AppBundle/Entity/Book.php
82+
namespace AppBundle\Entity;
83+
84+
use Symfony\Component\Validator\Constraints as Assert;
85+
use Symfony\Component\Validator\Mapping\ClassMetadata;
86+
87+
class Book
88+
{
89+
public static function loadValidatorMetadata(ClassMetadata $metadata)
90+
{
91+
$metadata->addConstraint(new Assert\Traverse());
92+
}
93+
}
94+
95+
Options
96+
-------
97+
98+
..include::/reference/constraints/_payload-option.rst.inc

‎setup/flex.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ manual steps:
257257
#. Move the source of the assets (e.g. the SCSS files) to ``assets/`` and use
258258
:doc:`Webpack Encore</frontend>` to manage and compile them.
259259

260+
#. ``SYMFONY_DEBUG`` and ``SYMFONY_ENV`` environment variables were replaced by
261+
``APP_DEBUG`` and ``APP_ENV``. Copy their values to the new vars and then remove
262+
the former ones.
263+
260264
#. Create the new ``public/index.php`` front controller
261265
`copying Symfony's index.php source`_ and, if you made any customization in
262266
your ``web/app.php`` and ``web/app_dev.php`` files, copy those changes into
@@ -267,6 +271,10 @@ manual steps:
267271

268272
#. Remove ``src/AppBundle/``.
269273

274+
#. Move the original source code from ``src/{App,...}Bundle/`` to ``src/`` and
275+
update the namespaces of every PHP file to be ``App\...`` (advanced IDEs can do
276+
this automatically).
277+
270278
#. Remove the ``bin/symfony_requirements`` script and if you need a replacement
271279
for it, use the new `Symfony Requirements Checker`_.
272280

‎templating/formats.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ be configured so that ``/about-us`` sets the request format to ``html`` while
5151
special ``_format`` placeholder in your route definition::
5252

5353
/**
54-
* @Route("/{slug}.{_format}", defaults={"_format"="html"})
54+
* @Route("/{slug}.{_format}", defaults={"_format"="html"}, requirements={"_format"="html|xml"}))
5555
*/
5656
public function show(Request $request, $slug)
5757
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp