log = $log; $this->applicationUser = $applicationUser; $this->injectableFactory = $injectableFactory; } public function run(string $className, ?Params $params = null): void { if (!$className || !class_exists($className)) { $this->log->error("Application runner '{$className}' does not exist."); throw new RunnerException(); } $class = new ReflectionClass($className); if ( $class->getStaticPropertyValue('cli', false) && substr(php_sapi_name(), 0, 3) !== 'cli' ) { throw new RunnerException("Can be run only via CLI."); } if ($class->getStaticPropertyValue('setupSystemUser', false)) { $this->applicationUser->setupSystemUser(); } $runner = $this->injectableFactory->create($className); if ($runner instanceof Runner) { $runner->run(); return; } if ($runner instanceof RunnerParameterized) { $runner->run( $params ?? Params::create() ); return; } throw new RunnerException("Class should implement Runner or RunnerParameterized interface."); } }