Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code style for PR.
  • Loading branch information
Fractal Zombie committed Dec 20, 2018
commit 4346606b0568e64f0a5daa958b1fe0a0d4bb9870
39 changes: 23 additions & 16 deletions src/Commands/HttpServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Commands;


use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Swoole\Process;
Expand Down Expand Up @@ -95,8 +94,10 @@ protected function start()
$this->info('Starting swoole http server...');
$this->info("Swoole http server started: <http://{$host}:{$port}>");
if ($this->isDaemon()) {
$this->info('> (You can run this command to ensure the ' .
'swoole_http_server process is running: ps aux|grep "swoole")');
$this->info(
'> (You can run this command to ensure the '.
'swoole_http_server process is running: ps aux|grep "swoole")'
);
}

$this->laravel->make('swoole.manager')->run();
Expand All @@ -109,7 +110,7 @@ protected function stop()
{
$pid = $this->getCurrentPid();

if (!$this->isRunning($pid)) {
if (! $this->isRunning($pid)) {
$this->error("Failed! There is no swoole_http_server process running.");

return;
Expand Down Expand Up @@ -153,7 +154,7 @@ protected function reload()
{
$pid = $this->getCurrentPid();

if (!$this->isRunning($pid)) {
if (! $this->isRunning($pid)) {
$this->error("Failed! There is no swoole_http_server process running.");

return;
Expand All @@ -163,7 +164,7 @@ protected function reload()

$isRunning = $this->killProcess($pid, SIGUSR1);

if (!$isRunning) {
if (! $isRunning) {
$this->error('> failure');

return;
Expand Down Expand Up @@ -220,8 +221,10 @@ protected function initAction()
{
$this->action = $this->argument('action');

if (!in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'], true)) {
$this->error("Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'.");
if (! in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'], true)) {
$this->error(
"Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'."
);

return;
}
Expand All @@ -236,7 +239,7 @@ protected function initAction()
*/
protected function isRunning($pid)
{
if (!$pid) {
if (! $pid) {
return false;
}

Expand Down Expand Up @@ -264,7 +267,7 @@ protected function killProcess($pid, $sig, $wait = 0)
$start = time();

do {
if (!$this->isRunning($pid)) {
if (! $this->isRunning($pid)) {
break;
}

Expand Down Expand Up @@ -330,14 +333,18 @@ protected function checkEnvironment()
$this->error("Swoole extension doesn't support Windows OS yet.");

return;
} else if (!extension_loaded('swoole')) {
$this->error("Can't detect Swoole extension installed.");
} else {
if (! extension_loaded('swoole')) {
$this->error("Can't detect Swoole extension installed.");

return;
} else if (!version_compare(swoole_version(), '4.0.0', 'ge')) {
$this->error("Your Swoole version must be higher than 4.0 to use coroutine.");
return;
} else {
if (! version_compare(swoole_version(), '4.0.0', 'ge')) {
$this->error("Your Swoole version must be higher than 4.0 to use coroutine.");

return;
return;
}
}
}
}
}
3 changes: 1 addition & 2 deletions src/Concerns/InteractsWithSwooleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Concerns;


use Illuminate\Contracts\Console\Application as ConsoleApp;
use Swoole\Table;
use SwooleTW\Http\Table\SwooleTable;
Expand Down Expand Up @@ -57,7 +56,7 @@ protected function registerTables()
*/
protected function bindSwooleTable()
{
if (!$this->app instanceof ConsoleApp) {
if (! $this->app instanceof ConsoleApp) {
$this->app->singleton(SwooleTable::class, function () {
return $this->currentTable;
});
Expand Down
15 changes: 7 additions & 8 deletions src/Concerns/InteractsWithWebsocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Concerns;


use Illuminate\Contracts\Container\Container;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -65,7 +64,7 @@ public function onOpen($swooleRequest)
// enable sandbox
$sandbox->enable();
// check if socket.io connection established
if (!$this->websocketHandler->onOpen($swooleRequest->fd, $illuminateRequest)) {
if (! $this->websocketHandler->onOpen($swooleRequest->fd, $illuminateRequest)) {
return;
}
// trigger 'connect' websocket event
Expand Down Expand Up @@ -129,7 +128,7 @@ public function onMessage($server, $frame)
*/
public function onClose($server, $fd, $reactorId)
{
if (!$this->isServerWebsocket($fd) || !$server instanceof Websocket) {
if (! $this->isServerWebsocket($fd) || ! $server instanceof Websocket) {
return;
}

Expand Down Expand Up @@ -162,7 +161,7 @@ public function pushMessage($server, array $data)
$payload = $this->payloadParser->encode($push->getEvent(), $push->getMessage());

// attach sender if not broadcast
if (!$push->isBroadcast() && $push->getSender() && !$push->hasOwnDescriptor()) {
if (! $push->isBroadcast() && $push->getSender() && ! $push->hasOwnDescriptor()) {
$push->addDescriptor($push->getSender());
}

Expand All @@ -173,7 +172,7 @@ public function pushMessage($server, array $data)

// push message to designated fds
foreach ($push->getDescriptors() as $descriptor) {
if ($server->exist($descriptor) || !$push->isBroadcastToDescriptor((int)$descriptor)) {
if ($server->exist($descriptor) || ! $push->isBroadcastToDescriptor((int)$descriptor)) {
$server->push($descriptor, $payload, $push->getOpcode());
}
}
Expand Down Expand Up @@ -256,7 +255,7 @@ protected function prepareWebsocketHandler()
{
$handlerClass = $this->container->make(Service::CONFIG_ALIAS)->get('swoole_websocket.handler');

if (!$handlerClass) {
if (! $handlerClass) {
throw new WebsocketNotSetInConfigException;
}

Expand Down Expand Up @@ -334,8 +333,8 @@ protected function loadWebsocketRoutes()
{
$routePath = $this->container->make(Service::CONFIG_ALIAS)->get('swoole_websocket.route_file');

if (!file_exists($routePath)) {
$routePath = __DIR__ . '/../../routes/websocket.php';
if (! file_exists($routePath)) {
$routePath = __DIR__.'/../../routes/websocket.php';
}

return require $routePath;
Expand Down
7 changes: 3 additions & 4 deletions src/Concerns/ResetApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Concerns;


use Illuminate\Contracts\Container\Container;
use SwooleTW\Http\Exceptions\SandboxException;
use SwooleTW\Http\Server\Resetters\ResetterContract;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected function setInitialProviders()
$providers = $this->config->get('swoole_http.providers', []);

foreach ($providers as $provider) {
if (class_exists($provider) && !in_array($provider, $this->providers)) {
if (class_exists($provider) && ! in_array($provider, $this->providers)) {
$providerClass = new $provider($app);
$this->providers[$provider] = $providerClass;
}
Expand All @@ -74,8 +73,8 @@ protected function setInitialResetters()

foreach ($resetters as $resetter) {
$resetterClass = $app->make($resetter);
if (!$resetterClass instanceof ResetterContract) {
throw new SandboxException("{$resetter} must implement " . ResetterContract::class);
if (! $resetterClass instanceof ResetterContract) {
throw new SandboxException("{$resetter} must implement ".ResetterContract::class);
}
$this->resetters[$resetter] = $resetterClass;
}
Expand Down
11 changes: 6 additions & 5 deletions src/Concerns/WithApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Concerns;


use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Support\Facades\Facade;
Expand Down Expand Up @@ -34,8 +33,10 @@ protected function bootstrap()
if ($this->framework === 'laravel') {
$bootstrappers = $this->getBootstrappers();
$this->app->bootstrapWith($bootstrappers);
} else if (is_null(Facade::getFacadeApplication())) {
$this->app->withFacades();
} else {
if (is_null(Facade::getFacadeApplication())) {
$this->app->withFacades();
}
}

$this->preResolveInstances();
Expand All @@ -57,7 +58,7 @@ protected function loadApplication()
*/
public function getApplication()
{
if (!$this->app instanceof Container) {
if (! $this->app instanceof Container) {
$this->app = $this->loadApplication();
$this->bootstrap();
}
Expand Down Expand Up @@ -108,7 +109,7 @@ protected function setFramework($framework)
{
$framework = strtolower($framework);

if (!in_array($framework, ['laravel', 'lumen'])) {
if (! in_array($framework, ['laravel', 'lumen'])) {
throw new FrameworkNotSupportException($framework);
}

Expand Down
41 changes: 24 additions & 17 deletions src/Controllers/SocketIOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

Expand All @@ -12,32 +11,40 @@ class SocketIOController

public function upgrade(Request $request)
{
if (!in_array($request->input('transport'), $this->transports)) {
return response()->json([
'code' => 0,
'message' => 'Transport unknown',
], 400);
if (! in_array($request->input('transport'), $this->transports)) {
return response()->json(
[
'code' => 0,
'message' => 'Transport unknown',
],
400
);
}

if ($request->has('sid')) {
return '1:6';
}

$payload = json_encode([
'sid' => base64_encode(uniqid()),
'upgrades' => ['websocket'],
'pingInterval' => Config::get('swoole_websocket.ping_interval'),
'pingTimeout' => Config::get('swoole_websocket.ping_timeout'),
]);
$payload = json_encode(
[
'sid' => base64_encode(uniqid()),
'upgrades' => ['websocket'],
'pingInterval' => Config::get('swoole_websocket.ping_interval'),
'pingTimeout' => Config::get('swoole_websocket.ping_timeout'),
]
);

return '97:0' . $payload . '2:40';
return '97:0'.$payload.'2:40';
}

public function reject()
{
return response()->json([
'code' => 3,
'message' => 'Bad request',
], 400);
return response()->json(
[
'code' => 3,
'message' => 'Bad request',
],
400
);
}
}
1 change: 0 additions & 1 deletion src/Coroutine/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Coroutine;


class ConnectionException extends \Exception
{
//
Expand Down
11 changes: 5 additions & 6 deletions src/Coroutine/Connectors/ConnectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Coroutine\Connectors;


use Illuminate\Support\Arr;
use SwooleTW\Http\Helpers\FW;

Expand Down Expand Up @@ -30,7 +29,7 @@ class ConnectorFactory
*
* @const string
*/
public const CONNECTOR_CLASS_PATH = __DIR__ . '/MySqlConnector.php';
public const CONNECTOR_CLASS_PATH = __DIR__.'/MySqlConnector.php';

/**
* @param string $version
Expand All @@ -40,7 +39,7 @@ class ConnectorFactory
public static function make(string $version): MySqlConnector
{
$isMatch = static::isFileVersionMatch($version);
$class = static::copy(static::stub($version), !$isMatch);
$class = static::copy(static::stub($version), ! $isMatch);

return new $class();
}
Expand All @@ -53,8 +52,8 @@ public static function make(string $version): MySqlConnector
public static function stub(string $version): string
{
return static::hasBreakingChanges($version)
? __DIR__ . '/../../../stubs/5.6/MySqlConnector.stub'
: __DIR__ . '/../../../stubs/5.5/MySqlConnector.stub';
? __DIR__.'/../../../stubs/5.6/MySqlConnector.stub'
: __DIR__.'/../../../stubs/5.5/MySqlConnector.stub';
}

/**
Expand All @@ -65,7 +64,7 @@ public static function stub(string $version): string
*/
public static function copy(string $stub, bool $rewrite = false): string
{
if (!file_exists(static::CONNECTOR_CLASS_PATH) || $rewrite) {
if (! file_exists(static::CONNECTOR_CLASS_PATH) || $rewrite) {
copy($stub, static::CONNECTOR_CLASS_PATH);
}

Expand Down
1 change: 0 additions & 1 deletion src/Coroutine/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Coroutine\Connectors;


use Illuminate\Database\Connectors\MySqlConnector as BaseConnector;
use Illuminate\Support\Str;
use SwooleTW\Http\Coroutine\PDO as SwoolePDO;
Expand Down
1 change: 0 additions & 1 deletion src/Coroutine/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SwooleTW\Http\Coroutine;


use Illuminate\Contracts\Container\Container;
use Swoole\Coroutine;

Expand Down
Loading