wujunxiong 4725452b86 初始版本提交 | 2 vuotta sitten | |
---|---|---|
.. | ||
resource | 2 vuotta sitten | |
src | 2 vuotta sitten | |
tests | 2 vuotta sitten | |
LICENSE | 2 vuotta sitten | |
README.md | 2 vuotta sitten | |
composer.json | 2 vuotta sitten |
一个轻量级的HTTP Dispatch组件
namespace App\HttpController;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Http\Dispatcher;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use Swoole\Http\Server;
require_once 'vendor/autoload.php';
class Index extends Controller
{
function index()
{
// TODO: Implement index() method
$this->response()->write('hello world');
}
}
$dispatcher = new Dispatcher();
$dispatcher->setNamespacePrefix('App\HttpController');
$http = new Server("127.0.0.1", 9501);
$http->on("request", function ($request, $response) use($dispatcher){
$request_psr = new Request($request);
$response_psr = new Response($response);
$dispatcher->dispatch($request_psr, $response_psr);
$response_psr->__response();
});
$http->start();
namespace App\HttpController;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Http\Dispatcher;
use EasySwoole\Http\GlobalParam\Hook;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\Session\FileSession;
use EasySwoole\Session\Session;
use Swoole\Http\Server;
require_once 'vendor/autoload.php';
class Index extends Controller
{
function index()
{
$this->response()->write('hello world');
}
function get()
{
var_dump($_GET['a']);
}
function session()
{
if(isset($_SESSION['isNew'])){
$this->response()->write('your are old user');
}else{
$_SESSION['isNew'] = 1;
$this->response()->write('your are new user');
}
}
function session2()
{
$this->writeJson(200,$_SESSION->toArray());
}
}
$dispatcher = new Dispatcher();
$dispatcher->setNamespacePrefix('App\HttpController');
$http = new Server("127.0.0.1", 9501);
$hook = new Hook();
$session = new Session(new FileSession(__DIR__.'/session'));
$hook->enableSession($session);
$hook->register();
$http->on("request", function ($request, $response) use($dispatcher,$hook){
$request_psr = new Request($request);
$response_psr = new Response($response);
$hook->onRequest($request_psr,$response_psr);
$dispatcher->dispatch($request_psr, $response_psr);
$response_psr->__response();
});
$http->start();
enableSession
,那么$_SESSION
则不可用。$_SESSION
目前仅支持如下操作: