Skip to content

Commit a689fb7

Browse files
Merge branch '7.4' into 8.0
* 7.4: [FrameworkBundle] Change HttpCache directory to use new getShareDir [Runtime] Expose `project_dir` as `APP_PROJECT_DIR` env var
2 parents 47be07a + cfa878e commit a689fb7

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Expose the runtime class in `$_SERVER['APP_RUNTIME']`
1111
* Expose the runtime options in `$_SERVER['APP_RUNTIME_OPTIONS']`
1212
* Make `project_dir` configurable in `composer.json`
13+
* Expose `project_dir` as `APP_PROJECT_DIR` env var
1314

1415
6.4
1516
---

SymfonyRuntime.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class SymfonyRuntime extends GenericRuntime
8888
* error_handler?: string|false,
8989
* env_var_name?: string,
9090
* debug_var_name?: string,
91+
* project_dir_var?: string|false,
9192
* dotenv_overload?: ?bool,
9293
* dotenv_extra_paths?: ?string[],
9394
* worker_loop_max?: int, // Use 0 or a negative integer to never restart the worker. Default: 500
@@ -111,6 +112,14 @@ public function __construct(array $options = [])
111112
$this->getInput();
112113
}
113114

115+
if (isset($options['project_dir']) && $projectDirVar = $options['project_dir_var'] ?? 'APP_PROJECT_DIR') {
116+
$_SERVER[$projectDirVar] = $_ENV[$projectDirVar] = $options['project_dir'];
117+
118+
if ($options['use_putenv'] ?? false) {
119+
putenv($projectDirVar.'='.$options['project_dir']);
120+
}
121+
}
122+
114123
if (!($options['disable_dotenv'] ?? false) && isset($options['project_dir']) && !class_exists(MissingDotenv::class, false)) {
115124
$overrideExistingVars = $options['dotenv_overload'] ?? false;
116125
$dotenv = (new Dotenv($envKey, $debugKey))

Tests/phpt/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ SOME_VAR=foo_bar
22
ENV_MODE=foo
33
DEBUG_MODE=0
44
DEBUG_ENABLED=1
5+
SOME_VAR2=OK ${APP_PROJECT_DIR}

Tests/phpt/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env.app_project_dir*
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SOME_VAR=OK ${APP_PROJECT_DIR}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Component\HttpFoundation\Response;
14+
15+
require __DIR__.'/autoload.php';
16+
17+
return fn (Request $request, array $context) => new Response($context['SOME_VAR2']);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Dotenv sees APP_PROJECT_DIR during boot
3+
--INI--
4+
display_errors=1
5+
--FILE--
6+
<?php
7+
8+
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_app_project_dir.php';
9+
10+
?>
11+
--EXPECTF--
12+
OK %s%eTests%ephpt

0 commit comments

Comments
 (0)