From 4ecda82f1e2f01fd4a7e232a80d701b1d2a99307 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 4 Apr 2019 13:16:55 +0200 Subject: [PATCH] Simplified some docs about getProjectDir --- deployment.rst | 31 +++++++++--------------------- reference/configuration/kernel.rst | 16 ++++++++++----- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/deployment.rst b/deployment.rst index c3aaf5093c5..ff7d769c537 100644 --- a/deployment.rst +++ b/deployment.rst @@ -217,28 +217,15 @@ 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 dirname(__DIR__); - } - } +The :ref:`project root directory ` +(whose value is used via the ``kernel.project_dir`` parameter and the +:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method) is +calculated automatically by Symfony as the directory where the main +``composer.json`` file is stored. + +In deployments not using the ``composer.json`` file, you'll need to override the +:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method +:ref:`as explained in this section `. Learn More ---------- diff --git a/reference/configuration/kernel.rst b/reference/configuration/kernel.rst index 4107987e5a3..4594915993a 100644 --- a/reference/configuration/kernel.rst +++ b/reference/configuration/kernel.rst @@ -61,17 +61,23 @@ The name of the kernel isn't usually directly important - it's used in the generation of cache files - and you probably will only change it when :doc:`using applications with multiple kernels `. +.. _configuration-kernel-project-directory: + Project Directory ~~~~~~~~~~~~~~~~~ **type**: ``string`` **default**: the directory of the project ``composer.json`` -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 used by +applications to perform operations with file paths relative to the project's +root directory. -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:: +By default, its value is calculated automatically as the directory where the +main ``composer.json`` file is stored. If you don't use Composer, or have moved +the ``composer.json`` file location or have deleted it entirely (for example in +the production servers), you can override the +:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method to return +the right project directory:: // src/Kernel.php use Symfony\Component\HttpKernel\Kernel as BaseKernel;