-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
- Laravel Version: 5.5.1
- PHP Version: 7.0.22
- Database Driver & Version: unrelated
Description:
This seem unrelated to laravel but please read.
When you try to install a package that also executes some scripts on install, like phpro/grumphp, you could run in errors because the autoload seems to be confused.
This ocurred to me when updating an app wich uses phpro/grumphp to laravel 5.5. I removed all the dependencies and executed composer install (without a lock file), this produced an error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 6 passed to Symfony\Component\Process\Process::__construct() must be of the type array, null given, called in /workspace/php/test/vendor/symfony/process/ProcessBuilder.php on line 274
Exception trace:
() at phar:///usr/bin/composer/vendor/symfony/process/Process.php:141
Symfony\Component\Process\Process->__construct() at /workspace/php/test/vendor/symfony/process/ProcessBuilder.php:274
Symfony\Component\Process\ProcessBuilder->getProcess() at /workspace/php/test/vendor/phpro/grumphp/src/Composer/GrumPHPPlugin.php:182
GrumPHP\Composer\GrumPHPPlugin->runGrumPhpCommand() at /workspace/php/test/vendor/phpro/grumphp/src/Composer/GrumPHPPlugin.php:137
...
You wont find any laravel related class, but if you look you will see that Process and ProcessBuilder are readed one from the phar (the composer phar) and another from the local vendor folder. So the version used of symfony/process differ (2.8 in the phar, 3.3 for laravel) and breaks the phpro/grumphp script that should run on installation.
After trying to debug this I realized that Illuminate\Foundation\ComposerScripts::postAutoloadDump loads the autoload of composer, removing this script off composer.json makes composer install work fine again. It looks like any script executed by composer after executing ComposerScripts::postAutoloadDump will have a "messed up" autoloader (I'm not shure of this), clashing the composer phar autoloader and the local autoloader.
A workaround could be change the composer.json like this:
{
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate"
],
"post-autoload-dump": [
"@php artisan package:discover"
]
},
}Seems like the order of execution of the scripts resolve the problem, the scripts of the package are executed first so there is no problem, at least for this case.
Steps To Reproduce:
$ laravel new test
$ cd test
$ composer require --dev phpro/grumphp -vvv
This is a edge case, maybe phpro/grumphp it's the only package producing errors, but I think that the problem is in the composer script defined by laravel. Maybe another package that uses symfony/process and runs on composer events would fall in the same problem.