From 9521ccad3b00fe384af0ab8f4a6b38ffcb724d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=99=88=E5=8F=94=E5=8F=94?= Date: Tue, 19 Jun 2018 17:16:29 +0800 Subject: [PATCH] update --- src/Commands.php | 32 +++++++++++++++++++++++++++++++- src/stubs/event.stub | 28 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/stubs/event.stub 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 @@ +