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

Appearance settings

Commit 7f2450a

Browse filesBrowse files
committed
Merge branch '2.0'
Conflicts: book/doctrine.rst
2 parents 99698bd + ff548b2 commit 7f2450a
Copy full SHA for 7f2450a

File tree

Expand file treeCollapse file tree

18 files changed

+252
-131
lines changed
Filter options
Expand file treeCollapse file tree

18 files changed

+252
-131
lines changed

‎book/doctrine.rst

Copy file name to clipboardExpand all lines: book/doctrine.rst
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ see the :ref:`book-doctrine-field-types` section.
249249
class name is ``Group``, then, by default, your table name will be ``group``,
250250
which will cause an SQL error in some engines. See Doctrine's
251251
`Reserved SQL keywords documentation`_ on how to properly escape these
252-
names.
252+
names. Alternatively, if you're free to choose your database schema,
253+
simply map to a different table name or column name. See Doctrine's
254+
`Persistent classes`_ and `Property Mapping`_ documentation.
253255

254256
.. note::
255257

@@ -1384,3 +1386,5 @@ For more information about Doctrine, see the *Doctrine* section of the
13841386
.. _`Property Mapping documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping
13851387
.. _`Lifecycle Events documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events
13861388
.. _`Reserved SQL keywords documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#quoting-reserved-words
1389+
.. _`Persistent classes`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#persistent-classes
1390+
.. _`Property Mapping`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping

‎book/translation.rst

Copy file name to clipboardExpand all lines: book/translation.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ locale to use for translation:
848848
'fr_FR',
849849
);
850850
851-
$this->get('translator')->trans(
851+
$this->get('translator')->transChoice(
852852
'{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
853853
10,
854854
array('%count%' => 10),

‎components/console.rst

Copy file name to clipboardExpand all lines: components/console.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Calling a command from another one is straightforward::
345345
// ...
346346
}
347347

348-
First, you :method:`Symfony\\Component\\Console\\Command\\Command::find` the
348+
First, you :method:`Symfony\\Component\\Console\\Application::find` the
349349
command you want to execute by passing the command name.
350350

351351
Then, you need to create a new

‎components/dependency_injection/compilation.rst

Copy file name to clipboardExpand all lines: components/dependency_injection/compilation.rst
+124-4Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Compiling the Container
1+
Compiling the Container
22
=======================
33

44
The service container can be compiled for various reasons. These reasons
@@ -24,16 +24,19 @@ Creating a Compiler Pass
2424

2525
You can also create and register your own compiler passes with the container.
2626
To create a compiler pass it needs to implements the :class:`Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface`
27-
interface. The compiler gives you an opportunity to manipulate the service
27+
interface. The compiler pass gives you an opportunity to manipulate the service
2828
definitions that have been compiled. This can be very powerful, but is not
2929
something needed in everyday use.
3030

3131
The compiler pass must have the ``process`` method which is passed the container
3232
being compiled::
3333

34-
public function process(ContainerBuilder $container)
34+
class CustomCompilerPass
3535
{
36-
//--
36+
public function process(ContainerBuilder $container)
37+
{
38+
//--
39+
}
3740
}
3841

3942
The container's parameters and definitions can be manipulated using the
@@ -42,6 +45,43 @@ One common thing to do in a compiler pass is to search for all services that
4245
have a certain tag in order to process them in some way or dynamically plug
4346
each into some other service.
4447

48+
Registering a Compiler Pass
49+
---------------------------
50+
51+
You need to register your custom pass with the container. Tts process method
52+
will then be called when the container is compiled::
53+
54+
use Symfony\Component\DependencyInjection\ContainerBuilder;
55+
56+
$container = new ContainerBuilder();
57+
$container->addCompilerPass(new CustomCompilerPass);
58+
59+
Controlling the Pass Ordering
60+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
62+
The default compiler passes are grouped into optimization passes and removal
63+
passes. The optimization passes run first and include tasks such as resolving
64+
references within the definitions. The removal passes perform tasks such as removing
65+
private aliases and unused services. You can choose where in the order any custom
66+
passes you add are run. By default they will be run before the optimization passes.
67+
68+
You can use the following constants as the second argument when registering
69+
a pass with the container to control where it goes in the order:
70+
71+
* ``PassConfig::TYPE_BEFORE_OPTIMIZATION``
72+
* ``PassConfig::TYPE_OPTIMIZE``
73+
* ``PassConfig::TYPE_BEFORE_REMOVING``
74+
* ``PassConfig::TYPE_REMOVE``
75+
* ``PassConfig::TYPE_AFTER_REMOVING``
76+
77+
For example, to run your custom pass after the default removal passes have been run::
78+
79+
use Symfony\Component\DependencyInjection\ContainerBuilder;
80+
81+
$container = new ContainerBuilder();
82+
$container->addCompilerPass(new CustomCompilerPass, PassConfig::TYPE_AFTER_REMOVING);
83+
84+
4585
Managing Configuration with Extensions
4686
--------------------------------------
4787

@@ -69,3 +109,83 @@ but are processed when the container's ``compile`` method is called.
69109
You should instead use a compiler pass which works with the full container
70110
after the extensions have been processed.
71111

112+
Dumping the Configuration for Performance
113+
-----------------------------------------
114+
115+
Using configuration files to manage the service container can be much easier
116+
to understand than using PHP once there are a lot of services. This ease comes
117+
at a price though when it comes to performance as the config files need to be
118+
parsed and the PHP configuration built from them. The compilation process makes
119+
the container more efficient but it takes time to run. You can have the best of both
120+
worlds though by using configuration files and then dumping and caching the resulting
121+
configuration. The ``PhpDumper`` makes dumping the compiled container easy::
122+
123+
use Symfony\Component\DependencyInjection\ContainerBuilder;
124+
use Symfony\Component\Config\FileLocator;
125+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
126+
use Symfony\Component\DependencyInjection\Dumper\PhpDumper
127+
128+
$container = new ContainerBuilder();
129+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__));
130+
$loader->load('services.xml');
131+
132+
$file = __DIR__ .'/cache/container.php';
133+
134+
if (file_exists($file)) {
135+
require_once $file;
136+
$container = new ProjectServiceContiner();
137+
} else {
138+
$container = new ContainerBuilder();
139+
//--
140+
$container->compile();
141+
142+
$dumper = new PhpDumper($container);
143+
file_put_contents($file, $dumper->dump());
144+
}
145+
146+
``ProjectServiceContiner`` is the default name given to the dumped container
147+
class, you can change this though this with the ``class`` option when you dump
148+
it::
149+
150+
// ...
151+
$file = __DIR__ .'/cache/container.php';
152+
153+
if (file_exists($file)) {
154+
require_once $file;
155+
$container = new MyCachedContainer();
156+
} else {
157+
$container = new ContainerBuilder();
158+
//--
159+
$container->compile();
160+
161+
$dumper = new PhpDumper($container);
162+
file_put_contents($file, $dumper->dump(array('class' => 'MyCachedContainer')));
163+
}
164+
165+
You will now get the speed of the PHP configured container with the ease of using
166+
configuration files. In the above example you will need to delete the cached
167+
container file whenever you make any changes. Adding a check for a variable that
168+
determines if you are in debug mode allows you to keep the speed of the cached
169+
container in production but getting an up to date configuration whilst developing
170+
your application::
171+
172+
// ...
173+
174+
// set $isDebug based on something in your project
175+
176+
$file = __DIR__ .'/cache/container.php';
177+
178+
if (!$isDebug && file_exists($file)) {
179+
require_once $file;
180+
$container = new MyCachedContainer();
181+
} else {
182+
$container = new ContainerBuilder();
183+
//--
184+
$container->compile();
185+
186+
if(!$isDebug)
187+
$dumper = new PhpDumper($container);
188+
file_put_contents($file, $dumper->dump(array('class' => 'MyCachedContainer')));
189+
}
190+
}
191+

‎components/dependency_injection/index.rst

Copy file name to clipboardExpand all lines: components/dependency_injection/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
introduction
88
definitions
99
compilation
10+
tags
1011
factories
1112
parentservices
1213

‎components/dependency_injection/introduction.rst

Copy file name to clipboardExpand all lines: components/dependency_injection/introduction.rst
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,3 @@ your application::
357357
file_put_contents($file, $dumper->dump(array('class' => 'MyCachedContainer')));
358358
}
359359
}
360-
361-
Learn more about this Component
362-
-------------------------------
363-
364-
* :doc:`/components/dependency_injection/definitions`
365-
* :doc:`/components/dependency_injection/factories`
366-
* :doc:`/components/dependency_injection/parentservices`

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.