Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Jul 25, 2018
1 parent 9ef6877 commit c43be1a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
19 changes: 10 additions & 9 deletions bin/easyswoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Install
{
public static function init()
{
\EasySwoole\Frame\Core::getInstance();
\EasySwoole\EasySwoole\Core::getInstance();
//强制更新easyswoole bin管理文件
if(is_file(EASYSWOOLE_ROOT . '/easyswoole')){
unlink(EASYSWOOLE_ROOT . '/easyswoole');
Expand Down Expand Up @@ -123,7 +123,7 @@ public static function showHelpForReload()

public static function showHelp()
{
$version = \EasySwoole\Frame\SysConst::VERSION;
$version = \EasySwoole\EasySwoole\SysConst::VERSION;
echo <<<DEFAULTHELP
\n欢迎使用为API而生的\e[32m easySwoole\e[0m 框架 当前版本: \e[34m{$version}\e[0m
Expand Down Expand Up @@ -168,8 +168,8 @@ public static function showHelp()
});

$com->setArgCallback('start',function ()use($com){
\EasySwoole\Frame\Core::getInstance()->initialize();
$conf = \EasySwoole\Frame\Config::getInstance();

$conf = \EasySwoole\EasySwoole\Config::getInstance();
if($com->getOptVal('d')){
$conf->setConf("MAIN_SERVER.SETTING.daemonize", true);
}
Expand All @@ -185,13 +185,14 @@ public static function showHelp()
Install::showTag('daemonize', $conf->getConf("MAIN_SERVER.SETTING.daemonize"));
Install::showTag('swoole version', phpversion('swoole'));
Install::showTag('php version', phpversion());
\EasySwoole\Frame\Core::getInstance()->createServer()->start();
\EasySwoole\EasySwoole\Core::getInstance()->initialize();
\EasySwoole\EasySwoole\Core::getInstance()->createServer()->start();
});

$com->setArgCallback('stop',function ()use($com){
$force = $com->getOptVal('f');
\EasySwoole\Frame\Core::getInstance()->initialize();
$Conf = \EasySwoole\Frame\Config::getInstance();
\EasySwoole\EasySwoole\Core::getInstance()->initialize();
$Conf = \EasySwoole\EasySwoole\Config::getInstance();
$pidFile = $Conf->getConf("MAIN_SERVER.SETTING.pid_file");
if (file_exists($pidFile)) {
$pid = file_get_contents($pidFile);
Expand Down Expand Up @@ -232,8 +233,8 @@ public static function showHelp()

$com->setArgCallback('reload',function ()use($com){
$all = $com->getOptVal('a');
\EasySwoole\Frame\Core::getInstance()->initialize();
$Conf = \EasySwoole\Frame\Config::getInstance();
\EasySwoole\EasySwoole\Core::getInstance()->initialize();
$Conf = \EasySwoole\EasySwoole\Config::getInstance();
$pidFile = $Conf->getConf("MAIN_SERVER.SETTING.pid_file");
if (file_exists($pidFile)) {
if (!$all) {
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
],
"require": {
"php": ">=7.1.0",
"ext-swoole": ">=4.0",
"ext-swoole": ">=4.0.3",
"easyswoole/component": "^1.0",
"easyswoole/spl": "^1.0",
"easyswoole/http": "^1.0",
"easyswoole/core": "^1.0",
"easyswoole/http": "^1.0",
"easyswoole/utility": "^1.0"
},
"require-dev": {
"easyswoole/swoole-ide-helper": "dev-master"
},
"autoload": {
"psr-4": {
"EasySwoole\\Frame\\": "src/"
"EasySwoole\\EasySwoole\\": "src/"
}
}
}
2 changes: 1 addition & 1 deletion src/AbstractInterface/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 下午6:32
*/

namespace EasySwoole\Frame\AbstractInterface;
namespace EasySwoole\EasySwoole\AbstractInterface;


use EasySwoole\Core\EventRegister;
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 下午5:46
*/

namespace EasySwoole\Frame;
namespace EasySwoole\EasySwoole;


use EasySwoole\Component\Singleton;
Expand Down
25 changes: 18 additions & 7 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
* Time: 下午6:07
*/

namespace EasySwoole\Frame;
namespace EasySwoole\EasySwoole;


use EasySwoole\Component\Di;
use EasySwoole\Component\Singleton;
use EasySwoole\Core\EventHelper;
use EasySwoole\Core\EventRegister;
use EasySwoole\Core\ServerManager;
use EasySwoole\Frame\AbstractInterface\Event;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\Http\WebService;
Expand All @@ -36,9 +38,9 @@ function initialize()
if(file_exists($file)){
require_once $file;
try{
$ref = new \ReflectionClass('EasySwoole\Frame\EasySwooleEvent');
$ref = new \ReflectionClass('EasySwoole\EasySwoole\EasySwooleEvent');
if(!$ref->implementsInterface(Event::class)){
die('global file for EasySwooleEvent is not compatible for EasySwoole\Frame\EasySwooleEvent');
die('global file for EasySwooleEvent is not compatible for EasySwoole\EasySwoole\EasySwooleEvent');
}
unset($ref);
}catch (\Throwable $throwable){
Expand Down Expand Up @@ -124,14 +126,20 @@ private function registerErrorHandler()

private function mainServerHook($type)
{
if($type != ServerManager::TYPE_SERVER){
if($type === ServerManager::TYPE_SERVER){

}else{
$namespace = Di::getInstance()->get(SysConst::HTTP_CONTROLLER_NAMESPACE);
if(empty($namespace)){
$namespace = 'App\\HttpController\\';
}
$depth = intval(Di::getInstance()->get(SysConst::HTTP_CONTROLLER_MAX_DEPTH));
$depth = $depth > 5 ? $depth : 5;
$webService = new WebService($namespace,$depth);
$max = intval(Di::getInstance()->get(SysConst::HTTP_CONTROLLER_POOL_MAX_NUM));
if($max == 0){
$max = 20;
}
$webService = new WebService($namespace,$depth,$max);
$httpExceptionHandler = Di::getInstance()->get(SysConst::HTTP_EXCEPTION_HANDLER);
if($httpExceptionHandler){
$webService->setExceptionHandler($httpExceptionHandler);
Expand All @@ -140,7 +148,10 @@ private function mainServerHook($type)
EventHelper::on($server,EventRegister::onRequest,function (\swoole_http_request $request,\swoole_http_response $response)use($webService){
$request_psr = new Request($request);
$response_psr = new Response($response);
$webService->onRequest($request_psr,$response_psr);
if(EasySwooleEvent::onRequest($request_psr,$response_psr)){
$webService->onRequest($request_psr,$response_psr);
}
EasySwooleEvent::afterRequest($request_psr,$response_psr);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Resource/EasySwooleEvent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Time: 下午6:33
*/

namespace EasySwoole\Frame;
namespace EasySwoole\EasySwoole;


use EasySwoole\Core\EventRegister;
use EasySwoole\Frame\AbstractInterface\Event;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

Expand Down
3 changes: 2 additions & 1 deletion src/SysConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 下午6:24
*/

namespace EasySwoole\Frame;
namespace EasySwoole\EasySwoole;


class SysConst
Expand All @@ -18,5 +18,6 @@ class SysConst
const HTTP_CONTROLLER_NAMESPACE = 'HTTP_CONTROLLER_NAMESPACE';
const HTTP_CONTROLLER_MAX_DEPTH = 'CONTROLLER_MAX_DEPTH';
const HTTP_EXCEPTION_HANDLER = 'HTTP_EXCEPTION_HANDLER';
const HTTP_CONTROLLER_POOL_MAX_NUM = 'HTTP_CONTROLLER_POOL_MAX_NUM';

}

0 comments on commit c43be1a

Please sign in to comment.