Skip to content

Commit f9c46c2

Browse files
committed
Merge branch '4.2'
* 4.2: Simplified some docs about getProjectDir Fixed the RST syntax of a serializer article
2 parents b456a83 + a3ebd5d commit f9c46c2

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

components/serializer.rst

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,29 +248,27 @@ that will be used by the normalizer must be aware of the format to use.
248248
The following code shows how to initialize the :class:`Symfony\\Component\\Serializer\\Mapping\\Factory\\ClassMetadataFactory`
249249
for each format:
250250

251-
.. configuration-block::
252-
253-
.. code-block:: php-annotations
251+
* Annotations in PHP files::
254252

255-
use Doctrine\Common\Annotations\AnnotationReader;
256-
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
257-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
253+
use Doctrine\Common\Annotations\AnnotationReader;
254+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
255+
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
258256

259-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
257+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
260258

261-
.. code-block:: yaml
259+
* XML files::
262260

263-
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
264-
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
261+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
262+
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
265263

266-
$classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
264+
$classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
267265

268-
.. code-block:: xml
266+
* YAML files::
269267

270-
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
271-
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
268+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
269+
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
272270

273-
$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
271+
$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
274272

275273
.. _component-serializer-attributes-groups-annotations:
276274

deployment.rst

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,15 @@ Troubleshooting
217217
Deployments not Using the ``composer.json`` File
218218
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219219

220-
Symfony applications provide a ``kernel.project_dir`` parameter and a related
221-
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method.
222-
You can use this method to perform operations with file paths relative to your
223-
project's root directory. The logic to find that project root directory is based
224-
on the location of the main ``composer.json`` file.
225-
226-
If your deployment method doesn't use Composer, you may have removed the
227-
``composer.json`` file and the application won't work on the production server.
228-
The solution is to override the ``getProjectDir()`` method in the application
229-
kernel and return your project's root directory::
230-
231-
// src/Kernel.php
232-
// ...
233-
class Kernel extends BaseKernel
234-
{
235-
// ...
236-
237-
public function getProjectDir()
238-
{
239-
return dirname(__DIR__);
240-
}
241-
}
220+
The :ref:`project root directory <configuration-kernel-project-directory>`
221+
(whose value is used via the ``kernel.project_dir`` parameter and the
222+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method) is
223+
calculated automatically by Symfony as the directory where the main
224+
``composer.json`` file is stored.
225+
226+
In deployments not using the ``composer.json`` file, you'll need to override the
227+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method
228+
:ref:`as explained in this section <configuration-kernel-project-directory>`.
242229

243230
Learn More
244231
----------

reference/configuration/kernel.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,23 @@ The name of the kernel isn't usually directly important - it's used in the
6161
generation of cache files - and you probably will only change it when
6262
:doc:`using applications with multiple kernels </configuration/multiple_kernels>`.
6363

64+
.. _configuration-kernel-project-directory:
65+
6466
Project Directory
6567
~~~~~~~~~~~~~~~~~
6668

6769
**type**: ``string`` **default**: the directory of the project ``composer.json``
6870

69-
This returns the root directory of your Symfony project. It's calculated as
70-
the directory where the main ``composer.json`` file is stored.
71+
This returns the root directory of your Symfony project, which is used by
72+
applications to perform operations with file paths relative to the project's
73+
root directory.
7174

72-
If for some reason the ``composer.json`` file is not stored at the root of your
73-
project, you can override the :method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir`
74-
method to return the right project directory::
75+
By default, its value is calculated automatically as the directory where the
76+
main ``composer.json`` file is stored. If you don't use Composer, or have moved
77+
the ``composer.json`` file location or have deleted it entirely (for example in
78+
the production servers), you can override the
79+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method to return
80+
the right project directory::
7581

7682
// src/Kernel.php
7783
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

0 commit comments

Comments
 (0)