Configuration and environments

โ† Configuration and environments

Ashterix

docs(articles): English translation of From Magento to Symfony

en/articles/magento-to-symfony/core/config.md new file +40 โˆ’0

1 + # Configuration and environments
2 +
3 + Configuration has two levels. Bundle config (`config/packages/*.yaml`) describes how the framework is set up and is read when the container is compiled. Environment variables (`%env(...)%`) hold what differs between servers and are read at runtime.
4 +
5 + **Magento** ยท a value from the admin
6 +
7 + ```php
8 + $enabled = $this->scopeConfig->isSetFlag(
9 + 'faq/general/enabled',
10 + ScopeInterface::SCOPE_STORE
11 + );
12 + ```
13 +
14 + **Symfony** ยท a value from the environment
15 +
16 + ```dotenv
17 + # .env
18 + FAQ_ENABLED=1
19 + ```
20 + ```php
21 + final class FaqMenu
22 + {
23 + public function __construct(
24 + #[Autowire(env: 'bool:FAQ_ENABLED')]
25 + private bool $enabled,
26 + ) {}
27 + }
28 + ```
29 +
30 + - **File order:** `.env` โ†’ `.env.local` โ†’ `.env.$APP_ENV` โ†’ `.env.$APP_ENV.local`. Real environment variables win over all files. `.env` is committed, `*.local` is not.
31 + - **Processors:** `%env(int:X)%`, `bool:`, `json:`, `resolve:`, `default:fallback_param:X`.
32 + - **Secrets:** `bin/console secrets:set ERP_TOKEN` encrypts the value in the repository, the decryption key lives only on the server.
33 + - **Environments:** a `when@prod:` block in any YAML or the `#[When(env: 'dev')]` attribute on a class.
34 + - **Prod:** `composer dump-env prod` builds `.env.local.php` so the files aren't parsed on every request.
35 + - **Reference:** `debug:config framework` shows the actual values, `config:dump-reference doctrine` shows all possible options.
36 +
37 + :::warning subtitle="There are no admin settings"
38 + If the business needs settings that a person changes in the browser, that is an ordinary entity, table, form and cache that you write yourself. There are no store/website scopes either: a multi-store or multi-tenant setup is designed separately.
39 +
40 + :::