Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cjango committed Jun 19, 2018
1 parent 687ef48 commit 9521cca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' : '';
Expand Down Expand Up @@ -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");
}

}
28 changes: 28 additions & 0 deletions src/stubs/event.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Workerman;

class Events
{

public static function onWorkerStart($businessWorker)
{
}

public static function onConnect($client_id)
{
}

public static function onWebSocketConnect($client_id, $data)
{

}

public static function onMessage($client_id, $message)
{
}

public static function onClose($client_id)
{
}
}

0 comments on commit 9521cca

Please # to comment.