Skip to content
Open
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
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
DATABASE_URL=sqlite:///%kernel.project_dir%/data/database_test.sqlite
APP_EMAIL_ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ cd my_project/
./bin/phpunit
```

> **Note:** User emails are encrypted in use using a key generated automatically
> in `.env.local` during `composer install`. If you regenerate the key (e.g. by
> deleting `.env.local` and running `composer install` again), you **must** reload
> the fixtures so the database is re-encrypted with the new key:
>
> ```bash
> php bin/console doctrine:fixtures:load
> ```
>
> The test database (`data/database_test.sqlite`) uses the fixed key defined in
> `.env.test` (`APP_EMAIL_ENCRYPTION_KEY=000...000`). After changing the test
> fixtures or the encryption logic, regenerate it with:
>
> ```bash
> php bin/console doctrine:fixtures:load --env=test
> ```

[1]: https://symfony.com/doc/current/best_practices.html
[2]: https://symfony.com/doc/current/setup.html#technical-requirements
[3]: https://symfony.com/doc/current/setup/web_server_configuration.html
Expand Down
36 changes: 36 additions & 0 deletions bin/generate-env-keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Generates missing secret keys in .env.local.
* Called automatically on composer install/update.
*/

$envLocalPath = dirname(__DIR__).'/.env.local';
$content = file_exists($envLocalPath) ? file_get_contents($envLocalPath) : '';

$keys = [
'APP_EMAIL_ENCRYPTION_KEY' => static fn () => bin2hex(random_bytes(32)),
];

$added = [];
foreach ($keys as $key => $generator) {
if (!str_contains($content, $key.'=')) {
$content .= PHP_EOL.$key.'='.$generator().PHP_EOL;
$added[] = $key;
}
}

if ($added !== []) {
file_put_contents($envLocalPath, $content);
echo 'Generated missing keys in .env.local: '.implode(', ', $added).PHP_EOL;
}
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
"license": "MIT",
"type": "project",
"description": "Symfony Demo Application",
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{"type": "vcs", "url": "https://github.com/GromNaN/DoctrineBundle.git"},
{"type": "vcs", "url": "https://github.com/GromNaN/dbal.git"},
{"type": "vcs", "url": "https://github.com/GromNaN/doctrine-orm.git"}
],
"require": {
"php": ">=8.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-pdo_sqlite": "*",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^3.0",
"doctrine/orm": "^3.5",
"doctrine/dbal": "dev-type-registry-config as 4.4.x-dev",
"doctrine/doctrine-bundle": "dev-feat/dbal-type-as-service as 3.3.x-dev",
"doctrine/orm": "dev-type-registry-instance as 3.6.x-dev",
"league/commonmark": "^2.1",
"symfony/apache-pack": "^1.0",
"symfony/asset": "^8",
Expand Down Expand Up @@ -98,6 +103,7 @@
"scripts": {
"auto-scripts": {
"-r \"@rename('.env.local.demo', '.env.local');\"": "php-script",
"bin/generate-env-keys": "script",
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd",
"importmap:install": "symfony-cmd",
Expand Down
164 changes: 101 additions & 63 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified data/database.sqlite
Binary file not shown.
Binary file modified data/database_test.sqlite
Binary file not shown.
Loading
Loading