Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/Artisan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Statamic\Cli;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Process;

class Artisan
{
protected $output;
protected $cwd;

/**
* Instantiate Laravel `artisan` command wrapper.
*/
public function __construct(OutputInterface $output)
{
$this->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();
}
}
2 changes: 1 addition & 1 deletion src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down