From 3c45a7b7c148c19b97ca1f270c6185dc1d661d36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Vernet?=
Date: Thu, 5 Dec 2024 07:48:44 +0100
Subject: [PATCH] feat: use PHP config instead of YAML (#129)
---
README.md | 25 +++-
composer.json | 3 +-
composer.lock | 44 ++++++-
config/packages/asset_mapper.php | 16 +++
config/packages/asset_mapper.yaml | 5 -
config/packages/cache.php | 29 +++++
config/packages/cache.yaml | 19 ---
config/packages/csrf.php | 23 ++++
config/packages/csrf.yaml | 11 --
config/packages/framework.php | 39 +++++++
config/packages/framework.yaml | 25 ----
config/packages/monolog.php | 110 ++++++++++++++++++
config/packages/monolog.yaml | 61 ----------
config/packages/routing.php | 24 ++++
config/packages/routing.yaml | 12 --
config/packages/twig.php | 20 ++++
config/packages/twig.yaml | 9 --
config/packages/validator.php | 27 +++++
config/packages/validator.yaml | 13 ---
config/packages/web_profiler.php | 32 +++++
config/packages/web_profiler.yaml | 17 ---
config/routes.php | 20 ++++
config/routes.yaml | 12 --
config/routes/framework.php | 12 ++
config/routes/framework.yaml | 4 -
config/routes/web_profiler.php | 14 +++
config/routes/web_profiler.yaml | 8 --
config/services.php | 41 +++++++
config/services.yaml | 34 ------
.../App/Controller/HelloWorldAction.html.twig | 2 +-
30 files changed, 472 insertions(+), 239 deletions(-)
create mode 100644 config/packages/asset_mapper.php
delete mode 100644 config/packages/asset_mapper.yaml
create mode 100644 config/packages/cache.php
delete mode 100644 config/packages/cache.yaml
create mode 100644 config/packages/csrf.php
delete mode 100644 config/packages/csrf.yaml
create mode 100644 config/packages/framework.php
delete mode 100644 config/packages/framework.yaml
create mode 100644 config/packages/monolog.php
delete mode 100644 config/packages/monolog.yaml
create mode 100644 config/packages/routing.php
delete mode 100644 config/packages/routing.yaml
create mode 100644 config/packages/twig.php
delete mode 100644 config/packages/twig.yaml
create mode 100644 config/packages/validator.php
delete mode 100644 config/packages/validator.yaml
create mode 100644 config/packages/web_profiler.php
delete mode 100644 config/packages/web_profiler.yaml
create mode 100644 config/routes.php
delete mode 100644 config/routes.yaml
create mode 100644 config/routes/framework.php
delete mode 100644 config/routes/framework.yaml
create mode 100644 config/routes/web_profiler.php
delete mode 100644 config/routes/web_profiler.yaml
create mode 100644 config/services.php
delete mode 100644 config/services.yaml
diff --git a/README.md b/README.md
index f2f0adc..e900484 100644
--- a/README.md
+++ b/README.md
@@ -14,9 +14,7 @@
MicroSymfony is a [Symfony 7.2](https://symfony.com/blog/symfony-7-2-curated-new-features)
application skeleton on steroids, ready to use.
-I have made a long blog post explaining all it contains; it will be the reference
-for documentation.
-I'll update it when needed:
+I have made a long blog post explaining the philosophy behind and how to use it:
* [Introducing the MicroSymfony application template](https://www.strangebuzz.com/en/blog/introducing-the-microsymfony-application-template)
@@ -171,7 +169,7 @@ are not merged in the main branch but are used to test the integration of a new
vendor library or make a [POC](https://en.wikipedia.org/wiki/Proof_of_concept).
For example, have you ever dreamed of testing [Eloquent](https://laravel.com/docs/11.x/eloquent#introduction),
the Laravel ORM, on a Symfony project?
-Then clone the `eloquent` branch and run `composer install && make load-fixtures`.
+Then clone the `eloquent` branch, and run `composer install && make load-fixtures`.
### Infrastructure
@@ -180,7 +178,7 @@ Then clone the `eloquent` branch and run `composer install && make load-fixtures
### Database ๐ฝ
-These ยซ database ยป branches aim to display a list of records coming from a [SQLite](https://www.sqlite.org/)
+These ยซ database ยป branches aim to display a list of records from a [SQLite](https://www.sqlite.org/)
database.
* Doctrine DBAL ([PR](https://github.com/strangebuzz/MicroSymfony/pull/72), [branch](https://github.com/strangebuzz/MicroSymfony/tree/doctrine-dbal), rebased on 2024-11-17)
@@ -192,19 +190,33 @@ database.
* TwigStan ([PR](https://github.com/strangebuzz/MicroSymfony/pull/95), [branch](https://github.com/strangebuzz/MicroSymfony/tree/twigstan), rebased on 2024-11-17)
* Twig-CS-Fixer ([PR](https://github.com/strangebuzz/MicroSymfony/pull/118), [branch](https://github.com/strangebuzz/MicroSymfony/tree/feat/use-twig-cs-fixer), rebased on 2024-11-21)
-These branches will be rebased after each release so they are always up to date.
+One will rebase those branches regularly so they are always up to date.
## Notes ๐
+### Symfony-UX
+
Turbo forms are disabled in [assets/app.js](https://github.com/strangebuzz/MicroSymfony/blob/main/assets/app.js).
To enable the feature for a given form, add the `data-turbo="true"` attribute to it.
Or change the parameter `Turbo.setFormMode` to `on` to activate the feature globally.
In both cases, your controller code has to be [modified accordingly](https://symfony.com/bundles/ux-turbo/current/index.html#3-form-response-code-changes).
+### PHP configuration files
+
+If you install a new Symfony library, the flex recipes can add YAML files to your
+project.
+These YAML files are loaded, but you can convert them to PHP like the other configuration
+files.
+For example, to convert the `messenger` YAML configuration to PHP with [Simplify](https://github.com/symplify/config-transformer),
+run:
+
+ vendor/bin/config-transformer convert config/packages/messenger.yaml
+
## Other good practices ๐
+* Using PHP configuration files instead of YAML ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/config/services.php))
* Using strict types in all PHP files ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/src/Controller/SlugifyAction.php#L3))
* Using the ADR pattern in an action controller ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/src/Controller/SlugifyAction.php)) ([doc](https://symfony.com/doc/current/controller/service.html#invokable-controllers))
* The [composer.json](https://github.com/strangebuzz/MicroSymfony/blob/main/composer.json)
@@ -215,6 +227,7 @@ In both cases, your controller code has to be [modified accordingly](https://sym
## References ๐
+* [How to Switch from YAML Configs to PHP Today with Symplify](https://tomasvotruba.com/blog/2020/07/27/how-to-switch-from-yaml-xml-configs-to-php-today-with-migrify/) (tomasvotruba.com)
* [PHPStan 2.0 Released With Level 10 and Elephpants!](https://phpstan.org/blog/phpstan-2-0-released-level-10-elephpants) (phpstan.org)
* [A better ADR pattern for your Symfony controllers](https://www.strangebuzz.com/en/blog/a-better-adr-pattern-for-your-symfony-controllers) (strangebuzz.com)
* [My Taskfile configuration for Symfony](https://jmsche.fr/en/blog/my-taskfile-configuration-for-symfony) (jmsche.fr)
diff --git a/composer.json b/composer.json
index 9134ea5..d3a7075 100644
--- a/composer.json
+++ b/composer.json
@@ -59,7 +59,8 @@
"symfony/maker-bundle": "^1.61",
"symfony/requirements-checker": "^2.0",
"symfony/stopwatch": "~7.2.0",
- "symfony/web-profiler-bundle": "~7.2.0"
+ "symfony/web-profiler-bundle": "~7.2.0",
+ "symplify/config-transformer": "^12.3"
},
"replace": {
"symfony/polyfill-ctype": "*",
diff --git a/composer.lock b/composer.lock
index 9ce6387..5108cdf 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "7806fc97730ded16b7b7cb9fce553964",
+ "content-hash": "d1b04f3d91e878fb58d41ee56bda4c4d",
"packages": [
{
"name": "composer/semver",
@@ -8574,6 +8574,48 @@
],
"time": "2024-11-19T10:12:55+00:00"
},
+ {
+ "name": "symplify/config-transformer",
+ "version": "12.3.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symplify/config-transformer.git",
+ "reference": "9fb4f5acf7ec4261ba426bee9eb7aeed174eb600"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symplify/config-transformer/zipball/9fb4f5acf7ec4261ba426bee9eb7aeed174eb600",
+ "reference": "9fb4f5acf7ec4261ba426bee9eb7aeed174eb600",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.2"
+ },
+ "bin": [
+ "bin/config-transformer"
+ ],
+ "type": "library",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Prefixed version of Symfony YAML/XML to PHP/YAML config converter",
+ "support": {
+ "issues": "https://github.com/symplify/config-transformer/issues",
+ "source": "https://github.com/symplify/config-transformer/tree/12.3.4"
+ },
+ "funding": [
+ {
+ "url": "https://www.paypal.me/rectorphp",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/tomasvotruba",
+ "type": "github"
+ }
+ ],
+ "time": "2024-01-15T21:58:26+00:00"
+ },
{
"name": "theseer/tokenizer",
"version": "1.2.3",
diff --git a/config/packages/asset_mapper.php b/config/packages/asset_mapper.php
new file mode 100644
index 0000000..ea8ca55
--- /dev/null
+++ b/config/packages/asset_mapper.php
@@ -0,0 +1,16 @@
+extension('framework', [
+ 'asset_mapper' => [
+ // The paths to make available to the asset mapper.
+ 'paths' => [
+ 'assets/',
+ ],
+ ],
+ ]);
+};
diff --git a/config/packages/asset_mapper.yaml b/config/packages/asset_mapper.yaml
deleted file mode 100644
index d1ac653..0000000
--- a/config/packages/asset_mapper.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-framework:
- asset_mapper:
- # The paths to make available to the asset mapper.
- paths:
- - assets/
diff --git a/config/packages/cache.php b/config/packages/cache.php
new file mode 100644
index 0000000..a4f87a0
--- /dev/null
+++ b/config/packages/cache.php
@@ -0,0 +1,29 @@
+extension('framework', [
+ // Unique name of your app: used to compute stable namespaces for cache keys.
+ // 'prefix_seed' => 'your_vendor_name/app_name',
+
+ // The "app" cache stores to the filesystem by default.
+ // The data in this cache should persist between deploys.
+ // Other options include:
+
+ // Redis
+ // 'app' => 'cache.adapter.redis',
+ // 'default_redis_provider' => 'redis://localhost',
+
+ // APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
+ // 'app' => 'cache.adapter.apcu',
+
+ // Namespaced pools use the above "app" backend by default
+ // 'pools' => [
+ // 'my.dedicated.cache' => null
+ // ],
+ 'cache' => null,
+ ]);
+};
diff --git a/config/packages/cache.yaml b/config/packages/cache.yaml
deleted file mode 100644
index 6899b72..0000000
--- a/config/packages/cache.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-framework:
- cache:
- # Unique name of your app: used to compute stable namespaces for cache keys.
- #prefix_seed: your_vendor_name/app_name
-
- # The "app" cache stores to the filesystem by default.
- # The data in this cache should persist between deploys.
- # Other options include:
-
- # Redis
- #app: cache.adapter.redis
- #default_redis_provider: redis://localhost
-
- # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
- #app: cache.adapter.apcu
-
- # Namespaced pools use the above "app" backend by default
- #pools:
- #my.dedicated.cache: null
diff --git a/config/packages/csrf.php b/config/packages/csrf.php
new file mode 100644
index 0000000..c033a11
--- /dev/null
+++ b/config/packages/csrf.php
@@ -0,0 +1,23 @@
+extension('framework', [
+ 'form' => [
+ 'csrf_protection' => [
+ 'token_id' => 'submit',
+ ],
+ ],
+ 'csrf_protection' => [
+ 'stateless_token_ids' => [
+ 'submit',
+ 'authenticate',
+ 'logout',
+ ],
+ ],
+ ]);
+};
diff --git a/config/packages/csrf.yaml b/config/packages/csrf.yaml
deleted file mode 100644
index 40d4040..0000000
--- a/config/packages/csrf.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-# Enable stateless CSRF protection for forms and logins/logouts
-framework:
- form:
- csrf_protection:
- token_id: submit
-
- csrf_protection:
- stateless_token_ids:
- - submit
- - authenticate
- - logout
diff --git a/config/packages/framework.php b/config/packages/framework.php
new file mode 100644
index 0000000..2d62a62
--- /dev/null
+++ b/config/packages/framework.php
@@ -0,0 +1,39 @@
+extension('framework', [
+ 'secret' => '%env(APP_SECRET)%',
+ // 'csrf_protection' => true,
+ 'http_method_override' => false,
+ 'handle_all_throwables' => true,
+
+ // Enables session support. Note that the session will ONLY be started if you read or write from it.
+ // Remove or comment this section to explicitly disable session support.
+ 'session' => [
+ 'handler_id' => null,
+ 'cookie_secure' => 'auto',
+ 'cookie_samesite' => 'lax',
+ 'storage_factory_id' => 'session.storage.factory.native',
+ ],
+
+ // 'esi' => true
+ // 'fragments' => true
+ 'php_errors' => [
+ 'log' => true,
+ ],
+ ]);
+
+ if ($containerConfigurator->env() === 'test') {
+ $containerConfigurator->extension('framework', [
+ 'test' => true,
+ 'session' => [
+ 'storage_factory_id' => 'session.storage.factory.mock_file',
+ ],
+ ]);
+ }
+};
diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml
deleted file mode 100644
index 6d85c29..0000000
--- a/config/packages/framework.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-# see https://symfony.com/doc/current/reference/configuration/framework.html
-framework:
- secret: '%env(APP_SECRET)%'
- #csrf_protection: true
- http_method_override: false
- handle_all_throwables: true
-
- # Enables session support. Note that the session will ONLY be started if you read or write from it.
- # Remove or comment this section to explicitly disable session support.
- session:
- handler_id: null
- cookie_secure: auto
- cookie_samesite: lax
- storage_factory_id: session.storage.factory.native
-
- #esi: true
- #fragments: true
- php_errors:
- log: true
-
-when@test:
- framework:
- test: true
- session:
- storage_factory_id: session.storage.factory.mock_file
diff --git a/config/packages/monolog.php b/config/packages/monolog.php
new file mode 100644
index 0000000..83aaf6f
--- /dev/null
+++ b/config/packages/monolog.php
@@ -0,0 +1,110 @@
+extension('monolog', [
+ 'channels' => [
+ 'deprecation',
+ ],
+ ]);
+
+ if ($containerConfigurator->env() === 'dev') {
+ $containerConfigurator->extension('monolog', [
+ 'handlers' => [
+ 'main' => [
+ 'type' => 'stream',
+ 'path' => '%kernel.logs_dir%/%kernel.environment%.log',
+ 'level' => 'debug',
+ 'channels' => [
+ '!event',
+ ],
+ ],
+ // uncomment to get logging in your browser
+ // you may have to allow bigger header sizes in your Web server configuration
+ // 'firephp' => [
+ // 'type' => 'firephp',
+ // 'level' => 'info',
+ // ],
+ // 'chromephp' => [
+ // 'type' => 'chromephp',
+ // 'level' => 'info',
+ // ],
+
+ 'console' => [
+ 'type' => 'console',
+ 'process_psr_3_messages' => false,
+ 'channels' => [
+ '!event',
+ '!doctrine',
+ '!console',
+ ],
+ ],
+ ],
+ ]);
+ }
+
+ if ($containerConfigurator->env() === 'test') {
+ $containerConfigurator->extension('monolog', [
+ 'handlers' => [
+ 'main' => [
+ 'type' => 'fingers_crossed',
+ 'action_level' => 'error',
+ 'handler' => 'nested',
+ 'excluded_http_codes' => [
+ 404,
+ 405,
+ ],
+ 'channels' => [
+ '!event',
+ ],
+ ],
+ 'nested' => [
+ 'type' => 'stream',
+ 'path' => '%kernel.logs_dir%/%kernel.environment%.log',
+ 'level' => 'debug',
+ ],
+ ],
+ ]);
+ }
+
+ if ($containerConfigurator->env() === 'prod') {
+ $containerConfigurator->extension('monolog', [
+ 'handlers' => [
+ 'main' => [
+ 'type' => 'fingers_crossed',
+ 'action_level' => 'error',
+ 'handler' => 'nested',
+ 'excluded_http_codes' => [
+ 404,
+ 405,
+ ],
+ 'buffer_size' => 50,
+ ],
+ 'nested' => [
+ 'type' => 'stream',
+ 'path' => 'php://stderr',
+ 'level' => 'debug',
+ 'formatter' => 'monolog.formatter.json',
+ ],
+ 'console' => [
+ 'type' => 'console',
+ 'process_psr_3_messages' => false,
+ 'channels' => [
+ '!event',
+ '!doctrine',
+ ],
+ ],
+ 'deprecation' => [
+ 'type' => 'stream',
+ 'channels' => [
+ 'deprecation',
+ ],
+ 'path' => 'php://stderr',
+ ],
+ ],
+ ]);
+ }
+};
diff --git a/config/packages/monolog.yaml b/config/packages/monolog.yaml
deleted file mode 100644
index 8c9efa9..0000000
--- a/config/packages/monolog.yaml
+++ /dev/null
@@ -1,61 +0,0 @@
-monolog:
- channels:
- - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
-
-when@dev:
- monolog:
- handlers:
- main:
- type: stream
- path: "%kernel.logs_dir%/%kernel.environment%.log"
- level: debug
- channels: ["!event"]
- # uncomment to get logging in your browser
- # you may have to allow bigger header sizes in your Web server configuration
- #firephp:
- # type: firephp
- # level: info
- #chromephp:
- # type: chromephp
- # level: info
- console:
- type: console
- process_psr_3_messages: false
- channels: ["!event", "!doctrine", "!console"]
-
-when@test:
- monolog:
- handlers:
- main:
- type: fingers_crossed
- action_level: error
- handler: nested
- excluded_http_codes: [404, 405]
- channels: ["!event"]
- nested:
- type: stream
- path: "%kernel.logs_dir%/%kernel.environment%.log"
- level: debug
-
-when@prod:
- monolog:
- handlers:
- main:
- type: fingers_crossed
- action_level: error
- handler: nested
- excluded_http_codes: [404, 405]
- buffer_size: 50 # How many messages should be saved? Prevent memory leaks
- nested:
- type: stream
- path: php://stderr
- level: debug
- formatter: monolog.formatter.json
- console:
- type: console
- process_psr_3_messages: false
- channels: ["!event", "!doctrine"]
- deprecation:
- type: stream
- channels: [deprecation]
- path: php://stderr
diff --git a/config/packages/routing.php b/config/packages/routing.php
new file mode 100644
index 0000000..5249a55
--- /dev/null
+++ b/config/packages/routing.php
@@ -0,0 +1,24 @@
+extension('framework', [
+ 'router' => [
+ 'utf8' => true,
+
+ // Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
+ // See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
+ // 'default_uri' => 'http://localhost'
+ ],
+ ]);
+ if ($containerConfigurator->env() === 'prod') {
+ $containerConfigurator->extension('framework', [
+ 'router' => [
+ 'strict_requirements' => null,
+ ],
+ ]);
+ }
+};
diff --git a/config/packages/routing.yaml b/config/packages/routing.yaml
deleted file mode 100644
index 4b766ce..0000000
--- a/config/packages/routing.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-framework:
- router:
- utf8: true
-
- # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
- # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
- #default_uri: http://localhost
-
-when@prod:
- framework:
- router:
- strict_requirements: null
diff --git a/config/packages/twig.php b/config/packages/twig.php
new file mode 100644
index 0000000..667dd08
--- /dev/null
+++ b/config/packages/twig.php
@@ -0,0 +1,20 @@
+extension('twig', [
+ 'default_path' => '%kernel.project_dir%/templates',
+ 'globals' => [
+ 'brand' => '%brand%',
+ 'brand_html' => '%brand_html%',
+ ],
+ ]);
+ if ($containerConfigurator->env() === 'test') {
+ $containerConfigurator->extension('twig', [
+ 'strict_variables' => true,
+ ]);
+ }
+};
diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml
deleted file mode 100644
index e9c9503..0000000
--- a/config/packages/twig.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-twig:
- default_path: '%kernel.project_dir%/templates'
- globals:
- brand: '%brand%'
- brand_html: '%brand_html%'
-
-when@test:
- twig:
- strict_variables: true
diff --git a/config/packages/validator.php b/config/packages/validator.php
new file mode 100644
index 0000000..8992502
--- /dev/null
+++ b/config/packages/validator.php
@@ -0,0 +1,27 @@
+extension('framework', [
+ 'validation' => [
+ 'email_validation_mode' => 'html5',
+
+ // Enables validator auto-mapping support.
+ // For instance, basic validation constraints will be inferred from Doctrine's metadata.
+ // 'auto_mapping' => [
+ // 'App\Entity\\' => [],
+ // ],
+ ],
+ ]);
+
+ if ($containerConfigurator->env() === 'test') {
+ $containerConfigurator->extension('framework', [
+ 'validation' => [
+ 'not_compromised_password' => false,
+ ],
+ ]);
+ }
+};
diff --git a/config/packages/validator.yaml b/config/packages/validator.yaml
deleted file mode 100644
index 0201281..0000000
--- a/config/packages/validator.yaml
+++ /dev/null
@@ -1,13 +0,0 @@
-framework:
- validation:
- email_validation_mode: html5
-
- # Enables validator auto-mapping support.
- # For instance, basic validation constraints will be inferred from Doctrine's metadata.
- #auto_mapping:
- # App\Entity\: []
-
-when@test:
- framework:
- validation:
- not_compromised_password: false
diff --git a/config/packages/web_profiler.php b/config/packages/web_profiler.php
new file mode 100644
index 0000000..f7c2b2e
--- /dev/null
+++ b/config/packages/web_profiler.php
@@ -0,0 +1,32 @@
+env() === 'dev') {
+ $containerConfigurator->extension('web_profiler', [
+ 'toolbar' => true,
+ 'intercept_redirects' => false,
+ ]);
+ $containerConfigurator->extension('framework', [
+ 'profiler' => [
+ 'only_exceptions' => false,
+ 'collect_serializer_data' => true,
+ ],
+ ]);
+ }
+
+ if ($containerConfigurator->env() === 'test') {
+ $containerConfigurator->extension('web_profiler', [
+ 'toolbar' => false,
+ 'intercept_redirects' => false,
+ ]);
+ $containerConfigurator->extension('framework', [
+ 'profiler' => [
+ 'collect' => false,
+ ],
+ ]);
+ }
+};
diff --git a/config/packages/web_profiler.yaml b/config/packages/web_profiler.yaml
deleted file mode 100644
index b946111..0000000
--- a/config/packages/web_profiler.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-when@dev:
- web_profiler:
- toolbar: true
- intercept_redirects: false
-
- framework:
- profiler:
- only_exceptions: false
- collect_serializer_data: true
-
-when@test:
- web_profiler:
- toolbar: false
- intercept_redirects: false
-
- framework:
- profiler: { collect: false }
diff --git a/config/routes.php b/config/routes.php
new file mode 100644
index 0000000..09a907f
--- /dev/null
+++ b/config/routes.php
@@ -0,0 +1,20 @@
+import([
+ 'path' => '../src/Controller/',
+ 'namespace' => 'App\Controller',
+ ], 'attribute');
+
+ // https://symfony.com/doc/current/templates.html#rendering-a-template-directly-from-a-route
+ $routingConfigurator->add('App\Controller\StimulusAction', '/stimulus')
+ ->controller(TemplateController::class)
+ ->defaults([
+ 'template' => 'App/Controller/StimulusAction.html.twig',
+ ]);
+};
diff --git a/config/routes.yaml b/config/routes.yaml
deleted file mode 100644
index 177dd2a..0000000
--- a/config/routes.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-controllers:
- resource:
- path: ../src/Controller/
- namespace: App\Controller
- type: attribute
-
-# https://symfony.com/doc/current/templates.html#rendering-a-template-directly-from-a-route
-App\Controller\StimulusAction:
- path: /stimulus
- defaults:
- _controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
- template: App/Controller/StimulusAction.html.twig
\ No newline at end of file
diff --git a/config/routes/framework.php b/config/routes/framework.php
new file mode 100644
index 0000000..27020e0
--- /dev/null
+++ b/config/routes/framework.php
@@ -0,0 +1,12 @@
+env() === 'dev') {
+ $routingConfigurator->import('@FrameworkBundle/Resources/config/routing/errors.xml')
+ ->prefix('/_error');
+ }
+};
diff --git a/config/routes/framework.yaml b/config/routes/framework.yaml
deleted file mode 100644
index 0fc74bb..0000000
--- a/config/routes/framework.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-when@dev:
- _errors:
- resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
- prefix: /_error
diff --git a/config/routes/web_profiler.php b/config/routes/web_profiler.php
new file mode 100644
index 0000000..f74f910
--- /dev/null
+++ b/config/routes/web_profiler.php
@@ -0,0 +1,14 @@
+env() === 'dev') {
+ $routingConfigurator->import('@WebProfilerBundle/Resources/config/routing/wdt.xml')
+ ->prefix('/_wdt');
+ $routingConfigurator->import('@WebProfilerBundle/Resources/config/routing/profiler.xml')
+ ->prefix('/_profiler');
+ }
+};
diff --git a/config/routes/web_profiler.yaml b/config/routes/web_profiler.yaml
deleted file mode 100644
index 8d85319..0000000
--- a/config/routes/web_profiler.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-when@dev:
- web_profiler_wdt:
- resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
- prefix: /_wdt
-
- web_profiler_profiler:
- resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
- prefix: /_profiler
diff --git a/config/services.php b/config/services.php
new file mode 100644
index 0000000..3e779e3
--- /dev/null
+++ b/config/services.php
@@ -0,0 +1,41 @@
+parameters();
+
+ // System parameters: https://symfony.com/doc/current/performance.html
+ $parameters->set('.container.dumper.inline_factories', true);
+
+ // App parameters
+ $parameters->set('brand', 'MicroSymfony');
+ $parameters->set('brand_html', 'MicroSymfony ๐ถ');
+
+ // Services
+ $services = $containerConfigurator->services();
+ $services->defaults()
+ ->autowire() // Automatically injects dependencies in your services.
+ ->autoconfigure() // Automatically registers your services as commands, event subscribers, etc.
+
+ // bind examples
+ ->bind('string $environment', '%kernel.environment%')
+ ->bind('bool $debug', '%kernel.debug%')
+ ;
+
+ $services->load('App\\', __DIR__.'/../src')
+ ->exclude([
+ __DIR__.'/../src/DependencyInjection/',
+ __DIR__.'/../src/Entity/',
+ __DIR__.'/../src/Kernel.php',
+ ]);
+};
diff --git a/config/services.yaml b/config/services.yaml
deleted file mode 100644
index 8b81a90..0000000
--- a/config/services.yaml
+++ /dev/null
@@ -1,34 +0,0 @@
-# This file is the entry point to configure your own services.
-# Files in the packages/ subdirectory configure your dependencies.
-
-# Put parameters here that don't need to change on each machine where the app is deployed
-# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
-parameters:
- # System parameters: https://symfony.com/doc/current/performance.html
- .container.dumper.inline_factories: true
-
- # App parameters
- brand: 'MicroSymfony'
- brand_html: 'MicroSymfony ๐ถ'
-
-services:
- # default configuration for services in *this* file
- _defaults:
- autowire: true # Automatically injects dependencies in your services.
- autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
- bind:
- # bind examples
- string $environment: '%kernel.environment%'
- bool $debug: '%kernel.debug%'
-
- # makes classes in src/ available to be used as services
- # this creates a service per class whose id is the fully-qualified class name
- App\:
- resource: '../src/'
- exclude:
- - '../src/DependencyInjection/'
- - '../src/Entity/'
- - '../src/Kernel.php'
-
- # add more service definitions when explicit configuration is needed
- # please note that last definitions always *replace* previous ones
diff --git a/templates/App/Controller/HelloWorldAction.html.twig b/templates/App/Controller/HelloWorldAction.html.twig
index 24125ac..9f4b173 100644
--- a/templates/App/Controller/HelloWorldAction.html.twig
+++ b/templates/App/Controller/HelloWorldAction.html.twig
@@ -9,7 +9,7 @@
Just a basic Twig template rendering.
These two parameters are injected in the controller action thanks to services binds.
- (@see config/services.yaml
)
+ (@see config/services.php
)
- environment: {{ environment }}