Skip to content

Commit 9521cca

Browse files
committed
update
1 parent 687ef48 commit 9521cca

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/Commands.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ class Commands extends Command
1717

1818
public function handle()
1919
{
20+
$this->checkEventFile();
21+
22+
$this->info('Welcome use Workerman server');
23+
2024
global $argv;
2125

2226
$action = $this->argument('action');
2327

2428
if (!in_array($action, ['start', 'stop', 'restart', 'reload', 'status', 'connections'])) {
25-
return 'Error';
29+
echo "Error";
30+
return;
2631
}
2732
$argv[1] = $action;
2833
$argv[2] = $this->option('d') ? '-d' : '';
@@ -77,4 +82,29 @@ private function startRegister()
7782
{
7883
new Register('text://0.0.0.0:1236');
7984
}
85+
86+
private function checkEventFile()
87+
{
88+
if (!is_dir(app_path('Workerman'))) {
89+
$this->warn('Workerman Path Notexist');
90+
$this->laravel['files']->makeDirectory(app_path('Workerman'), 0755, true, true);
91+
$this->info('Make Workerman Path was created.');
92+
}
93+
94+
$eventFile = app_path('Workerman/Events.php');
95+
if (file_exists($eventFile)) {
96+
$this->info('Workerman EventFile already exists');
97+
} else {
98+
$contents = $this->getStub('event');
99+
$this->warn('Workerman EventFile Notexist');
100+
$this->laravel['files']->put($eventFile, $contents);
101+
$this->info('Make Workerman EventFile was created.');
102+
}
103+
}
104+
105+
private function getStub($name)
106+
{
107+
return $this->laravel['files']->get(__DIR__ . "/stubs/$name.stub");
108+
}
109+
80110
}

src/stubs/event.stub

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Workerman;
4+
5+
class Events
6+
{
7+
8+
public static function onWorkerStart($businessWorker)
9+
{
10+
}
11+
12+
public static function onConnect($client_id)
13+
{
14+
}
15+
16+
public static function onWebSocketConnect($client_id, $data)
17+
{
18+
19+
}
20+
21+
public static function onMessage($client_id, $message)
22+
{
23+
}
24+
25+
public static function onClose($client_id)
26+
{
27+
}
28+
}

0 commit comments

Comments
 (0)