From df64145fc65eca1dd4c4c9d288a86c2a77486881 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 27 Mar 2019 15:50:30 +0100 Subject: [PATCH] Documented the new Kernel project_dir argument --- deployment.rst | 29 ----------------------------- reference/configuration/kernel.rst | 25 +++++++++++++++++++------ 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/deployment.rst b/deployment.rst index f4caee2ead4..a50f1fe16c5 100644 --- a/deployment.rst +++ b/deployment.rst @@ -211,35 +211,6 @@ Don't forget that deploying your application also involves updating any dependen (typically via Composer), migrating your database, clearing your cache and other potential things like pushing assets to a CDN (see `Common Post-Deployment Tasks`_). -Troubleshooting ---------------- - -Deployments not Using the ``composer.json`` File -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Symfony applications provide a ``kernel.project_dir`` parameter and a related -:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method. -You can use this method to perform operations with file paths relative to your -project's root directory. The logic to find that project root directory is based -on the location of the main ``composer.json`` file. - -If your deployment method doesn't use Composer, you may have removed the -``composer.json`` file and the application won't work on the production server. -The solution is to override the ``getProjectDir()`` method in the application -kernel and return your project's root directory:: - - // src/Kernel.php - // ... - class Kernel extends BaseKernel - { - // ... - - public function getProjectDir() - { - return __DIR__.'/..'; - } - } - Learn More ---------- diff --git a/reference/configuration/kernel.rst b/reference/configuration/kernel.rst index c009fb3ec20..a166ee64a4e 100644 --- a/reference/configuration/kernel.rst +++ b/reference/configuration/kernel.rst @@ -64,14 +64,27 @@ generation of cache files - and you probably will only change it when Project Directory ~~~~~~~~~~~~~~~~~ -**type**: ``string`` **default**: the directory of the project ``composer.json`` +**type**: ``string`` **default**: see explanation -This returns the root directory of your Symfony project. It's calculated as -the directory where the main ``composer.json`` file is stored. +This returns the root directory of your Symfony project, which is useful to +perform operations with file paths relative to your project's root. It's set by +default to the parent directory of ``public/`` or ``bin/`` (depending if it's +the front controller or the console script). -If for some reason the ``composer.json`` file is not stored at the root of your -project, you can override the :method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` -method to return the right project directory:: +If you need to change the project directory, pass the new path as the third +argument of the ``new Kernel(...)`` instantiation both in ``public/index.php`` +and ``bin/console`` files. + +.. versionadded:: 4.3 + + The third argument of the ``Kernel`` class constructor was introduced in + Symfony 4.3. Also, in previous Symfony versions the project directory was + set by default to the directory that contained the project's + ``composer.json`` file. + +An alternative solution is to override the +:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method in the +application kernel and return the right project directory path:: // src/Kernel.php use Symfony\Component\HttpKernel\Kernel as BaseKernel;