-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
2,673 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace Imi; | ||
|
||
use Imi\RequestContext; | ||
|
||
abstract class ConnectContext | ||
{ | ||
private static $context = []; | ||
|
||
/** | ||
* 为当前请求创建上下文 | ||
* @return void | ||
*/ | ||
public static function create($fd) | ||
{ | ||
if(!RequestContext::exsits()) | ||
{ | ||
RequestContext::create(); | ||
} | ||
RequestContext::set('fd', $fd); | ||
if(!isset(static::$context[$fd])) | ||
{ | ||
static::$context[$fd] = []; | ||
} | ||
} | ||
|
||
/** | ||
* 销毁当前请求的上下文 | ||
* @return void | ||
*/ | ||
public static function destroy($fd) | ||
{ | ||
if(isset(static::$context[$fd])) | ||
{ | ||
unset(static::$context[$fd]); | ||
} | ||
} | ||
|
||
/** | ||
* 判断当前请求上下文是否存在 | ||
* @return boolean | ||
*/ | ||
public static function exsits() | ||
{ | ||
if(RequestContext::exsits()) | ||
{ | ||
return isset(static::$context[RequestContext::get('fd')]); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* 获取上下文数据 | ||
* @param string $name | ||
* @param mixed $default | ||
* @return mixed | ||
*/ | ||
public static function get($name, $default = null) | ||
{ | ||
return static::$context[RequestContext::get('fd')][$name] ?? $default; | ||
} | ||
|
||
/** | ||
* 设置上下文数据 | ||
* @param string $name | ||
* @param mixed $value | ||
* @return void | ||
*/ | ||
public static function set($name, $value) | ||
{ | ||
static::$context[RequestContext::get('fd')][$name] = $value; | ||
} | ||
|
||
/** | ||
* 获取当前上下文 | ||
* @return array | ||
*/ | ||
public static function getContext() | ||
{ | ||
return static::$context[RequestContext::get('fd')] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<?php | ||
namespace Imi\Controller; | ||
|
||
/** | ||
* Http 控制器 | ||
*/ | ||
abstract class HttpController | ||
{ | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Imi\Controller; | ||
|
||
/** | ||
* WebSocket 控制器 | ||
*/ | ||
abstract class WebSocketController | ||
{ | ||
/** | ||
* 请求 | ||
* @var \Imi\Server\WebSocket\Server | ||
*/ | ||
public $server; | ||
|
||
/** | ||
* 桢 | ||
* @var \Imi\Server\WebSocket\Message\IFrame | ||
*/ | ||
public $frame; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,48 @@ | ||
<?php | ||
namespace Imi\Listener; | ||
|
||
use Imi\App; | ||
use Imi\Config; | ||
use Imi\Worker; | ||
use Imi\Util\File; | ||
use Imi\Main\Helper; | ||
use Imi\Util\Coroutine; | ||
use Imi\Bean\Annotation; | ||
use Imi\Pool\PoolConfig; | ||
use Imi\Event\EventParam; | ||
use Imi\Pool\PoolManager; | ||
use Imi\Cache\CacheManager; | ||
use Imi\Event\IEventListener; | ||
use Imi\Bean\Annotation\Listener; | ||
use Imi\Util\CoroutineChannelManager; | ||
use Imi\App; | ||
use Imi\Server\Event\Param\WorkStartEventParam; | ||
use Imi\Server\Event\Listener\IWorkStartEventListener; | ||
|
||
/** | ||
* @Listener(eventName="IMI.MAIN_SERVER.WORKER.START",priority=PHP_INT_MAX) | ||
*/ | ||
class WorkerInit implements IEventListener | ||
class WorkerInit implements IWorkStartEventListener | ||
{ | ||
/** | ||
* 事件处理方法 | ||
* @param EventParam $e | ||
* @return void | ||
*/ | ||
public function handle(EventParam $e) | ||
public function handle(WorkStartEventParam $e) | ||
{ | ||
// 当前进程的 WorkerID 设置 | ||
Worker::setWorkerID($e->server->getSwooleServer()->worker_id); | ||
|
||
// 清除当前 worker 进程的 Bean 类缓存 | ||
$path = Config::get('@app.beanClassCache', sys_get_temp_dir()); | ||
$path = File::path($path, 'imiBeanCache', Worker::getWorkerID()); | ||
foreach (File::enum($path) as $file) | ||
{ | ||
if (is_file($file)) | ||
{ | ||
unlink($file); | ||
} | ||
} | ||
|
||
// 初始化 worker | ||
App::initWorker(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.