File tree Expand file tree Collapse file tree 2 files changed +71
-1
lines changed
Expand file tree Collapse file tree 2 files changed +71
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Statamic \Cli ;
4+
5+ use Symfony \Component \Console \Output \OutputInterface ;
6+ use Symfony \Component \Process \Exception \RuntimeException ;
7+ use Symfony \Component \Process \Process ;
8+
9+ class Artisan
10+ {
11+ protected $ output ;
12+ protected $ cwd ;
13+
14+ /**
15+ * Instantiate Laravel `artisan` command wrapper.
16+ */
17+ public function __construct (OutputInterface $ output )
18+ {
19+ $ this ->output = $ output ;
20+ }
21+
22+ /**
23+ * Get or set current working directory.
24+ *
25+ * @param mixed $cwd
26+ * @return mixed
27+ */
28+ public function cwd ($ cwd = null )
29+ {
30+ if (func_num_args () === 0 ) {
31+ return $ this ->cwd ?? getcwd ();
32+ }
33+
34+ $ this ->cwd = $ cwd ;
35+
36+ return $ this ;
37+ }
38+
39+ /**
40+ * Run artisan command.
41+ *
42+ * @param mixed $commandParts
43+ * @return int
44+ */
45+ public function run (...$ commandParts )
46+ {
47+ if (! is_file ($ this ->cwd ().'/artisan ' )) {
48+ throw new \RuntimeException ('This does not appear to be a Laravel project. ' );
49+ }
50+
51+ $ process = (new Process (array_merge ([PHP_BINARY , 'artisan ' ], $ commandParts )))
52+ ->setTimeout (null );
53+
54+ if ($ this ->cwd ) {
55+ $ process ->setWorkingDirectory ($ this ->cwd );
56+ }
57+
58+ try {
59+ $ process ->setTty (true );
60+ } catch (RuntimeException $ e ) {
61+ // TTY not supported. Move along.
62+ }
63+
64+ $ process ->run (function ($ type , $ line ) {
65+ $ this ->output ->write ($ line );
66+ });
67+
68+ return $ process ->getExitCode ();
69+ }
70+ }
Original file line number Diff line number Diff line change @@ -610,7 +610,7 @@ protected function configureDatabaseConnection()
610610 $ command [] = '--no-interaction ' ;
611611 }
612612
613- $ migrate = (new Please ($ this ->output ))
613+ $ migrate = (new Artisan ($ this ->output ))
614614 ->cwd ($ this ->absolutePath )
615615 ->run (...$ command );
616616
You can’t perform that action at this time.
0 commit comments