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

Commit8e5caca

Browse files
committed
Merge branch '2.1' into 2.2
Conflicts:components/event_dispatcher/introduction.rstcookbook/symfony1.rst
2 parents43dd04a +960bb9f commit8e5caca

File tree

7 files changed

+164
-14
lines changed

7 files changed

+164
-14
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
..index::
2+
single: Event Dispatcher; Immutable
3+
4+
The Immutable Event Dispatcher
5+
==============================
6+
7+
..versionadded::2.1
8+
This feature was added in Symfony 2.1.
9+
10+
The:class:`Symfony\\Component\\EventDispatcher\\ImmutableEventDispatcher` is
11+
a locked or frozen event dispatcher. The dispatcher cannot register new
12+
listeners or subscribers.
13+
14+
The ``ImmutableEventDispatcher`` takes another event dispatcher with all the
15+
listeners and subscribers. The immutable dispatcher is just a proxy of this
16+
original dispatcher.
17+
18+
To use it, first create a normal dispatcher (``EventDispatcher`` or
19+
``ContainerAwareEventDispatcher``) and register some listeners or
20+
subscribers::
21+
22+
use Symfony\Component\EventDispatcher\EventDispatcher;
23+
24+
$dispatcher = new EventDispatcher();
25+
$dispatcher->addListener('foo.action', function ($event) {
26+
// ...
27+
});
28+
29+
// ...
30+
31+
Now, inject that into an ``ImmutableEventDispatcher``::
32+
33+
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
34+
// ...
35+
36+
$immutableDispatcher = new ImmutableEventDispatcher($dispatcher);
37+
38+
You'll need to use this new dispatcher in your project.
39+
40+
If you are trying to execute one of the methods which modifies the dispatcher
41+
(e.g. ``addListener``), a ``BadMethodCallException`` is thrown.

‎components/event_dispatcher/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ Event Dispatcher
55
:maxdepth:2
66

77
introduction
8-
generic_event
98
container_aware_dispatcher
9+
generic_event
10+
immutable_dispatcher

‎components/event_dispatcher/introduction.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,15 @@ part of the listener's processing logic::
597597
}
598598
}
599599

600+
Other Dispatchers
601+
-----------------
602+
603+
Besides the commonly used ``EventDispatcher``, the component comes with 2
604+
other dispatchers:
605+
606+
*:doc:`/components/event_dispatcher/container_aware_dispatcher`
607+
*:doc:`/components/event_dispatcher/immutable_dispatcher`
608+
600609
.. _Mediator:http://en.wikipedia.org/wiki/Mediator_pattern
601610
.. _Closures:http://php.net/manual/en/functions.anonymous.php
602611
.. _PHP callable:http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback

‎components/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* :doc:`/components/event_dispatcher/introduction`
4646
* :doc:`/components/event_dispatcher/container_aware_dispatcher`
4747
* :doc:`/components/event_dispatcher/generic_event`
48+
* :doc:`/components/event_dispatcher/immutable_dispatcher`
4849

4950
***Filesystem**
5051

‎cookbook/symfony1.rst

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ were added or moved.
119119
In Symfony2, a tool named `Composer`_ handles this process.
120120
The idea behind the autoloader is simple: the name of your class (including
121121
the namespace) must match up with the path to the file containing that class.
122-
Take the``FrameworkExtraBundle`` from the Symfony2 Standard Edition as an
122+
Take the FrameworkExtraBundle from the Symfony2 Standard Edition as an
123123
example::
124124

125125
namespace Sensio\Bundle\FrameworkExtraBundle;
@@ -134,26 +134,30 @@ example::
134134

135135
The file itself lives at
136136
``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/SensioFrameworkExtraBundle.php``.
137-
As you can see, the location of the file follows the namespace of the class.
138-
Specifically, the namespace, ``Sensio\Bundle\FrameworkExtraBundle``, spells out
139-
the directory that the file should live in
137+
As you can see, the second part of the path follows the namespace of the
138+
class. The first part is equal to the package name of the SensioFrameworkExtraBundle.
139+
140+
The namespace, ``Sensio\Bundle\FrameworkExtraBundle``, and package name,
141+
``sensio/framework-extra-bundle``, spells out the directory that the file
142+
should live in
140143
(``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/``).
141-
Composer can then look for the file at this specific place and load it very fast.
144+
Composer can then look for the file at this specific place and load it very
145+
fast.
142146

143147
If the file did *not* live at this exact location, you'd receive a
144148
``Class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" does not exist.``
145-
error. In Symfony2, a "class does not exist" means that thesuspect class
146-
namespace and physical location do not match. Basically, Symfony2 is looking
149+
error. In Symfony2, a "class does not exist"errormeans that thenamespace of
150+
the class and physical location do not match. Basically, Symfony2 is looking
147151
in one exact location for that class, but that location doesn't exist (or
148152
contains a different class). In order for a class to be autoloaded, you
149153
**never need to clear your cache** in Symfony2.
150154

151155
As mentioned before, for the autoloader to work, it needs to know that the
152-
``Sensio`` namespace lives in the ``vendor/bundles`` directory and that, for
153-
example, the ``Doctrine`` namespace lives in the ``vendor/doctrine/orm/lib/``
154-
directory. This mapping is entirely controlled by Composer. Each
155-
third-party library you load throughcomposer hastheir settings defined
156-
and Composer takes care of everything for you.
156+
``Sensio`` namespace lives in the ``vendor/sensio/framework-extra-bundle``
157+
directory and that, forexample, the ``Doctrine`` namespace lives in the
158+
``vendor/doctrine/orm/lib/``directory. This mapping is entirely controlled by
159+
Composer. Eachthird-party library you load throughComposer hasits
160+
settings definedand Composer takes care of everything for you.
157161

158162
For this to work, all third-party libraries used by your project must be
159163
defined in the ``composer.json`` file.
@@ -170,6 +174,11 @@ from specific directories without defining a dependency:
170174
"psr-0":{ "": "src/" }
171175
}
172176
177+
This means that if a class is not found in the ``vendor`` directory, Composer
178+
will search in the ``src`` directory before throwing a "class does not exist"
179+
exception. Read more about configuring the Composer Autoloader in
180+
`the Composer documentation`_
181+
173182
Using the Console
174183
-----------------
175184

@@ -357,3 +366,4 @@ the chapter titled ":doc:`/book/service_container`".
357366

358367
.. _`Composer`:http://getcomposer.org
359368
.. _`Symfony2 Standard Edition`:https://github.com/symfony/symfony-standard
369+
.. _`the Composer documentation`:http://getcomposer.org/doc/04-schema.md#autoload

‎reference/configuration/framework.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ gc_maxlifetime
244244
..versionadded::2.1
245245
The ``gc_maxlifetime`` option is new in version 2.1
246246

247-
**type**: ``integer`` **default**: ``14400``
247+
**type**: ``integer`` **default**: ``1440``
248248

249249
This determines the number of seconds after which data will be seen as "garbage"
250250
and potentially cleaned up. Garbage collection may occur during session start

‎reference/constraints/Regex.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Validates that a value matches a regular expression.
77
| Applies to|:ref:`property or method<validation-property-target>`|
88
+----------------+-----------------------------------------------------------------------+
99
| Options| - `pattern`_|
10+
|| - `htmlPattern`_|
1011
|| - `match`_|
1112
|| - `message`_|
1213
+----------------+-----------------------------------------------------------------------+
@@ -173,6 +174,93 @@ does *not* match this regular expression (via the :phpfunction:`preg_match` PHP
173174
However, if `match`_ is set to false, then validation will fail if the input
174175
string *does* match this pattern.
175176

177+
htmlPattern
178+
~~~~~~~~~~~
179+
180+
..versionadded::2.1
181+
The ``htmlPattern`` option was added in Symfony 2.1
182+
183+
**type**: ``string|Boolean`` **default**: null
184+
185+
This option specifies the pattern to use in the HTML5 ``pattern`` attribute.
186+
You usually don't need to specify this option because by default, the constraint
187+
will convert the pattern given in the `pattern`_ option into an HTML5 compatible
188+
pattern. This means that the delimiters are removed (e.g. ``/[a-z]+/`` becomes ``[a-z]+``).
189+
190+
However, there are some other incompatibilities between both patterns which
191+
cannot be fixed by the constraint. For instance, the html5 pattern attribute
192+
does not support flags. If you have a pattern like ``/[a-z]+/i`` you need to
193+
specify the html5 compatible pattern in the ``htmlPattern`` option:
194+
195+
..configuration-block::
196+
197+
..code-block::yaml
198+
199+
# src/Acme/BlogBundle/Resources/config/validation.yml
200+
Acme\BlogBundle\Entity\Author:
201+
properties:
202+
name:
203+
-Regex:
204+
pattern:"/^[a-z]+$/i"
205+
htmlPattern:"^[a-zA-Z]+$"
206+
207+
..code-block::php-annotations
208+
209+
// src/Acme/BlogBundle/Entity/Author.php
210+
namespace Acme\BlogBundle\Entity;
211+
212+
use Symfony\Component\Validator\Constraints as Assert;
213+
214+
class Author
215+
{
216+
/**
217+
* @Assert\Regex({
218+
* pattern = "/^[a-z]+$/i",
219+
* htmlPattern = "^[a-zA-Z]+$"
220+
* })
221+
*/
222+
protected $name;
223+
}
224+
225+
..code-block::xml
226+
227+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml-->
228+
<?xml version="1.0" encoding="UTF-8" ?>
229+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
230+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
231+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
232+
233+
<classname="Acme\BlogBundle\Entity\Author">
234+
<propertyname="name">
235+
<constraintname="Regex">
236+
<optionname="pattern">/^[a-z]+$/i</option>
237+
<optionname="htmlPattern">^[a-zA-Z]+$</option>
238+
</constraint>
239+
</property>
240+
</class>
241+
</constraint-mapping>
242+
243+
..code-block::php
244+
245+
// src/Acme/BlogBundle/Entity/Author.php
246+
namespace Acme\BlogBundle\Entity;
247+
248+
use Symfony\Component\Validator\Mapping\ClassMetadata;
249+
use Symfony\Component\Validator\Constraints as Assert;
250+
251+
class Author
252+
{
253+
public static function loadValidatorMetadata(ClassMetadata $metadata)
254+
{
255+
$metadata->addPropertyConstraint('name', new Assert\Regex(array(
256+
'pattern' => '/^[a-z]+$/i',
257+
'htmlPattern' => '^[a-zA-Z]+$',
258+
)));
259+
}
260+
}
261+
262+
Setting ``htmlPattern`` to false will disable client side validation.
263+
176264
match
177265
~~~~~
178266

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp