Skip to content

Commit d2599a1

Browse files
author
symfony-flex-server[bot]
authored
Merge pull request #481
2 parents 5b3ce90 + 95bb543 commit d2599a1

File tree

22 files changed

+157
-90
lines changed

22 files changed

+157
-90
lines changed
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
<?php
22

3-
use Symfony\Component\Dotenv\Dotenv;
4-
5-
// The check is to ensure we don't use .env in production
6-
if (!isset($_SERVER['APP_ENV'])) {
7-
if (!class_exists(Dotenv::class)) {
8-
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.');
9-
}
10-
(new Dotenv())->load(__DIR__.'/../../.env');
11-
}
3+
App\Kernel::bootstrapEnv('test');

phpunit/phpunit/4.7/.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS=App\\Kernel
3+
APP_SECRET='s$cretf0rt3st'
4+
SHELL_VERBOSITY=-1

phpunit/phpunit/4.7/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"copy-from-recipe": {
3+
".env.test": ".env.test",
34
"phpunit.xml.dist": "phpunit.xml.dist",
45
"tests/": "tests/"
56
},

phpunit/phpunit/4.7/phpunit.xml.dist

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.7/phpunit.xsd"
66
backupGlobals="false"
77
colors="true"
8-
bootstrap="vendor/autoload.php"
8+
bootstrap="tests/bootstrap.php"
99
>
1010
<php>
1111
<ini name="error_reporting" value="-1" />
12-
<env name="KERNEL_CLASS" value="App\Kernel" />
13-
<env name="APP_ENV" value="test" />
14-
<env name="APP_DEBUG" value="1" />
15-
<env name="APP_SECRET" value="s$cretf0rt3st" />
16-
<env name="SHELL_VERBOSITY" value="-1" />
17-
<!-- define your env variables for the test env here -->
1812
</php>
1913

2014
<testsuites>

phpunit/phpunit/4.7/tests/.gitignore

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
require dirname(__DIR__).'/vendor/autoload.php';
4+
5+
App\Kernel::bootstrapEnv('test');

symfony/console/3.3/bin/console

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,27 @@
33

44
use App\Kernel;
55
use Symfony\Bundle\FrameworkBundle\Console\Application;
6-
use Symfony\Component\Console\Input\ArgvInput;
76
use Symfony\Component\Debug\Debug;
8-
use Symfony\Component\Dotenv\Dotenv;
97

108
set_time_limit(0);
119

12-
require __DIR__.'/../vendor/autoload.php';
10+
require dirname(__DIR__).'/vendor/autoload.php';
1311

1412
if (!class_exists(Application::class)) {
1513
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
1614
}
1715

18-
if (!isset($_SERVER['APP_ENV'])) {
19-
if (!class_exists(Dotenv::class)) {
20-
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.');
21-
}
22-
(new Dotenv())->load(__DIR__.'/../.env');
23-
}
24-
25-
$input = new ArgvInput();
26-
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
27-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
16+
Kernel::bootstrapCli($_SERVER['argv']);
17+
Kernel::bootstrapEnv();
2818

29-
if ($debug) {
19+
if ($_SERVER['APP_DEBUG']) {
3020
umask(0000);
3121

3222
if (class_exists(Debug::class)) {
3323
Debug::enable();
3424
}
3525
}
3626

37-
$kernel = new Kernel($env, $debug);
27+
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
3828
$application = new Application($kernel);
39-
$application->run($input);
29+
$application->run();
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 variables 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/3.3/public/index.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22

33
use App\Kernel;
44
use Symfony\Component\Debug\Debug;
5-
use Symfony\Component\Dotenv\Dotenv;
65
use Symfony\Component\HttpFoundation\Request;
76

8-
require __DIR__.'/../vendor/autoload.php';
7+
require dirname(__DIR__).'/vendor/autoload.php';
98

10-
// The check is to ensure we don't use .env in production
11-
if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) {
12-
if (!class_exists(Dotenv::class)) {
13-
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.');
14-
}
15-
(new Dotenv())->load(__DIR__.'/../.env');
16-
}
17-
18-
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
19-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env));
9+
Kernel::bootstrapEnv();
2010

21-
if ($debug) {
11+
if ($_SERVER['APP_DEBUG']) {
2212
umask(0000);
2313

2414
Debug::enable();
@@ -32,7 +22,7 @@
3222
Request::setTrustedHosts(explode(',', $trustedHosts));
3323
}
3424

35-
$kernel = new Kernel($env, $debug);
25+
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
3626
$request = Request::createFromGlobals();
3727
$response = $kernel->handle($request);
3828
$response->send();

symfony/framework-bundle/3.3/src/Kernel.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Component\Config\Loader\LoaderInterface;
77
use Symfony\Component\Config\Resource\FileResource;
88
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\Dotenv\Dotenv;
910
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
1011
use Symfony\Component\Routing\RouteCollectionBuilder;
1112

@@ -58,4 +59,78 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
5859
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
5960
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
6061
}
62+
63+
public static function bootstrapCli(array &$argv)
64+
{
65+
// consume --env and --no-debug from the command line
66+
67+
// when using symfony/console v4.2 or higher, this should
68+
// be replaced by a call to Application::bootstrapEnv()
69+
70+
for ($i = 0; $i < \count($argv) && '--' !== $v = $argv[$i]; ++$i) {
71+
if ('--no-debug' === $v) {
72+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
73+
$argvUnset[$i] = true;
74+
break;
75+
}
76+
}
77+
78+
for ($i = 0; $i < \count($argv) && '--' !== $v = $argv[$i]; ++$i) {
79+
if (!$v || '-' !== $v[0] || !preg_match('/^-(?:-env(?:=|$)|e=?)(.*)$/D', $v, $v)) {
80+
continue;
81+
}
82+
if (!empty($v[1]) || !empty($argv[1 + $i])) {
83+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = empty($v[1]) ? $argv[1 + $i] : $v[1]);
84+
$argvUnset[$i] = $argvUnset[$i + empty($v[1])] = true;
85+
}
86+
break;
87+
}
88+
89+
if (!empty($argvUnset)) {
90+
$argv = array_values(array_diff_key($argv, $argvUnset));
91+
}
92+
}
93+
94+
public static function bootstrapEnv($env = null)
95+
{
96+
if (null !== $env) {
97+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $env);
98+
}
99+
100+
if ('prod' !== $_SERVER['APP_ENV'] = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : (isset($_ENV['APP_ENV']) ? $_ENV['APP_ENV'] : null)) {
101+
if (!class_exists(Dotenv::class)) {
102+
throw new \RuntimeException('The "APP_ENV" environment variable is not defined. You need to set it or run "composer require symfony/dotenv" to load it from a ".env" file.');
103+
}
104+
105+
// when using symfony/dotenv v4.2 or higher, this call and the related methods
106+
// below should be replaced by a call to the new Dotenv::loadEnv() method
107+
self::loadEnv(new Dotenv(), \dirname(__DIR__).'/.env');
108+
}
109+
110+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'dev';
111+
$_SERVER['APP_DEBUG'] = isset($_SERVER['APP_DEBUG']) ? $_SERVER['APP_DEBUG'] : (isset($_ENV['APP_DEBUG']) ? $_ENV['APP_DEBUG'] : 'prod' !== $_SERVER['APP_ENV']);
112+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
113+
}
114+
115+
private static function loadEnv(Dotenv $dotenv, $path)
116+
{
117+
$dotenv->load($path);
118+
119+
if (null === $env = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : (isset($_ENV['APP_ENV']) ? $_ENV['APP_ENV'] : null)) {
120+
$dotenv->populate(array('APP_ENV' => $env = 'dev'));
121+
}
122+
123+
if ('test' !== $env && file_exists($p = "$path.local")) {
124+
$dotenv->load($p);
125+
$env = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : (isset($_ENV['APP_ENV']) ? $_ENV['APP_ENV'] : $env);
126+
}
127+
128+
if (file_exists($p = "$path.$env")) {
129+
$dotenv->load($p);
130+
}
131+
132+
if (file_exists($p = "$path.$env.local")) {
133+
$dotenv->load($p);
134+
}
135+
}
61136
}

symfony/framework-bundle/4.2/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"#TRUSTED_HOSTS": "localhost,example.com"
1919
},
2020
"gitignore": [
21-
"/.env",
21+
"/.env.local",
22+
"/.env.*.local",
2223
"/%PUBLIC_DIR%/bundles/",
2324
"/%VAR_DIR%/",
2425
"/vendor/"

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22

33
use App\Kernel;
44
use Symfony\Component\Debug\Debug;
5-
use Symfony\Component\Dotenv\Dotenv;
65
use Symfony\Component\HttpFoundation\Request;
76

8-
require __DIR__.'/../vendor/autoload.php';
7+
require dirname(__DIR__).'/vendor/autoload.php';
98

10-
// The check is to ensure we don't use .env if APP_ENV is defined
11-
if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) {
12-
if (!class_exists(Dotenv::class)) {
13-
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.');
14-
}
15-
(new Dotenv())->load(__DIR__.'/../.env');
16-
}
17-
18-
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
19-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env));
9+
Kernel::bootstrapEnv();
2010

21-
if ($debug) {
11+
if ($_SERVER['APP_DEBUG']) {
2212
umask(0000);
2313

2414
Debug::enable();
@@ -32,7 +22,7 @@
3222
Request::setTrustedHosts(explode(',', $trustedHosts));
3323
}
3424

35-
$kernel = new Kernel($env, $debug);
25+
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
3626
$request = Request::createFromGlobals();
3727
$response = $kernel->handle($request);
3828
$response->send();

symfony/framework-bundle/4.2/src/Kernel.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
66
use Symfony\Component\Config\Loader\LoaderInterface;
77
use Symfony\Component\Config\Resource\FileResource;
8+
use Symfony\Component\Console\Application;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Symfony\Component\Dotenv\Dotenv;
911
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
1012
use Symfony\Component\Routing\RouteCollectionBuilder;
1113

@@ -58,4 +60,29 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
5860
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
5961
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
6062
}
63+
64+
public static function bootstrapCli(array &$argv)
65+
{
66+
// consume --env and --no-debug from the command line
67+
Application::bootstrapEnv($argv);
68+
}
69+
70+
public static function bootstrapEnv(string $env = null)
71+
{
72+
if (null !== $env) {
73+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $env);
74+
}
75+
76+
if ('prod' !== $_SERVER['APP_ENV'] = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) {
77+
if (!class_exists(Dotenv::class)) {
78+
throw new \RuntimeException('The "APP_ENV" environment variable is not defined. You need to set it or run "composer require symfony/dotenv" to load it from a ".env" file.');
79+
}
80+
81+
(new Dotenv())->loadEnv(\dirname(__DIR__).'/.env');
82+
}
83+
84+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $_SERVER['APP_ENV'] ?? $_SERVER['APP_ENV'] ?? 'dev';
85+
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
86+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
87+
}
6188
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS=App\\Kernel
3+
APP_SECRET='s$cretf0rt3st'
4+
SHELL_VERBOSITY=-1
5+
SYMFONY_DEPRECATIONS_HELPER=999999
6+
SYMFONY_PHPUNIT_VERSION=6.5

symfony/phpunit-bridge/3.3/bin/phpunit

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-php
55
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
66
exit(1);
77
}
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-
}
8+
9+
$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
10+
App\Kernel::bootstrapEnv('test');
11+
$classLoader->unregister();
12+
1213
if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) {
1314
putenv('SYMFONY_PHPUNIT_REMOVE=symfony/yaml');
1415
}
15-
if (false === getenv('SYMFONY_PHPUNIT_VERSION')) {
16-
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
17-
}
1816
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
1917
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
2018
}

symfony/phpunit-bridge/3.3/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"copy-from-recipe": {
3+
".env.test": ".env.test",
34
"bin/": "%BIN_DIR%/",
45
"config/": "%CONFIG_DIR%/",
56
"phpunit.xml.dist": "phpunit.xml.dist",

symfony/phpunit-bridge/3.3/phpunit.xml.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
>
1010
<php>
1111
<ini name="error_reporting" value="-1" />
12-
<env name="KERNEL_CLASS" value="App\Kernel" />
13-
<env name="APP_ENV" value="test" />
14-
<env name="APP_DEBUG" value="1" />
15-
<env name="APP_SECRET" value="s$cretf0rt3st" />
16-
<env name="SHELL_VERBOSITY" value="-1" />
17-
<!-- define your env variables for the test env here -->
1812
</php>
1913

2014
<testsuites>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS=App\\Kernel
3+
APP_SECRET='s$cretf0rt3st'
4+
SHELL_VERBOSITY=-1
5+
SYMFONY_DEPRECATIONS_HELPER=999999
6+
SYMFONY_PHPUNIT_VERSION=6.5

symfony/phpunit-bridge/4.1/bin/phpunit

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-php
55
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
66
exit(1);
77
}
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-
}
8+
9+
$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
10+
App\Kernel::bootstrapEnv('test');
11+
$classLoader->unregister();
12+
1213
if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) {
1314
putenv('SYMFONY_PHPUNIT_REMOVE=');
1415
}
15-
if (false === getenv('SYMFONY_PHPUNIT_VERSION')) {
16-
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
17-
}
1816
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
1917
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
2018
}

0 commit comments

Comments
 (0)