diff --git a/src/Artisan.php b/src/Artisan.php new file mode 100644 index 0000000..46f12c0 --- /dev/null +++ b/src/Artisan.php @@ -0,0 +1,70 @@ +output = $output; + } + + /** + * Get or set current working directory. + * + * @param mixed $cwd + * @return mixed + */ + public function cwd($cwd = null) + { + if (func_num_args() === 0) { + return $this->cwd ?? getcwd(); + } + + $this->cwd = $cwd; + + return $this; + } + + /** + * Run artisan command. + * + * @param mixed $commandParts + * @return int + */ + public function run(...$commandParts) + { + if (! is_file($this->cwd().'/artisan')) { + throw new \RuntimeException('This does not appear to be a Laravel project.'); + } + + $process = (new Process(array_merge([PHP_BINARY, 'artisan'], $commandParts))) + ->setTimeout(null); + + if ($this->cwd) { + $process->setWorkingDirectory($this->cwd); + } + + try { + $process->setTty(true); + } catch (RuntimeException $e) { + // TTY not supported. Move along. + } + + $process->run(function ($type, $line) { + $this->output->write($line); + }); + + return $process->getExitCode(); + } +} diff --git a/src/NewCommand.php b/src/NewCommand.php index a676037..83079ea 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -610,7 +610,7 @@ protected function configureDatabaseConnection() $command[] = '--no-interaction'; } - $migrate = (new Please($this->output)) + $migrate = (new Artisan($this->output)) ->cwd($this->absolutePath) ->run(...$command);