Skip to content

Commit

Permalink
chore: CR & optimized codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy131 committed Feb 20, 2023
1 parent ee50eff commit 5b3a11e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
$response = $obj->response;
// 解压参数
extract($params);
if(empty($params) || !isset($type, $hashTag) || !file_exists($file = owo\cache_path("{$type}/{$hashTag}.php"))) {
$file = owo\cache_path("{$type}/{$hashTag}.php");
if(empty($params) || !isset($type, $hashTag) || !file_exists($file)) {
$response->setResponseCode(403);
return ['msg' => 'Access Denied'];
}
Expand Down
3 changes: 2 additions & 1 deletion src/owoframe/application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function banController(string $name) : Application
public function unbanController(string $name, bool $force = false) : Application
{
if($this->isControllerBanned($name)) {
if($force && (count($_ =& $this->controllerBanList[$name]) === 0)) {
$_ =& $this->controllerBanList[$name];
if($force && (count($_) === 0)) {
unset($_);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/owoframe/http/WebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ public function run(?callable $callback = null, ?array $args = null) : void
static $isRunning;
if(!$this->created) {
throw new ErrorException('Invalid Socket! Error message: ' . socket_strerror(socket_last_error()));
return;
}
if($isRunning) {
throw new ErrorException('Do not call twice this method when WebSocket Server is running!');
return;
}
if(!isset($isRunning)) {
$clients[] = $this->socket;
Expand All @@ -123,9 +121,9 @@ public function run(?callable $callback = null, ?array $args = null) : void
// 判断是不是新接入的客户端
if($this->socket == $client)
{
if(!($newClient = socket_accept($client))) {
$newClient = socket_accept($client);
if(!($newClient)) {
throw new ErrorException('Failed to accept socket: ' . socket_strerror(socket_last_error($client)));
continue;
}
$this->handshaking($newClient, trim(socket_read($newClient, 1024)), $data);
socket_getpeername($newClient, $ip);
Expand Down
6 changes: 4 additions & 2 deletions src/owoframe/http/route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ protected function handle(&$handler, array $params = [])
{
if(is_a($handler, Controller::class, true)) {
$handler = new $handler;
if(method_exists($handler, $method = $handler->getDefaultHandlerMethod() ?? $handler->getName())) {
$method = $handler->getDefaultHandlerMethod() ?? $handler->getName();
if(method_exists($handler, $method)) {
return call_user_func_array([$handler, $method], $params) ?? true;
}
}
Expand All @@ -455,7 +456,8 @@ protected function handle(&$handler, array $params = [])

$controller = $handler->getDefaultController();
if($controller instanceof Controller) {
if(method_exists($controller, $method = $controller->getDefaultHandlerMethod() ?? $controller->getName())) {
$method = $controller->getDefaultHandlerMethod() ?? $controller->getName();
if(method_exists($controller, $method)) {
return call_user_func_array([$controller, $method], $params) ?? true;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/owoframe/template/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ protected function replaceFunction(string &$str) : Template
$function = $matches[1][$k];
if(!function_exists($function))
{
if(function_exists($_ = '\\owo\\' . $function)) {
$function = $_;
$tmp = '\\owo\\' . $function;
if(function_exists($tmp)) {
$function = $tmp;
} else {
continue;
}
Expand Down Expand Up @@ -474,7 +475,8 @@ protected function parseLoopArea(string &$loopArea, ?int $level = null) : void
$parseArray = explode('.', $matchedTag); // 解析并分级绑定标签
array_shift($parseArray); // 去除第一级原始绑定标签

if((count($parseArray) === 0) && (($cnum = count($data)) > 1)) {
$cnum = count($data);
if((count($parseArray) === 0) && ($cnum > 1)) {
$complied[$k][$n] = str_replace($bindElement . $matchedTag . $bindElement, "Array(n:{$bindElement}{$bindTag})[{$cnum}]", $line);
} else {
$current = $v;
Expand Down
3 changes: 2 additions & 1 deletion src/owoframe/template/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ protected function parseDisplayArea(string &$str) : void
$display = strtolower($matches[2][$k]);
$display = ($display === 'true') ? true : false;
if(strlen($cid) > 0) {
if(is_bool($value = $this->getDisplayZoneStatus($cid))) {
$value = $this->getDisplayZoneStatus($cid);
if(is_bool($value)) {
$display = $value;
}
}
Expand Down

0 comments on commit 5b3a11e

Please sign in to comment.