55namespace Spiral \RoadRunnerLaravel \Console \Commands ;
66
77use InvalidArgumentException ;
8- use Spiral \RoadRunnerLaravel \WorkerInterface ;
98use Symfony \Component \Console \Input \InputOption ;
109use Symfony \Component \Console \Input \InputInterface ;
1110use Symfony \Component \Console \Output \OutputInterface ;
@@ -19,17 +18,11 @@ class StartCommand extends \Symfony\Component\Console\Command\Command
1918 * Option names.
2019 */
2120 protected const
21+ OPTION_WORKER_MODE = 'worker-mode ' ,
2222 OPTION_LARAVEL_PATH = 'laravel-path ' ,
2323 OPTION_RELAY_DSN = 'relay-dsn ' ,
2424 OPTION_REFRESH_APP = 'refresh-app ' ;
2525
26- /**
27- * Worker instance.
28- *
29- * @var WorkerInterface
30- */
31- protected WorkerInterface $ worker ;
32-
3326 /**
3427 * @var string|null
3528 */
@@ -38,14 +31,12 @@ class StartCommand extends \Symfony\Component\Console\Command\Command
3831 /**
3932 * Create a new command instance.
4033 *
41- * @var WorkerInterface $worker
42- * @var string|null $laravel_base_path
34+ * @var string|null $laravel_base_path
4335 */
44- public function __construct (WorkerInterface $ worker , ?string $ laravel_base_path = null )
36+ public function __construct (?string $ laravel_base_path = null )
4537 {
4638 parent ::__construct ();
4739
48- $ this ->worker = $ worker ;
4940 $ this ->laravel_base_path = $ laravel_base_path ;
5041 }
5142
@@ -81,6 +72,14 @@ protected function configure(): void
8172 InputOption::VALUE_NONE ,
8273 'Refresh application instance on each HTTP request (avoid this for performance reasons) '
8374 );
75+
76+ $ this ->addOption (
77+ static ::OPTION_WORKER_MODE ,
78+ null ,
79+ InputOption::VALUE_REQUIRED ,
80+ 'Worker mode ' , /** @see \Spiral\RoadRunner\Environment\Mode */
81+ WorkerFactory::MODE_AUTO
82+ );
8483 }
8584
8685 /**
@@ -94,19 +93,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9493 $ this ->getRelayDSN ($ input ),
9594 );
9695
96+ $ worker = (new WorkerFactory ($ options ->getAppBasePath ()))->make ($ mode = $ this ->getWorkerMode ($ input ));
97+
9798 if ($ output ->isDebug ()) {
9899 $ hints = [
99- 'Laravel base path ' => $ options ->getAppBasePath (),
100+ 'Laravel base path ' => $ options ->getAppBasePath (),
100101 'Application refreshing ' => $ options ->getRefreshApp () ? 'yes ' : 'no ' ,
101- 'Relay DSN ' => $ options ->getRelayDsn (),
102+ 'Relay DSN ' => $ options ->getRelayDsn (),
103+ 'Mode ' => $ mode ,
104+ 'Worker class ' => \get_class ($ worker ),
102105 ];
103106
104107 foreach ($ hints as $ key => $ value ) {
105108 $ output ->writeln (\sprintf ('%s: <comment>%s</comment> ' , $ key , $ value ));
106109 }
107110 }
108111
109- $ this -> worker ->start ($ options );
112+ $ worker ->start ($ options );
110113
111114 return 0 ;
112115 }
@@ -133,6 +136,24 @@ protected function getLaravelBasePath(InputInterface $input): string
133136 throw new InvalidArgumentException ("Laravel base path was not set " );
134137 }
135138
139+ /**
140+ * @param InputInterface $input
141+ *
142+ * @return string
143+ *
144+ * @throws InvalidArgumentException
145+ */
146+ protected function getWorkerMode (InputInterface $ input ): string
147+ {
148+ $ worker_mode = $ input ->getOption (static ::OPTION_WORKER_MODE );
149+
150+ if (\is_string ($ worker_mode ) && !empty ($ worker_mode )) {
151+ return $ worker_mode ;
152+ }
153+
154+ throw new InvalidArgumentException ("Invalid option value for the worker mode " );
155+ }
156+
136157 /**
137158 * @param InputInterface $input
138159 *
0 commit comments