Skip to content
Open
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
33 changes: 27 additions & 6 deletions doc/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
1. [Project directory](#project-directory)
2. [Cache](#cache)

Examples of Symfony applications can be found in the project under `fixtures/build/dir012` (Symfony5) and
`fixtures/build/dir018` (Symfony6 with the Runtime component).
Examples of Symfony applications can be found in the project:
- `fixtures/build/dir018-bis`: a Symfony 7.3 application using the Runtime component.

Check failure on line 8 in doc/symfony.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Lists should be surrounded by blank lines

doc/symfony.md:8 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `fixtures/build/dir018-bis`:..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md
- `fixtures/build/dir018`: a Symfony 6.4 application using the Runtime component.
- `fixtures/build/dir012-bis`: a Symfony 7.3 application without the Runtime component.
- `fixtures/build/dir012`: a Symfony 6.4 application without the Runtime component.

They may slightly vary to what you want to do since they are here for testing purposes, but they should be good enough
to show-case a working scenario if this doc does not prove to be enough.
Expand All @@ -20,37 +23,54 @@
to use the `force-autodiscovery` setting. For more information you can find check the [Including files](./configuration.md#including-files)
doc.

For example (not guaranteed to be up to date):

```json
"files-bin": [
".env.local.php"
],
"directories": [
"config",
"public",
"var"
],
```


## Project directory

Symfony 5.1+ defines the "project dir" as the directory where the composer.json file is. Because box deletes it during PHAR compilation, you need to redefine it in your Kernel. It is usually located in `src/Kernel.php` and can be defined as follow:
Symfony 5.1+ defines the `project dir` as the directory where the `composer.json` file is. Because Box deletes it (the `composer.json`) during PHAR compilation, you need to redefine it in your `Kernel`. It is usually located in `src/Kernel.php` and can be defined as follows:

```php
<?php

class Kernel extends BaseKernel
{
...
public function getProjectDir()
public function getProjectDir(): string
{
return __DIR__.'/../';
}
}
```

Alternatively, you can disable the deletion of the Composer files with `exclude-composer-files`. It is not
rare for a Symfony application to rely on them one way or another.


## Cache

What makes Symfony a bit special for shipping it into a PHAR is its compilation step. Indeed, the Symfony container can
be dumped depending on multiple parameters such the application environment, whether it is in debug mode or not and if
the cache is fresh.

A PHAR however is a readonly only environment, which means the container _cannot_ be dumped once inside the PHAR. To
A PHAR, however, is a readonly only environment, which means the container _cannot_ be dumped once inside the PHAR. To
prevent the issue, you need to make sure of the following:

- The cache is warmed up before being shipped within the PHAR
- The application within the PHAR is running in production mode

To achieve this with the least amount of changes is to:
To achieve this with the least number of changes is to:

- Create the `.env.local.php` file by running the following command:

Expand Down Expand Up @@ -83,6 +103,7 @@
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd"
# no more assets install, unless necessary
},
"post-autoload-dump": [
"@auto-scripts"
Expand Down
Loading