mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 00:25:35 +08:00
update to 1.6.3 version
fix response redirect bug fix document_index not working
This commit is contained in:
@@ -27,7 +27,8 @@ class RequestEvent implements SwooleEvent
|
|||||||
*/
|
*/
|
||||||
private $response;
|
private $response;
|
||||||
|
|
||||||
public function __construct(Request $request, Response $response) {
|
public function __construct(Request $request, Response $response)
|
||||||
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,8 @@ class RequestEvent implements SwooleEvent
|
|||||||
* @return $this|SwooleEvent
|
* @return $this|SwooleEvent
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function onActivate() {
|
public function onActivate()
|
||||||
|
{
|
||||||
ZMUtil::checkWait();
|
ZMUtil::checkWait();
|
||||||
foreach (ZMBuf::globals("http_header") as $k => $v) {
|
foreach (ZMBuf::globals("http_header") as $k => $v) {
|
||||||
$this->response->setHeader($k, $v);
|
$this->response->setHeader($k, $v);
|
||||||
@@ -49,7 +51,10 @@ class RequestEvent implements SwooleEvent
|
|||||||
$params = [];
|
$params = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
$r = array_shift($uri);
|
$r = array_shift($uri);
|
||||||
if ($r === null) break;
|
if ($r === null) {
|
||||||
|
if ($node == ZMBuf::$req_mapping) goto statics;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
if (($cnt = count($node["son"] ?? [])) == 1) {
|
if (($cnt = count($node["son"] ?? [])) == 1) {
|
||||||
if (isset($node["param_route"])) {
|
if (isset($node["param_route"])) {
|
||||||
foreach ($node["son"] as $k => $v) {
|
foreach ($node["son"] as $k => $v) {
|
||||||
@@ -80,13 +85,18 @@ class RequestEvent implements SwooleEvent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
statics:
|
||||||
if (ZMBuf::globals("static_file_server")["status"]) {
|
if (ZMBuf::globals("static_file_server")["status"]) {
|
||||||
$base_dir = ZMBuf::globals("static_file_server")["document_root"];
|
$base_dir = ZMBuf::globals("static_file_server")["document_root"];
|
||||||
$base_index = ZMBuf::globals("static_file_server")["document_index"];
|
$base_index = ZMBuf::globals("static_file_server")["document_index"];
|
||||||
$uri = $this->request->server["request_uri"];
|
$uri = $this->request->server["request_uri"];
|
||||||
$path = realpath($base_dir . urldecode($uri));
|
$path = realpath($base_dir . urldecode($uri));
|
||||||
if ($path !== false) {
|
if ($path !== false) {
|
||||||
|
if (is_dir($path) && mb_substr($uri, -1, 1) != "/") {
|
||||||
|
$this->response->redirect($uri . "/", 301);
|
||||||
|
$this->response->end();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
if (is_dir($path)) $path = $path . '/';
|
if (is_dir($path)) $path = $path . '/';
|
||||||
$work = realpath(DataProvider::getWorkingDir()) . '/';
|
$work = realpath(DataProvider::getWorkingDir()) . '/';
|
||||||
if (strpos($path, $work) !== 0) {
|
if (strpos($path, $work) !== 0) {
|
||||||
@@ -150,7 +160,8 @@ class RequestEvent implements SwooleEvent
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function onAfter() {
|
public function onAfter()
|
||||||
|
{
|
||||||
foreach (ZMBuf::$events[SwooleEventAfter::class] ?? [] as $v) {
|
foreach (ZMBuf::$events[SwooleEventAfter::class] ?? [] as $v) {
|
||||||
if (strtolower($v->type) == "request" && $this->parseSwooleRule($v)) {
|
if (strtolower($v->type) == "request" && $this->parseSwooleRule($v)) {
|
||||||
$c = $v->class;
|
$c = $v->class;
|
||||||
@@ -162,12 +173,14 @@ class RequestEvent implements SwooleEvent
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function responseStatus(int $int) {
|
private function responseStatus(int $int)
|
||||||
|
{
|
||||||
$this->response->status($int);
|
$this->response->status($int);
|
||||||
$this->response->end();
|
$this->response->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseSwooleRule($v) {
|
private function parseSwooleRule($v)
|
||||||
|
{
|
||||||
switch (explode(":", $v->rule)[0]) {
|
switch (explode(":", $v->rule)[0]) {
|
||||||
case "containsGet":
|
case "containsGet":
|
||||||
case "containsPost":
|
case "containsPost":
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class Response
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function redirect($location, $http_code = null) {
|
public function redirect($location, $http_code = null) {
|
||||||
return $this->redirect($location, $http_code);
|
return $this->response->redirect($location, $http_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user