diff --git a/src/Commands.php b/src/Commands.php index 43b38db..e4718b7 100644 --- a/src/Commands.php +++ b/src/Commands.php @@ -17,12 +17,17 @@ class Commands extends Command public function handle() { + $this->checkEventFile(); + + $this->info('Welcome use Workerman server'); + global $argv; $action = $this->argument('action'); if (!in_array($action, ['start', 'stop', 'restart', 'reload', 'status', 'connections'])) { - return 'Error'; + echo "Error"; + return; } $argv[1] = $action; $argv[2] = $this->option('d') ? '-d' : ''; @@ -77,4 +82,29 @@ private function startRegister() { new Register('text://0.0.0.0:1236'); } + + private function checkEventFile() + { + if (!is_dir(app_path('Workerman'))) { + $this->warn('Workerman Path Notexist'); + $this->laravel['files']->makeDirectory(app_path('Workerman'), 0755, true, true); + $this->info('Make Workerman Path was created.'); + } + + $eventFile = app_path('Workerman/Events.php'); + if (file_exists($eventFile)) { + $this->info('Workerman EventFile already exists'); + } else { + $contents = $this->getStub('event'); + $this->warn('Workerman EventFile Notexist'); + $this->laravel['files']->put($eventFile, $contents); + $this->info('Make Workerman EventFile was created.'); + } + } + + private function getStub($name) + { + return $this->laravel['files']->get(__DIR__ . "/stubs/$name.stub"); + } + } diff --git a/src/stubs/event.stub b/src/stubs/event.stub new file mode 100644 index 0000000..bb5c4d5 --- /dev/null +++ b/src/stubs/event.stub @@ -0,0 +1,28 @@ +