Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug #1

Merged
merged 2 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ public function setSocketFile($socketFile): Bridge
$this->socketFile = $socketFile;
return $this;
}
}
}
11 changes: 7 additions & 4 deletions src/BridgeProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ function onAccept(Socket $socket)
* @var $package Package
*/
$package = unserialize($data);
$callback = $this->container->get($package->getCommand());
if (!$callback) {
/**
* @var $command CommandInterface
*/
$command = $this->container->get($package->getCommand());
if (!$command instanceof CommandInterface) {
$package = new Package();
$package->setStatus(Package::STATUS_COMMAND_NOT_EXIST);
$package->setMsg("command:{$package->getCommand()} is not exist");
Expand All @@ -51,7 +54,7 @@ function onAccept(Socket $socket)
try{
//结果在闭包中更改
$responsePackage->setStatus(Package::STATUS_SUCCESS);
call_user_func($callback,$package,$responsePackage,$socket);
$command->exec($package,$responsePackage,$socket);
}catch (\Throwable $throwable){
$responsePackage->setStatus(Package::STATUS_COMMAND_ERROR);
$responsePackage->setMsg($throwable->getMessage());
Expand All @@ -70,4 +73,4 @@ protected function onException(\Throwable $throwable, ...$args)
throw $throwable;
}
}
}
}
6 changes: 4 additions & 2 deletions src/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
namespace EasySwoole\Bridge;


use Swoole\Coroutine\Socket;

interface CommandInterface
{
public function commandName():string;
public function exec(...$arg);
}
public function exec(Package $package,Package $responsePackage,Socket $socket);
}