Skip to content
Merged
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 src/Symfony/Component/Runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
* Expose the runtime class in `$_SERVER['APP_RUNTIME']`
* Expose the runtime options in `$_SERVER['APP_RUNTIME_OPTIONS']`
* Make `project_dir` configurable in `composer.json`
* Expose `project_dir` as `APP_PROJECT_DIR` env var

6.4
---
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Runtime/SymfonyRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class SymfonyRuntime extends GenericRuntime
* error_handler?: string|false,
* env_var_name?: string,
* debug_var_name?: string,
* project_dir_var?: string|false,
* dotenv_overload?: ?bool,
* dotenv_extra_paths?: ?string[],
* worker_loop_max?: int, // Use 0 or a negative integer to never restart the worker. Default: 500
Expand All @@ -111,6 +112,14 @@ public function __construct(array $options = [])
$this->getInput();
}

if (isset($options['project_dir']) && $projectDirVar = $options['project_dir_var'] ?? 'APP_PROJECT_DIR') {
$_SERVER[$projectDirVar] = $_ENV[$projectDirVar] = $options['project_dir'];

if ($options['use_putenv'] ?? false) {
putenv($projectDirVar.'='.$options['project_dir']);
}
}

if (!($options['disable_dotenv'] ?? false) && isset($options['project_dir']) && !class_exists(MissingDotenv::class, false)) {
$overrideExistingVars = $options['dotenv_overload'] ?? false;
$dotenv = (new Dotenv($envKey, $debugKey))
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Runtime/Tests/phpt/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SOME_VAR=foo_bar
ENV_MODE=foo
DEBUG_MODE=0
DEBUG_ENABLED=1
SOME_VAR2=OK ${APP_PROJECT_DIR}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Runtime/Tests/phpt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env.app_project_dir*

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOME_VAR=OK ${APP_PROJECT_DIR}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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.
*/

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

require __DIR__.'/autoload.php';

return fn (Request $request, array $context) => new Response($context['SOME_VAR2']);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Dotenv sees APP_PROJECT_DIR during boot
--INI--
display_errors=1
--FILE--
<?php

require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_app_project_dir.php';

?>
--EXPECTF--
OK %s%eTests%ephpt