Checks if the types of the passed arguments in a function/method call are compatible.
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * This file is part of Laravel Zero. |
||
7 | * |
||
8 | * (c) Nuno Maduro <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace LaravelZero\Framework\Providers\Composer; |
||
15 | |||
16 | use Throwable; |
||
17 | use function collect; |
||
18 | use Symfony\Component\Process\Process; |
||
19 | use Illuminate\Contracts\Foundation\Application; |
||
20 | use Symfony\Component\Console\Output\OutputInterface; |
||
21 | use LaravelZero\Framework\Contracts\Providers\ComposerContract; |
||
22 | |||
23 | /** |
||
24 | * @codeCoverageIgnore |
||
25 | * @internal |
||
26 | */ |
||
27 | final class Composer implements ComposerContract |
||
28 | { |
||
29 | /** |
||
30 | * Holds an instance of the app. |
||
31 | * |
||
32 | * @var \Illuminate\Contracts\Foundation\Application |
||
33 | */ |
||
34 | private $app; |
||
35 | |||
36 | /** |
||
37 | * Composer constructor. |
||
38 | * |
||
39 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function __construct(Application $app) |
||
44 | { |
||
45 | $this->app = $app; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function install(array $options = []): bool |
||
52 | { |
||
53 | $cmd = 'composer install'; |
||
54 | |||
55 | collect($options)->each( |
||
56 | function ($option) use (&$cmd) { |
||
57 | $cmd .= " $option"; |
||
58 | } |
||
59 | ); |
||
60 | |||
61 | return $this->run($cmd, $this->app->basePath()); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function require(string $package): bool |
||
68 | { |
||
69 | return $this->run("composer require $package", $this->app->basePath()); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function createProject(string $skeleton, string $projectName, array $options): bool |
||
76 | { |
||
77 | $cmd = "composer create-project $skeleton $projectName"; |
||
78 | |||
79 | collect($options)->each( |
||
80 | function ($option) use (&$cmd) { |
||
81 | $cmd .= " $option"; |
||
82 | } |
||
83 | ); |
||
84 | |||
85 | return $this->run($cmd); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Runs the provided command on the provided folder. |
||
90 | */ |
||
91 | private function run(string $cmd, string $cwd = null): bool |
||
92 | { |
||
93 | $process = new Process($cmd, $cwd); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
94 | |||
95 | if ($process->isTty()) { |
||
96 | $process->setTty(true); |
||
97 | } |
||
98 | |||
99 | try { |
||
100 | $output = $this->app->make(OutputInterface::class); |
||
101 | } catch (Throwable $e) { |
||
102 | $output = null; |
||
103 | } |
||
104 | |||
105 | if ($output) { |
||
106 | $output->write("\n"); |
||
107 | $process->run( |
||
108 | function ($type, $line) use ($output) { |
||
109 | $output->write($line); |
||
110 | } |
||
111 | ); |
||
112 | } else { |
||
113 | $process->run(); |
||
114 | } |
||
115 | |||
116 | return $process->isSuccessful(); |
||
117 | } |
||
118 | } |
||
119 |