Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 232525f

Browse files
committed
Merge branch '2.2'
2 parents bbdc8ce + 0dd0042 commit 232525f

25 files changed

+420
-204
lines changed

book/doctrine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ to easily fetch objects based on multiple conditions::
602602
$product = $repository->findOneBy(array('name' => 'foo', 'price' => 19.99));
603603

604604
// query for all products matching the name, ordered by price
605-
$product = $repository->findBy(
605+
$products = $repository->findBy(
606606
array('name' => 'foo'),
607607
array('price' => 'ASC')
608608
);

book/http_cache.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,10 @@ Here is how you can configure the Symfony2 reverse proxy to support the
10341034

10351035
class AppCache extends HttpCache
10361036
{
1037-
protected function invalidate(Request $request)
1037+
protected function invalidate(Request $request, $catch = false)
10381038
{
10391039
if ('PURGE' !== $request->getMethod()) {
1040-
return parent::invalidate($request);
1040+
return parent::invalidate($request, $catch);
10411041
}
10421042

10431043
$response = new Response();

book/routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ Take a quick look at the routes that have been created so far:
479479
480480
return $collection;
481481
482-
Can you spot the problem? Notice that both routes have paths that match
482+
Can you spot the problem? Notice that both routes have patterns that match
483483
URL's that look like ``/blog/*``. The Symfony router will always choose the
484484
**first** matching route it finds. In other words, the ``blog_show`` route
485485
will *never* be matched. Instead, a URL like ``/blog/my-blog-post`` will match

book/service_container.rst

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ container and customizing objects from any third-party bundle. You'll begin
2828
writing code that is more reusable, testable and decoupled, simply because
2929
the service container makes writing good code so easy.
3030

31+
.. tip::
32+
33+
If you want to know a lot more after reading this chapter, check out
34+
the :doc:`Dependency Injection Component Documentation</components/dependency_injection/introduction>`.
35+
3136
.. index::
3237
single: Service Container; What is a service?
3338

@@ -222,15 +227,6 @@ The end result is exactly the same as before - the difference is only in
222227
to look for parameters with those names. When the container is built, it
223228
looks up the value of each parameter and uses it in the service definition.
224229

225-
.. note::
226-
227-
The percent sign inside a parameter or argument, as part of the string, must
228-
be escaped with another percent sign:
229-
230-
.. code-block:: xml
231-
232-
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
233-
234230
The purpose of parameters is to feed information into services. Of course
235231
there was nothing wrong with defining the service without using any parameters.
236232
Parameters, however, have several advantages:
@@ -251,60 +247,7 @@ however, you may not need the flexibility of parameters.
251247
Array Parameters
252248
~~~~~~~~~~~~~~~~
253249

254-
Parameters do not need to be flat strings, they can also be arrays. For the XML
255-
format, you need to use the type="collection" attribute for all parameters that are
256-
arrays.
257-
258-
.. configuration-block::
259-
260-
.. code-block:: yaml
261-
262-
# app/config/config.yml
263-
parameters:
264-
my_mailer.gateways:
265-
- mail1
266-
- mail2
267-
- mail3
268-
my_multilang.language_fallback:
269-
en:
270-
- en
271-
- fr
272-
fr:
273-
- fr
274-
- en
275-
276-
.. code-block:: xml
277-
278-
<!-- app/config/config.xml -->
279-
<parameters>
280-
<parameter key="my_mailer.gateways" type="collection">
281-
<parameter>mail1</parameter>
282-
<parameter>mail2</parameter>
283-
<parameter>mail3</parameter>
284-
</parameter>
285-
<parameter key="my_multilang.language_fallback" type="collection">
286-
<parameter key="en" type="collection">
287-
<parameter>en</parameter>
288-
<parameter>fr</parameter>
289-
</parameter>
290-
<parameter key="fr" type="collection">
291-
<parameter>fr</parameter>
292-
<parameter>en</parameter>
293-
</parameter>
294-
</parameter>
295-
</parameters>
296-
297-
.. code-block:: php
298-
299-
// app/config/config.php
300-
use Symfony\Component\DependencyInjection\Definition;
301-
302-
$container->setParameter('my_mailer.gateways', array('mail1', 'mail2', 'mail3'));
303-
$container->setParameter('my_multilang.language_fallback', array(
304-
'en' => array('en', 'fr'),
305-
'fr' => array('fr', 'en'),
306-
));
307-
250+
Parameters can also contain array values. See :ref:`component-di-parameters-array`.
308251

309252
Importing other Container Configuration Resources
310253
-------------------------------------------------
@@ -965,6 +908,7 @@ its id:
965908
Learn more
966909
----------
967910

911+
* :doc:`/components/dependency_injection/parameters`
968912
* :doc:`/components/dependency_injection/compilation`
969913
* :doc:`/components/dependency_injection/definitions`
970914
* :doc:`/components/dependency_injection/factories`

book/translation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ You can also specify the message domain and pass some additional variables:
775775
{% trans with {'%name%': 'Fabien'} from "app" into "fr" %}Hello %name%{% endtrans %}
776776
777777
{% transchoice count with {'%name%': 'Fabien'} from "app" %}
778-
{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples
778+
{0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf] %name%, there are %count% apples
779779
{% endtranschoice %}
780780
781781
.. _book-translation-filters:

book/validation.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ into a database or passed to a web service.
1010

1111
Symfony2 ships with a `Validator`_ component that makes this task easy and
1212
transparent. This component is based on the
13-
`JSR303 Bean Validation specification`_. What? A Java specification in PHP?
14-
You heard right, but it's not as bad as it sounds. Let's look at how it
15-
can be used in PHP.
13+
`JSR303 Bean Validation specification`_.
1614

1715
.. index::
1816
single: Validation; The basics

components/config/definition.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ The separator used in keys is typically ``_`` in Yaml and ``-`` in XML. For
382382
example, ``auto_connect`` in Yaml and ``auto-connect``. The normalization would
383383
make both of these ``auto_connect``.
384384

385+
.. caution::
386+
387+
The target key will not be altered if it's mixed like
388+
``foo-bar_moo`` or if it already exists.
389+
385390
Another difference between Yaml and XML is in the way arrays of values may
386391
be represented. In Yaml you may have:
387392

components/dependency_injection/definitions.rst

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,13 @@
22
single: Dependency Injection; Service definitions
33

44

5-
Working with Container Parameters and Definitions
6-
=================================================
7-
8-
Getting and Setting Container Parameters
9-
----------------------------------------
10-
11-
Working with container parameters is straight forward using the container's
12-
accessor methods for parameters. You can check if a parameter has been defined
13-
in the container with::
14-
15-
$container->hasParameter($name);
16-
17-
You can retrieve parameters set in the container with::
18-
19-
$container->getParameter($name);
20-
21-
and set a parameter in the container with::
22-
23-
$container->setParameter($name, $value);
5+
Working with Container Service Definitions
6+
==========================================
247

258
Getting and Setting Service Definitions
269
---------------------------------------
2710

28-
There are also some helpful methods for
29-
working with the service definitions.
11+
There are some helpful methods for working with the service definitions.
3012

3113
To find out if there is a definition for a service id::
3214

@@ -137,3 +119,10 @@ You can also replace any existing method calls with an array of new ones with::
137119
in the PHP code blocks of the configuration examples on pages such as
138120
:doc:`/components/dependency_injection/factories` and
139121
:doc:`/components/dependency_injection/parentservices`.
122+
123+
.. note::
124+
125+
The methods here that change service definitions can only be used before
126+
the container is compiled, once the container is compiled you cannot
127+
manipulate service definitions further. To learn more about compiling
128+
the container see :doc:`/components/dependency_injection/compilation`.

components/dependency_injection/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
introduction
88
types
9+
parameters
910
definitions
1011
compilation
1112
tags

components/dependency_injection/introduction.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ You could then get your ``newsletter_manager`` service from the container
153153
like this::
154154

155155
use Symfony\Component\DependencyInjection\ContainerBuilder;
156-
use Symfony\Component\DependencyInjection\Reference;
157156

158157
$container = new ContainerBuilder();
159158

@@ -179,8 +178,13 @@ should be as few times as possible at the entry point to your application.
179178
Setting Up the Container with Configuration Files
180179
-------------------------------------------------
181180

182-
As well as setting up the services using PHP as above you can also use configuration
183-
files. To do this you also need to install :doc:`the Config Component</components/config/introduction>`.
181+
As well as setting up the services using PHP as above you can also use
182+
configuration files. This allows you to use XML or Yaml to write the definitions
183+
for the services rather than using PHP to define the services as in the above
184+
examples. In anything but the smallest applications it make sense to organize
185+
the service definitions by moving them into one or more configuration files.
186+
To do this you also need to install
187+
:doc:`the Config Component</components/config/introduction>`.
184188

185189
Loading an XML config file::
186190

@@ -207,13 +211,24 @@ Loading a YAML config file::
207211
If you want to load YAML config files then you will also need to install
208212
:doc:`The YAML component</components/yaml/introduction>`.
209213

210-
The ``newsletter_manager`` and ``mailer`` services can be set up using config files:
214+
If you *do* want to use PHP to create the services then you can move this
215+
into a separate config file and load it in a similar way::
216+
217+
use Symfony\Component\DependencyInjection\ContainerBuilder;
218+
use Symfony\Component\Config\FileLocator;
219+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
220+
221+
$container = new ContainerBuilder();
222+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__));
223+
$loader->load('services.php');
224+
225+
You can now set up the ``newsletter_manager`` and ``mailer`` services using
226+
config files:
211227

212228
.. configuration-block::
213229

214230
.. code-block:: yaml
215231
216-
# src/Acme/HelloBundle/Resources/config/services.yml
217232
parameters:
218233
# ...
219234
mailer.transport: sendmail
@@ -229,7 +244,6 @@ The ``newsletter_manager`` and ``mailer`` services can be set up using config fi
229244
230245
.. code-block:: xml
231246
232-
<!-- src/Acme/HelloBundle/Resources/config/services.xml -->
233247
<parameters>
234248
<!-- ... -->
235249
<parameter key="mailer.transport">sendmail</parameter>

0 commit comments

Comments
 (0)