Skip to content

Commit f40f384

Browse files
committed
Allow to override .env files for specific environments
1 parent 6ebbd64 commit f40f384

File tree

13 files changed

+139
-4
lines changed

13 files changed

+139
-4
lines changed

symfony/console/4.2/bin/console

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
use Symfony\Component\Dotenv\Dotenv;
9+
10+
set_time_limit(0);
11+
12+
require __DIR__.'/../vendor/autoload.php';
13+
14+
if (!class_exists(Application::class)) {
15+
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
16+
}
17+
18+
$input = new ArgvInput();
19+
$env = $input->getParameterOption(['--env', '-e'], null, true);
20+
21+
if (!isset($_SERVER['APP_ENV'])) {
22+
if (!class_exists(Dotenv::class)) {
23+
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
24+
}
25+
(new Dotenv())->loadForEnv($env ?? 'dev', __DIR__.'/../.env');
26+
}
27+
28+
$env = $env ?? $_SERVER['APP_ENV'] ?? 'dev';
29+
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
30+
31+
if ($debug) {
32+
umask(0000);
33+
34+
if (class_exists(Debug::class)) {
35+
Debug::enable();
36+
}
37+
}
38+
39+
$kernel = new Kernel($env, $debug);
40+
$application = new Application($kernel);
41+
$application->run($input);

symfony/console/4.2/manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"copy-from-recipe": {
3+
"bin/": "%BIN_DIR%/"
4+
},
5+
"aliases": ["cli"]
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file is a "template" of which env vars need to be defined for your application
2-
# Copy this file to .env file for development, create environment variables when deploying to production
2+
# Override the variabled you want in .env.local for development, create environment variables when deploying to production
33
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

symfony/flex/1.0/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"copy-from-recipe": {
3-
".env.dist": ".env.dist"
3+
".env": ".env"
44
}
55
}

symfony/framework-bundle/4.2/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"#TRUSTED_HOSTS": "localhost,example.com"
1919
},
2020
"gitignore": [
21-
"/.env",
21+
"/.env.*",
2222
"/%PUBLIC_DIR%/bundles/",
2323
"/%VAR_DIR%/",
2424
"/vendor/"

symfony/framework-bundle/4.2/public/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if (!class_exists(Dotenv::class)) {
1313
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
1414
}
15-
(new Dotenv())->load(__DIR__.'/../.env');
15+
(new Dotenv())->loadForEnv('dev', __DIR__.'/../.env');
1616
}
1717

1818
$env = $_SERVER['APP_ENV'] ?? 'dev';

symfony/phpunit-bridge/4.2/.env.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# define your env variables for the test env here
2+
APP_ENV=test
3+
APP_SECRET=s$cretf0rt3st
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
5+
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
6+
exit(1);
7+
}
8+
if (false === getenv('SYMFONY_DEPRECATIONS_HELPER')) {
9+
// see https://symfony.com/doc/current/components/phpunit_bridge.html#making-tests-fail
10+
putenv('SYMFONY_DEPRECATIONS_HELPER=999999');
11+
}
12+
if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) {
13+
putenv('SYMFONY_PHPUNIT_REMOVE=');
14+
}
15+
if (false === getenv('SYMFONY_PHPUNIT_VERSION')) {
16+
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
17+
}
18+
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
19+
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
20+
}
21+
22+
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"copy-from-recipe": {
3+
"bin/": "%BIN_DIR%/",
4+
"phpunit.xml.dist": "phpunit.xml.dist",
5+
"tests/": "tests/",
6+
".env.test": ".env.test"
7+
},
8+
"gitignore": [
9+
".phpunit",
10+
"/phpunit.xml"
11+
],
12+
"aliases": ["simple-phpunit"]
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="tests/bootstrap.php"
9+
>
10+
<php>
11+
<ini name="error_reporting" value="-1" />
12+
<env name="KERNEL_CLASS" value="App\Kernel" />
13+
<env name="SHELL_VERBOSITY" value="-1" />
14+
</php>
15+
16+
<testsuites>
17+
<testsuite name="Project Test Suite">
18+
<directory>tests</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<filter>
23+
<whitelist>
24+
<directory>src</directory>
25+
</whitelist>
26+
</filter>
27+
28+
<listeners>
29+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
30+
</listeners>
31+
</phpunit>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<bg=blue;fg=white> </>
2+
<bg=blue;fg=white> How to test? </>
3+
<bg=blue;fg=white> </>
4+
5+
* <fg=blue>Write</> test cases in the <comment>tests/</> folder
6+
* <fg=blue>Run</> <comment>php bin/phpunit</>

symfony/phpunit-bridge/4.2/tests/.gitignore

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require __DIR__.'/../vendor/autoload.php';
4+
5+
use Symfony\Component\Dotenv\Dotenv;
6+
7+
// The check is to ensure we don't use .env if APP_ENV is defined
8+
if (!isset($_SERVER['APP_ENV'])) {
9+
if (!class_exists(Dotenv::class)) {
10+
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
11+
}
12+
(new Dotenv())->loadForEnv('test', __DIR__.'/../.env');
13+
}

0 commit comments

Comments
 (0)