Skip to content

Commit

Permalink
Refactor server and event
Browse files Browse the repository at this point in the history
  • Loading branch information
stelin committed Jul 13, 2019
1 parent 3c4a6a4 commit a8d5a8d
Show file tree
Hide file tree
Showing 52 changed files with 1,205 additions and 291 deletions.
6 changes: 3 additions & 3 deletions src/http-server/src/HttpContext.php
Expand Up @@ -13,9 +13,9 @@
/**
* Class HttpContext
*
* @Bean(scope=Bean::PROTOTYPE)
*
* @since 2.0
*
* @Bean(scope=Bean::PROTOTYPE)
*/
class HttpContext extends AbstractContext
{
Expand Down Expand Up @@ -43,7 +43,7 @@ class HttpContext extends AbstractContext
*/
public static function new(Request $request, Response $response): self
{
$instance = self::__instance();
$instance = self::__instance();

$instance->request = $request;
$instance->response = $response;
Expand Down
2 changes: 1 addition & 1 deletion src/http-server/src/Swoole/RequestListener.php
Expand Up @@ -9,7 +9,7 @@
use Swoft\Http\Message\Request as ServerRequest;
use Swoft\Http\Message\Response as ServerResponse;
use Swoft\Http\Server\HttpDispatcher;
use Swoft\Server\Swoole\RequestInterface;
use Swoft\Server\Contract\RequestInterface;
use Swoole\Http\Request;
use Swoole\Http\Response;

Expand Down
2 changes: 1 addition & 1 deletion src/rpc-server/src/Swoole/CloseListener.php
Expand Up @@ -8,7 +8,7 @@
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Rpc\Server\ServiceServerEvent;
use Swoft\Server\Swoole\CloseInterface;
use Swoft\Server\Contract\CloseInterface;
use Swoole\Server;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/rpc-server/src/Swoole/ConnectListener.php
Expand Up @@ -8,7 +8,7 @@
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Rpc\Server\ServiceServerEvent;
use Swoft\Server\Swoole\ConnectInterface;
use Swoft\Server\Contract\ConnectInterface;
use Swoole\Server;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/rpc-server/src/Swoole/ReceiveListener.php
Expand Up @@ -12,7 +12,7 @@
use Swoft\Rpc\Server\Request;
use Swoft\Rpc\Server\Response;
use Swoft\Rpc\Server\ServiceDispatcher;
use Swoft\Server\Swoole\ReceiveInterface;
use Swoft\Server\Contract\ReceiveInterface;
use Swoole\Server;

/**
Expand Down
33 changes: 33 additions & 0 deletions src/server/src/AutoLoader.php
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);


namespace Swoft\Server;


use Swoft\SwoftComponent;

/**
* Class AutoLoader
*
* @since 2.0
*/
class AutoLoader extends SwoftComponent
{
/**
* @return array
*/
public function getPrefixDirs(): array
{
return [
__NAMESPACE__ => __DIR__,
];
}

/**
* @return array
*/
public function metadata(): array
{
return [];
}
}
53 changes: 53 additions & 0 deletions src/server/src/Context/ShutdownContext.php
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);


namespace Swoft\Server\Context;


use ReflectionException;
use Swoft\Bean\Concern\PrototypeTrait;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Context\AbstractContext;
use Swoole\Server as SwooleServer;
use Swoft\Bean\Annotation\Mapping\Bean;

/**
* Class ShutdownContext
*
* @since 2.0
*
* @Bean(scope=Bean::PROTOTYPE)
*/
class ShutdownContext extends AbstractContext
{
use PrototypeTrait;

/**
* @var SwooleServer
*/
private $server;

/**
* @param SwooleServer $server
*
* @return ShutdownContext
* @throws ContainerException
* @throws ReflectionException
*/
public static function new(SwooleServer $server): self
{
$self = self::__instance();

$self->server = $server;

return $self;
}

/**
* @return SwooleServer
*/
public function getSwooleServer(): SwooleServer
{
return $this->server;
}
}
53 changes: 53 additions & 0 deletions src/server/src/Context/StartContext.php
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);


namespace Swoft\Server\Context;


use ReflectionException;
use Swoft\Bean\Concern\PrototypeTrait;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Context\AbstractContext;
use Swoole\Server as SwooleServer;
use Swoft\Bean\Annotation\Mapping\Bean;

/**
* Class StartContext
*
* @since 2.0
*
* @Bean(scope=Bean::PROTOTYPE)
*/
class StartContext extends AbstractContext
{
use PrototypeTrait;

/**
* @var SwooleServer
*/
private $server;

/**
* @param SwooleServer $server
*
* @return StartContext
* @throws ContainerException
* @throws ReflectionException
*/
public static function new(SwooleServer $server): self
{
$self = self::__instance();

$self->server = $server;

return $self;
}

/**
* @return SwooleServer
*/
public function getSwooleServer(): SwooleServer
{
return $this->server;
}
}
114 changes: 114 additions & 0 deletions src/server/src/Context/WorkerErrorContext.php
@@ -0,0 +1,114 @@
<?php declare(strict_types=1);


namespace Swoft\Server\Context;


use ReflectionException;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Concern\PrototypeTrait;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Context\AbstractContext;
use Swoole\Server as SwooleServer;

/**
* Class WorkerErrorContext
*
* @since 2.0
*
* @Bean(scope=Bean::PROTOTYPE)
*/
class WorkerErrorContext extends AbstractContext
{
use PrototypeTrait;

/**
* @var SwooleServer
*/
private $server;

/**
* @var int
*/
private $workerId;

/**
* @var int
*/
private $workerPid;

/**
* @var int
*/
private $exitCode;

/**
* @var int
*/
private $sigal;

/**
* @param SwooleServer $server
* @param int $workerId
*
* @param int $workerPid
* @param int $exitCode
* @param int $signal
*
* @return WorkerErrorContext
* @throws ContainerException
* @throws ReflectionException
*/
public static function new(SwooleServer $server, int $workerId, int $workerPid, int $exitCode, int $signal): self
{
$self = self::__instance();

$self->server = $server;
$self->workerId = $workerId;
$self->workerPid = $workerPid;
$self->exitCode = $exitCode;
$self->sigal = $signal;

return $self;
}

/**
* @return SwooleServer
*/
public function getSwooleServer(): SwooleServer
{
return $this->server;
}

/**
* @return int
*/
public function getWorkerId(): int
{
return $this->workerId;
}

/**
* @return int
*/
public function getWorkerPid(): int
{
return $this->workerPid;
}

/**
* @return int
*/
public function getExitCode(): int
{
return $this->exitCode;
}

/**
* @return int
*/
public function getSigal(): int
{
return $this->sigal;
}
}
68 changes: 68 additions & 0 deletions src/server/src/Context/WorkerStartContext.php
@@ -0,0 +1,68 @@
<?php declare(strict_types=1);


namespace Swoft\Server\Context;


use ReflectionException;
use Swoft\Bean\Concern\PrototypeTrait;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Context\AbstractContext;
use Swoole\Server as SwooleServer;
use Swoft\Bean\Annotation\Mapping\Bean;

/**
* Class WorkerStartContext
*
* @since 2.0
*
* @Bean(scope=Bean::PROTOTYPE)
*/
class WorkerStartContext extends AbstractContext
{
use PrototypeTrait;

/**
* @var SwooleServer
*/
private $server;

/**
* @var int
*/
private $workerId;

/**
* @param SwooleServer $server
* @param int $workerId
*
* @return WorkerStartContext
* @throws ContainerException
* @throws ReflectionException
*/
public static function new(SwooleServer $server, int $workerId): self
{
$self = self::__instance();

$self->server = $server;
$self->workerId = $workerId;

return $self;
}

/**
* @return SwooleServer
*/
public function getSwooleServer(): SwooleServer
{
return $this->server;
}

/**
* @return int
*/
public function getWorkerId(): int
{
return $this->workerId;
}
}

0 comments on commit a8d5a8d

Please sign in to comment.