Skip to content

Simplified some docs about getProjectDir #11297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <configuration-kernel-project-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 <configuration-kernel-project-directory>`.

Learn More
----------
Expand Down
16 changes: 11 additions & 5 deletions reference/configuration/kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/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;
Expand Down