8000 Documented the new Kernel project_dir argument by javiereguiluz · Pull Request #11228 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Documented the new Kernel project_dir argument #11228

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

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 0 additions & 29 deletions deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------

Expand Down
25 changes: 19 additions & 6 deletions reference/configuration/kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
0