Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.49 KB

File metadata and controls

55 lines (39 loc) · 1.49 KB

Usage

Read variables in PHP

use Nowo\RuntimeEnvBundle\Service\RuntimeEnvBag;

final class SomeService
{
    public function __construct(private readonly RuntimeEnvBag $runtimeEnv)
    {
    }

    public function callExternalApi(): void
    {
        $token = $this->runtimeEnv->get('EXTERNAL_API_TOKEN');
        if ($token === null) {
            throw new \RuntimeException('EXTERNAL_API_TOKEN is not configured.');
        }
        // ...
    }
}
  • has(string $name): bool
  • get(string $name, ?string $default = null): ?string
  • all(): array<string, string> — enabled variables only

Twig

{% if runtime_env_has('FEATURE_FLAG_X') %}
  {{ runtime_env('FEATURE_FLAG_X') }}
{% endif %}

Do not dump secret values into public HTML.

Admin CRUD

Open /_runtime_env (or your panel.path_prefix). Names must match ^[A-Z][A-Z0-9_]*$.

List view always masks values. Edit form shows the decrypted plaintext only to authorized admins.

What stays in .env

Anything required to boot the kernel / connect to the DB / decrypt fields:

  • DATABASE_URL, APP_SECRET
  • DoctrineEncrypt secret key path / material
  • FRANKENPHP_MODE, ports, etc.

FrankenPHP worker

RuntimeEnvBag is tagged with kernel.reset. Between requests the in-memory map is cleared so values cannot leak across users/requests. After CRUD writes, the bag cache is invalidated immediately for the current process; other workers pick up changes on their next request (next reset + reload from DB).