Skip to content

Commit 34c1293

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: [#5373] Small tweak per Stof's comment Fixed a minor grammar issue Fixed typos Link to the official repository of the bundle. Added mentions to some popular (and useful) Symfony bundles [#5095] Fixing a typo and updating to a more realistic example [#4228] Move synthetic services to its own recipe clarify bundle installation instructions Implemented the suggestions made by Christian and Wouter Replace phpDocumentor by the standard PHPDoc Implemented the changes suggested by reviewers Fixed an internal link reference Reviewed the Bundles cookbook articles Constraints - empty strings and null values Add a caution to the getUploadRootDir - correction Adding a caution to the getUploadRootDir() method [#4228] Moved requiring files to definitions
2 parents 179526c + c7ec621 commit 34c1293

16 files changed

+190
-156
lines changed

book/security.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ But who can you login as? Where do users come from?
280280
What other methods are supported? See the :doc:`Configuration Reference </reference/configuration/security>`
281281
or :doc:`build your own </cookbook/security/custom_authentication_provider>`.
282282

283+
.. tip::
284+
285+
If your application logs users in via a third-party service such as Google,
286+
Facebook or Twitter, check out the `HWIOAuthBundle`_ community bundle.
287+
283288
.. _security-user-providers:
284289
.. _where-do-users-come-from-user-providers:
285290

@@ -485,7 +490,7 @@ else, you'll want to encode their passwords. The best algorithm to use is
485490
<encoder class="Symfony\Component\Security\Core\User\User"
486491
algorithm="bcrypt"
487492
cost="12" />
488-
493+
489494
<!-- ... -->
490495
</config>
491496
</srv:container>
@@ -1386,3 +1391,4 @@ Learn More from the Cookbook
13861391
.. _`online tool`: https://www.dailycred.com/blog/12/bcrypt-calculator
13871392
.. _`frameworkextrabundle documentation`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
13881393
.. _`security advisories database`: https://github.com/FriendsOfPHP/security-advisories
1394+
.. _`HWIOAuthBundle`: https://github.com/hwi/HWIOAuthBundle

components/dependency_injection/advanced.rst

-96
Original file line numberDiff line numberDiff line change
@@ -73,61 +73,6 @@ below) to access this service (via the alias).
7373

7474
Services are by default public.
7575

76-
Synthetic Services
77-
------------------
78-
79-
Synthetic services are services that are injected into the container instead
80-
of being created by the container.
81-
82-
For example, if you're using the :doc:`HttpKernel </components/http_kernel/introduction>`
83-
component with the DependencyInjection component, then the ``request``
84-
service is injected in the
85-
:method:`ContainerAwareHttpKernel::handle() <Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel::handle>`
86-
method when entering the request :doc:`scope </cookbook/service_container/scopes>`.
87-
The class does not exist when there is no request, so it can't be included in
88-
the container configuration. Also, the service should be different for every
89-
subrequest in the application.
90-
91-
To create a synthetic service, set ``synthetic`` to ``true``:
92-
93-
.. configuration-block::
94-
95-
.. code-block:: yaml
96-
97-
services:
98-
request:
99-
synthetic: true
100-
101-
.. code-block:: xml
102-
103-
<?xml version="1.0" encoding="UTF-8" ?>
104-
<container xmlns="http://symfony.com/schema/dic/services"
105-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
106-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
107-
108-
<services>
109-
<service id="request" synthetic="true" />
110-
</services>
111-
</container>
112-
113-
.. code-block:: php
114-
115-
use Symfony\Component\DependencyInjection\Definition;
116-
117-
$container
118-
->setDefinition('request', new Definition())
119-
->setSynthetic(true);
120-
121-
As you see, only the ``synthetic`` option is set. All other options are only used
122-
to configure how a service is created by the container. As the service isn't
123-
created by the container, these options are omitted.
124-
125-
Now, you can inject the class by using
126-
:method:`Container::set <Symfony\\Component\\DependencyInjection\\Container::set>`::
127-
128-
// ...
129-
$container->set('request', new MyRequest(...));
130-
13176
Aliasing
13277
--------
13378

@@ -183,47 +128,6 @@ service by asking for the ``bar`` service like this::
183128
class: Example\Foo
184129
bar: "@foo"
185130
186-
187-
Requiring Files
188-
---------------
189-
190-
There might be use cases when you need to include another file just before
191-
the service itself gets loaded. To do so, you can use the ``file`` directive.
192-
193-
.. configuration-block::
194-
195-
.. code-block:: yaml
196-
197-
services:
198-
foo:
199-
class: Example\Foo\Bar
200-
file: "%kernel.root_dir%/src/path/to/file/foo.php"
201-
202-
.. code-block:: xml
203-
204-
<?xml version="1.0" encoding="UTF-8" ?>
205-
<container xmlns="http://symfony.com/schema/dic/services"
206-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
207-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
208-
209-
<services>
210-
<service id="foo" class="Example\Foo\Bar">
211-
<file>%kernel.root_dir%/src/path/to/file/foo.php</file>
212-
</service>
213-
</services>
214-
</container>
215-
216-
.. code-block:: php
217-
218-
use Symfony\Component\DependencyInjection\Definition;
219-
220-
$definition = new Definition('Example\Foo\Bar');
221-
$definition->setFile('%kernel.root_dir%/src/path/to/file/foo.php');
222-
$container->setDefinition('foo', $definition);
223-
224-
Notice that Symfony will internally call the PHP statement ``require_once``,
225-
which means that your file will be included only once per request.
226-
227131
Decorating Services
228132
-------------------
229133

components/dependency_injection/definitions.rst

+12
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,15 @@ You can also replace any existing method calls with an array of new ones with::
125125
the container is compiled. Once the container is compiled you cannot
126126
manipulate service definitions further. To learn more about compiling
127127
the container see :doc:`/components/dependency_injection/compilation`.
128+
129+
Requiring Files
130+
~~~~~~~~~~~~~~~
131+
132+
There might be use cases when you need to include another file just before
133+
the service itself gets loaded. To do so, you can use the
134+
:method:`Symfony\\Component\\DependencyInjection\\Definition::setFile` method::
135+
136+
$definition->setFile('/src/path/to/file/foo.php');
137+
138+
Notice that Symfony will internally call the PHP statement ``require_once``,
139+
which means that your file will be included only once per request.

components/dependency_injection/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
types
99
parameters
1010
definitions
11+
synthetic_services
1112
compilation
1213
tags
1314
factories
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. index::
2+
single: DependencyInjection; Synthetic Services
3+
4+
How to Inject Instances into the Container
5+
------------------------------------------
6+
7+
When using the container in your application, you sometimes need to inject an
8+
instance instead of configuring the container to create a new instance.
9+
10+
For instance, if you're using the :doc:`HttpKernel </components/http_kernel/introduction>`
11+
component with the DependencyInjection component, then the ``kernel``
12+
service is injected into the container from within the ``Kernel`` class::
13+
14+
// ...
15+
abstract class Kernel implements KernelInterface, TerminableInterface
16+
{
17+
// ...
18+
protected function initializeContainer()
19+
{
20+
// ...
21+
$this->container->set('kernel', $this);
22+
23+
// ...
24+
}
25+
}
26+
27+
The ``kernel`` service is called a synthetic service. This service has to be
28+
configured in the container, so the container knows the service does exist
29+
during compilation (otherwise, services depending on this ``kernel`` service
30+
will get a "service does not exists" error).
31+
32+
In order to do so, you have to use
33+
:method:`Definition::setSynthetic() <Symfony\\Component\\DependencyInjection\\Definition::setSynthetic>`::
34+
35+
use Symfony\Component\DependencyInjectino\Definition;
36+
37+
// synthetic services don't specify a class
38+
$kernelDefinition = new Definition();
39+
$kernelDefinition->setSynthetic(true);
40+
41+
$container->setDefinition('your_service', $kernelDefinition);
42+
43+
Now, you can inject the instance in the container using
44+
:method:`Container::set() <Symfony\\Component\\DependencyInjection\\Container::set>`::
45+
46+
$yourService = new YourObject();
47+
$container->set('your_service', $yourService);
48+
49+
``$container->get('your_service')`` will now return the same instance as
50+
``$yourService``.

components/map.rst.inc

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* :doc:`/components/dependency_injection/types`
4343
* :doc:`/components/dependency_injection/parameters`
4444
* :doc:`/components/dependency_injection/definitions`
45+
* :doc:`/components/dependency_injection/synthetic_services`
4546
* :doc:`/components/dependency_injection/compilation`
4647
* :doc:`/components/dependency_injection/tags`
4748
* :doc:`/components/dependency_injection/factories`

cookbook/assetic/asset_management.rst

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ To include an image you can use the ``image`` tag.
183183
You can also use Assetic for image optimization. More information in
184184
:doc:`/cookbook/assetic/jpeg_optimize`.
185185

186+
.. tip::
187+
188+
Instead of using Assetic to include images, you may consider using the
189+
`LiipImagineBundle`_ community bundle, which allows to compress and
190+
manipulate images (rotate, resize, watermark, etc.) before serving them.
191+
186192
.. _cookbook-assetic-cssrewrite:
187193

188194
Fixing CSS Paths with the ``cssrewrite`` Filter
@@ -572,3 +578,5 @@ some isolated directory (e.g. ``/js/compiled``), to keep things organized:
572578
) as $url): ?>
573579
<script src="<?php echo $view->escape($url) ?>"></script>
574580
<?php endforeach ?>
581+
582+
.. _`LiipImagineBundle`: https://github.com/liip/LiipImagineBundle

cookbook/assetic/jpeg_optimize.rst

+6
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,10 @@ file:
250250
),
251251
));
252252
253+
.. tip::
254+
255+
For uploaded images, you can compress and manipulate them using the
256+
`LiipImagineBundle`_ community bundle.
257+
253258
.. _`Jpegoptim`: http://www.kokkonen.net/tjko/projects.html
259+
.. _`LiipImagineBundle`: http://knpbundles.com/liip/LiipImagineBundle

cookbook/bundles/best_practices.rst

+22-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Best Practices for Reusable Bundles
55
===================================
66

7-
There are 2 types of bundles:
7+
There are two types of bundles:
88

99
* Application-specific bundles: only used to build your application;
1010
* Reusable bundles: meant to be shared across many projects.
@@ -13,12 +13,8 @@ This article is all about how to structure your **reusable bundles** so that
1313
they're easy to configure and extend. Many of these recommendations do not
1414
apply to application bundles because you'll want to keep those as simple
1515
as possible. For application bundles, just follow the practices shown throughout
16-
the book and cookbook.
17-
18-
.. seealso::
19-
20-
The best practices for application-specific bundles are discussed in
21-
:doc:`/best_practices/introduction`.
16+
the :doc:`book </book/index>`, the :doc:`cookbook </cookbook/index>` and the
17+
:doc:`best practices </best_practices/index>` book.
2218

2319
.. index::
2420
pair: Bundle; Naming conventions
@@ -38,7 +34,7 @@ bundle class name must follow these simple rules:
3834

3935
* Use only alphanumeric characters and underscores;
4036
* Use a CamelCased name;
41-
* Use a descriptive and short name (no more than 2 words);
37+
* Use a descriptive and short name (no more than two words);
4238
* Prefix the name with the concatenation of the vendor (and optionally the
4339
category namespaces);
4440
* Suffix the name with ``Bundle``.
@@ -112,7 +108,7 @@ The following files are mandatory:
112108
structure to work.
113109

114110
The depth of sub-directories should be kept to the minimal for most used
115-
classes and files (2 levels at a maximum). More levels can be defined for
111+
classes and files (two levels at a maximum). More levels can be defined for
116112
non-strategic, less-used files.
117113

118114
The bundle directory is read-only. If you need to write temporary files, store
@@ -158,7 +154,7 @@ instance, a ``HelloController`` controller is stored in
158154
``Bundle/HelloBundle/Controller/HelloController.php`` and the fully qualified
159155
class name is ``Bundle\HelloBundle\Controller\HelloController``.
160156

161-
All classes and files must follow the Symfony coding :doc:`standards </contributing/code/standards>`.
157+
All classes and files must follow the :doc:`Symfony coding standards </contributing/code/standards>`.
162158

163159
Some classes should be seen as facades and should be as short as possible, like
164160
Commands, Helpers, Listeners, and Controllers.
@@ -181,7 +177,7 @@ Tests
181177
-----
182178

183179
A bundle should come with a test suite written with PHPUnit and stored under
184-
the ``Tests/`` directory. Tests should follow the following principles:
180+
the ``Tests/`` directory. Tests should follow these principles:
185181

186182
* The test suite must be executable with a simple ``phpunit`` command run from
187183
a sample application;
@@ -190,13 +186,14 @@ the ``Tests/`` directory. Tests should follow the following principles:
190186
* The tests should cover at least 95% of the code base.
191187

192188
.. note::
189+
193190
A test suite must not contain ``AllTests.php`` scripts, but must rely on the
194191
existence of a ``phpunit.xml.dist`` file.
195192

196193
Documentation
197194
-------------
198195

199-
All classes and functions must come with full PHPDoc.
196+
All classes and functions must be fully documented using `PHPDoc`_ tags.
200197

201198
Extensive documentation should also be provided in the
202199
:doc:`reStructuredText </contributing/documentation/format>` format, under
@@ -233,8 +230,8 @@ following standardized instructions in your ``README.md`` file.
233230
Step 2: Enable the Bundle
234231
-------------------------
235232
236-
Then, enable the bundle by adding the following line in the `app/AppKernel.php`
237-
file of your project:
233+
Then, enable the bundle by adding it to the list of registered bundles
234+
in the `app/AppKernel.php` file of your project:
238235
239236
```php
240237
<?php
@@ -279,8 +276,8 @@ following standardized instructions in your ``README.md`` file.
279276
Step 2: Enable the Bundle
280277
-------------------------
281278
282-
Then, enable the bundle by adding the following line in the ``app/AppKernel.php``
283-
file of your project:
279+
Then, enable the bundle by adding it to the list of registered bundles
280+
in the ``app/AppKernel.php`` file of your project:
284281
285282
.. code-block:: php
286283
@@ -306,8 +303,11 @@ following standardized instructions in your ``README.md`` file.
306303
307304
.. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
308305
309-
This template assumes that your bundle is in its ``1.x`` version. If not, change
310-
the ``"~1"`` installation version accordingly (``"~2"``, ``"~3"``, etc.)
306+
The example above assumes that you are installing the latest stable version of
307+
the bundle, where you don't have to provide the package version number
308+
(e.g. ``composer require friendsofsymfony/user-bundle``). If the installation
309+
instructions refer to some past bundle version or to some unstable version,
310+
include the version constraint (e.g. ``composer require friendsofsymfony/user-bundle "~2.0@dev"``).
311311

312312
Optionally, you can add more installation steps (*Step 3*, *Step 4*, etc.) to
313313
explain other required installation tasks, such as registering routes or
@@ -330,7 +330,8 @@ Translation Files
330330
-----------------
331331

332332
If a bundle provides message translations, they must be defined in the XLIFF
333-
format; the domain should be named after the bundle name (``bundle.hello``).
333+
format; the :ref:`translation domain <using-message-domains>` should be named
334+
after the bundle name (``bundle.hello``).
334335

335336
A bundle must not override existing messages from another bundle.
336337

@@ -369,18 +370,12 @@ The end user can provide values in any configuration file:
369370
// app/config/config.php
370371
$container->setParameter('acme_hello.email.from', '[email protected]');
371372
372-
.. code-block:: ini
373-
374-
; app/config/config.ini
375-
[parameters]
376-
acme_hello.email.from = [email protected]
377-
378373
Retrieve the configuration parameters in your code from the container::
379374

380375
$container->getParameter('acme_hello.email.from');
381376

382377
Even if this mechanism is simple enough, you are highly encouraged to use the
383-
semantic configuration described in the cookbook.
378+
:doc:`semantic bundle configuration </cookbook/bundles/extension>` instead.
384379

385380
.. note::
386381

@@ -435,3 +430,4 @@ Learn more from the Cookbook
435430
* :doc:`/cookbook/bundles/extension`
436431

437432
.. _standards: http://www.php-fig.org/psr/psr-4/
433+
.. _`PHPDoc`: https://en.wikipedia.org/wiki/PHPDoc

0 commit comments

Comments
 (0)