New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for existence of vendor directory for better error message #1301
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks for the PR 😍 How to test these changes in your application
Diff between recipe versionsIn order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. symfony/console3.3 vs 4.2diff --git a/symfony/console/3.3/config/bootstrap.php b/symfony/console/4.2/config/bootstrap.php
index 2a47186..55560fb 100644
--- a/symfony/console/3.3/config/bootstrap.php
+++ b/symfony/console/4.2/config/bootstrap.php
@@ -13,38 +13,8 @@ if (!class_exists(Dotenv::class)) {
if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
(new Dotenv(false))->populate($env);
} else {
- $path = dirname(__DIR__).'/.env';
- $dotenv = new Dotenv(false);
-
// load all the .env files
- if (method_exists($dotenv, 'loadEnv')) {
- $dotenv->loadEnv($path);
- } else {
- // fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added)
-
- if (file_exists($path) || !file_exists($p = "$path.dist")) {
- $dotenv->load($path);
- } else {
- $dotenv->load($p);
- }
-
- if (null === $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) {
- $dotenv->populate(array('APP_ENV' => $env = 'dev'));
- }
-
- if ('test' !== $env && file_exists($p = "$path.local")) {
- $dotenv->load($p);
- $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env;
- }
-
- if (file_exists($p = "$path.$env")) {
- $dotenv->load($p);
- }
-
- if (file_exists($p = "$path.$env.local")) {
- $dotenv->load($p);
- }
- }
+ (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
}
$_SERVER += $_ENV; 4.2 vs 4.4diff --git a/symfony/console/4.2/bin/console b/symfony/console/4.4/bin/console
index 5cef879..5de0e1c 100755
--- a/symfony/console/4.2/bin/console
+++ b/symfony/console/4.4/bin/console
@@ -4,7 +4,7 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
-use Symfony\Component\Debug\Debug;
+use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; 4.4 vs 5.1diff --git a/symfony/console/4.4/bin/console b/symfony/console/5.1/bin/console
index 5de0e1c..8fe9d49 100755
--- a/symfony/console/4.4/bin/console
+++ b/symfony/console/5.1/bin/console
@@ -4,6 +4,7 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
+use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
@@ -14,8 +15,8 @@ set_time_limit(0);
require dirname(__DIR__).'/vendor/autoload.php';
-if (!class_exists(Application::class)) {
- throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.');
+if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
+ throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
$input = new ArgvInput();
@@ -27,7 +28,7 @@ if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
-require dirname(__DIR__).'/config/bootstrap.php';
+(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);
diff --git a/symfony/console/4.4/config/bootstrap.php b/symfony/console/4.4/config/bootstrap.php
deleted file mode 100644
index 55560fb..0000000
--- a/symfony/console/4.4/config/bootstrap.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-use Symfony\Component\Dotenv\Dotenv;
-
-require dirname(__DIR__).'/vendor/autoload.php';
-
-if (!class_exists(Dotenv::class)) {
- throw new LogicException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
-}
-
-// Load cached env vars if the .env.local.php file exists
-// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
-if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
- (new Dotenv(false))->populate($env);
-} else {
- // load all the .env files
- (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
-}
-
-$_SERVER += $_ENV;
-$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
-$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
-$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
diff --git a/symfony/console/4.4/manifest.json b/symfony/console/5.1/manifest.json
index c00421d..b0e9e1d 100644
--- a/symfony/console/4.4/manifest.json
+++ b/symfony/console/5.1/manifest.json
@@ -1,7 +1,6 @@
{
"copy-from-recipe": {
- "bin/": "%BIN_DIR%/",
- "config/": "%CONFIG_DIR%/"
+ "bin/": "%BIN_DIR%/"
},
"aliases": ["cli"]
} 5.1 vs 5.3diff --git a/symfony/console/5.1/bin/console b/symfony/console/5.3/bin/console
index 8fe9d49..d8d530e 100755
--- a/symfony/console/5.1/bin/console
+++ b/symfony/console/5.3/bin/console
@@ -3,41 +3,19 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
-use Symfony\Component\Console\Input\ArgvInput;
-use Symfony\Component\Dotenv\Dotenv;
-use Symfony\Component\ErrorHandler\Debug;
-if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
- echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
+if (!is_dir(dirname(__DIR__).'/vendor')) {
+ throw new LogicException('Dependencies are missing. Try running "composer install".');
}
-set_time_limit(0);
-
-require dirname(__DIR__).'/vendor/autoload.php';
-
-if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
- throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
-}
-
-$input = new ArgvInput();
-if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
- putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
+if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
+ throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}
-if ($input->hasParameterOption('--no-debug', true)) {
- putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
-}
-
-(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
-if ($_SERVER['APP_DEBUG']) {
- umask(0000);
-
- if (class_exists(Debug::class)) {
- Debug::enable();
- }
-}
+return function (array $context) {
+ $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
-$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
-$application = new Application($kernel);
-$application->run($input);
+ return new Application($kernel);
+}; |
fabpot
approved these changes
Mar 22, 2024
stof
approved these changes
Mar 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The error message
Symfony Runtime is missing. Try running "composer require symfony/runtime".
is missleading if no vendor directory exists. In that case somebody want to run a Symfony project just need to runcomposer install
.