-
-
Save bhaidar/f3e29c77d95598d4249bd9c33b776e41 to your computer and use it in GitHub Desktop.
Laravel helper class to run composer command programmatically.
This file contains hidden or 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
| <?php | |
| namespace App; | |
| class Composer extends \Illuminate\Support\Composer | |
| { | |
| public function run(array $command) | |
| { | |
| // findComposer() resolves to composer's binary | |
| // $command is an array that looks like ['composer', 'some-composer-command'] | |
| $command = array_merge($this->findComposer(), $command); | |
| // we then pass the command array to getProcess() | |
| // getProcess() returns a Symfony Process() instance, which runs the command for us in the shell | |
| // the run() method execute the composer command | |
| $this->getProcess($command)->run(function ($type, $data) { | |
| // $type can be 'err' or 'out' | |
| // 'err' when there is an error | |
| // 'out' is stdout from the command | |
| // $data is the command output | |
| // ie whatever composer spits out when the command runs. | |
| echo $data; | |
| }, [ | |
| // we can pass in env var to the process instance here | |
| // setting any additional environmental variable to the process | |
| 'COMPOSER_HOME' => '$HOME/.config/composer' | |
| ]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment