diff --git a/.gitignore b/.gitignore
index b505552a..ee3a7e54 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,10 @@ composer.lock
.phpunit.result.cache
.daemon_pid
/runtime/
-/tmp/
\ No newline at end of file
+/tmp/
+/ext/go-cqhttp/data/
+/ext/go-cqhttp/logs/
+/ext/go-cqhttp/config.hjson
+/ext/go-cqhttp/device.json
+/ext/go-cqhttp/go-cqhttp
+/ext/go-cqhttp/session.token
diff --git a/build-runtime.sh b/build-runtime.sh
index 4994480e..07d3f31b 100755
--- a/build-runtime.sh
+++ b/build-runtime.sh
@@ -1,29 +1,5 @@
#!/usr/bin/env bash
-_php_ver="7.4.16"
-_libiconv_ver="1.15"
-_openssl_ver="1.1.1j"
-_swoole_ver="4.6.3"
-_home_dir=$(pwd)"/"
-
-function checkEnv() {
- echo -n "检测核心组件... "
- _msg="请通过包管理安装此依赖!"
- type git >/dev/null 2>&1 || { echo "失败,git 不存在!"$_msg; return 1; }
- type gcc >/dev/null 2>&1 || { echo "失败,gcc 不存在!"$_msg; return 1; }
- type g++ >/dev/null 2>&1 || { echo "失败,g++ 不存在!"$_msg; return 1; }
- type unzip >/dev/null 2>&1 || { echo "失败,unzip 不存在!"$_msg; return 1; }
- type autoconf >/dev/null 2>&1 || { echo "失败,autoconf 不存在!"; return 1; }
- type pkg-config >/dev/null 2>&1 || { echo "失败,pkg-config 不存在!"$_msg; return 1; }
- type wget >/dev/null 2>&1 || type curl >/dev/null 2>&1 || { echo "失败,curl/wget 不存在!"$_msg; return 1; }
- echo "完成!"
- echo "如果下载过程中出现错误,请删除 runtime/ 文件夹重试!"
- echo "此脚本安装的php/swoole均为最小版本,不含其他扩展(如zip、xml、gd)等!"
- echo -n "如果编译过程缺少依赖,请通过包管理安装对应的依赖![按回车继续] "
- # shellcheck disable=SC2034
- read ents
-}
-
function downloadIt() {
downloader="wget"
type wget >/dev/null 2>&1 || { downloader="curl"; }
@@ -34,6 +10,7 @@ function downloadIt() {
fi
_down_symbol=0
if [ ! -f "$2" ]; then
+ echo $1
$downloader "$1" -$_down_prefix "$2" >/dev/null 2>&1 && \
echo "完成!" && _down_symbol=1
else
@@ -47,6 +24,34 @@ function downloadIt() {
return 0
}
+downloadIt https://mirrors.cloud.tencent.com/openssl/source/ /tmp/openssl_ver.html
+
+_php_ver="7.1.33"
+_libiconv_ver="1.15"
+_openssl_ver=$(cat /tmp/openssl_ver.html | grep "openssl-1.1.1.*.tar.gz<" | awk -F\" '{print $2}' | awk -F- '{print $2}' | awk -F".tar.gz" '{print $1}')
+_swoole_ver="4.6.3"
+_home_dir=$(pwd)"/"
+
+function checkEnv() {
+ echo -n "检测核心组件... "
+ _msg="请通过包管理安装此依赖!"
+ type git >/dev/null 2>&1 || { echo "失败,git 不存在!"$_msg; return 1; }
+ type gcc >/dev/null 2>&1 || { echo "失败,gcc 不存在!"$_msg; return 1; }
+ type g++ >/dev/null 2>&1 || { echo "失败,g++ 不存在!"$_msg; return 1; }
+ type unzip >/dev/null 2>&1 || { echo "失败,unzip 不存在!"$_msg; return 1; }
+ type autoconf >/dev/null 2>&1 || { echo "失败,autoconf 不存在!"; return 1; }
+ #type pkg-config >/dev/null 2>&1 || { echo "失败,pkg-config 不存在!"$_msg; return 1; }
+ type wget >/dev/null 2>&1 || type curl >/dev/null 2>&1 || { echo "失败,curl/wget 不存在!"$_msg; return 1; }
+ echo "完成!"
+ echo "如果下载过程中出现错误,请删除 runtime/ 文件夹重试!"
+ echo "此脚本安装的php/swoole均为最小版本,不含其他扩展(如zip、xml、gd)等!"
+ echo -n "如果编译过程缺少依赖,请通过包管理安装对应的依赖![按回车继续] "
+ # shellcheck disable=SC2034
+ read ents
+}
+
+
+
function downloadAll() {
# 创建文件夹
mkdir "$_home_dir""runtime" >/dev/null 2>&1
@@ -56,20 +61,34 @@ function downloadAll() {
# 下载PHP
echo -n "正在下载 php 源码... "
- downloadIt "http://mirrors.sohu.com/php/php-$_php_ver.tar.gz" "$_down_dir""php.tar.gz" || { exit; }
+ downloadIt "http://mirrors.sohu.com/php/php-$_php_ver.tar.gz" "$_down_dir""php.tar.gz" || { exit; } &
# 下载libiconv
echo -n "正在下载 libiconv 源码... "
- downloadIt "https://mirrors.tuna.tsinghua.edu.cn/gnu/libiconv/libiconv-$_libiconv_ver.tar.gz" "$_down_dir""libiconv.tar.gz" || { exit; }
+ downloadIt "https://mirrors.tuna.tsinghua.edu.cn/gnu/libiconv/libiconv-$_libiconv_ver.tar.gz" "$_down_dir""libiconv.tar.gz" || { exit; } &
echo -n "正在下载 openssl 源码... "
- downloadIt "http://mirrors.cloud.tencent.com/openssl/source/openssl-$_openssl_ver.tar.gz" "$_down_dir""openssl.tar.gz" || { exit; }
+ downloadIt "http://mirrors.cloud.tencent.com/openssl/source/openssl-$_openssl_ver.tar.gz" "$_down_dir""openssl.tar.gz" || { exit; } &
echo -n "正在下载 swoole 源码... "
- downloadIt "https://dl.zhamao.me/swoole/swoole-$_swoole_ver.tgz" "$_down_dir""swoole.tar.gz" || { exit; }
+ downloadIt "https://dl.zhamao.me/swoole/swoole-$_swoole_ver.tgz" "$_down_dir""swoole.tar.gz" || { exit; } &
echo -n "正在下载 composer ... "
- downloadIt "https://mirrors.aliyun.com/composer/composer.phar" "$_home_dir""runtime/cellar/composer" || { exit; }
+ downloadIt "https://mirrors.aliyun.com/composer/composer.phar" "$_home_dir""runtime/cellar/composer" || { exit; } &
+
+ echo -n "正在下载 zlib ... "
+ downloadIt "https://zlib.net/fossils/zlib-1.2.5.tar.gz" "$_down_dir""zlib.tar.gz" || { exit; } &
+
+ echo -n "正在下载 libxml2 ... "
+ downloadIt "https://dl.zhamao.me/libxml2/libxml2-2.9.8.tar.gz" "$_down_dir""libxml2.tar.gz" || { exit; } &
+
+ echo -n "正在下载 libpng ... "
+ downloadIt "https://dl.zhamao.me/libpng/libpng-1.6.37.tar.gz" "$_down_dir""libpng.tar.gz" || { exit; } &
+
+ echo -n "正在下载 oniguruma ... "
+ downloadIt "https://dl.zhamao.me/oniguruma/onig-6.9.6.tar.gz" "$_down_dir""onig.tar.gz" || { exit; } &
+
+ wait
#echo -n "正在下载 libcurl 源码... "
#downloadIt "https://curl.se/download/curl-7.75.0.tar.gz" "$_down_dir""libcurl.tar.gz" || { exit; }
@@ -80,6 +99,50 @@ function compileIt() {
_source_dir="$_home_dir""runtime/tmp_source/"
_cellar_dir="$_home_dir""runtime/cellar/"
case $1 in
+ "onig")
+ if [ -f "$_cellar_dir""onig/bin/onig-config" ]; then
+ echo "已编译!" && return
+ fi
+ tar -xf "$_down_dir""onig.tar.gz" -C "$_source_dir" && \
+ cd "$_source_dir""onig-6.9.6" && \
+ ./configure --prefix="$_cellar_dir""onig" && \
+ make -j4 && \
+ make install && \
+ echo "完成!"
+ ;;
+ "libxml2")
+ if [ -f "$_cellar_dir""libxml2/lib/libxml2.so" ]; then
+ echo "已编译!" && return
+ fi
+ tar -xf "$_down_dir""libxml2.tar.gz" -C "$_source_dir" && \
+ cd "$_source_dir""libxml2-2.9.8" && \
+ ./configure --prefix="$_cellar_dir""libxml2" --exec-prefix="$_cellar_dir""libxml2" --without-python && \
+ make -j4 && \
+ make install && \
+ echo "完成!"
+ ;;
+ "libpng")
+ if [ -f "$_cellar_dir""libpng/bin/libpng-config" ]; then
+ echo "已编译!" && return
+ fi
+ tar -xf "$_down_dir""libpng.tar.gz" -C "$_source_dir" && \
+ cd "$_source_dir""libpng-1.6.37" && \
+ LDFLAGS="-L$_cellar_dir""zlib/lib" CPPFLAGS="-I$_cellar_dir""zlib/include" ./configure --prefix="$_cellar_dir""libpng" && \
+ make -j4 && \
+ make install && \
+ echo "完成!"
+ ;;
+ "zlib")
+ if [ -f "$_cellar_dir""zlib/lib/libz.so" ]; then
+ echo "已编译!" && return
+ fi
+ tar -xf "$_down_dir""zlib.tar.gz" -C "$_source_dir" && \
+ cd "$_source_dir""zlib-1.2.5" && \
+ ./configure --prefix="$_cellar_dir""zlib" && \
+ make -j4 && \
+ make install && \
+ echo "完成!"
+ ;;
"libiconv")
if [ -f "$_cellar_dir""libiconv/bin/iconv" ]; then
echo "已编译!" && return
@@ -117,30 +180,31 @@ function compileIt() {
if [ -f "$_cellar_dir""php/bin/php" ]; then
echo "已编译!" && return
fi
+ PKG_CONFIG_PATH="$_cellar_dir""openssl/lib/pkgconfig"
+ PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$_cellar_dir""zlib/lib/pkgconfig"
+ PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$_cellar_dir""libxml2/lib/pkgconfig"
+ PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$_cellar_dir""libpng/lib/pkgconfig"
+ PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$_cellar_dir""onig/lib/pkgconfig"
tar -xf "$_down_dir""php.tar.gz" -C "$_source_dir" && \
cd "$_source_dir""php-"$_php_ver && \
./buildconf --force && \
- PKG_CONFIG_PATH="$_cellar_dir""openssl/lib/pkgconfig" ./configure --prefix="$_cellar_dir""php" \
+ PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure --prefix="$_cellar_dir""php" \
--with-config-file-path="$_home_dir""runtime/etc" \
--disable-fpm \
--enable-cli \
--enable-posix \
--enable-ctype \
--enable-mysqlnd \
+ --enable-mbstring \
+ --enable-gd \
--enable-pdo \
--enable-pcntl \
--with-openssl="$_cellar_dir""openssl" \
--enable-sockets \
- --disable-xml \
- --disable-xmlreader \
- --disable-xmlwriter \
- --without-libxml \
- --disable-dom \
--without-sqlite3 \
--without-pdo-sqlite \
- --disable-simplexml \
--with-pdo-mysql=mysqlnd \
- --with-zlib \
+ --with-zlib="$_cellar_dir""zlib" \
--with-iconv="$_cellar_dir""libiconv" \
--enable-phar && \
make -j4 && \
@@ -197,6 +261,18 @@ function compileAll() {
echo -n "正在编译 openssl ... "
compileIt openssl || { return 1; }
+ echo -n "正在编译 zlib ... "
+ compileIt zlib || { return 1; }
+
+ echo -n "正在编译 libxml2 ... "
+ compileIt libxml2 || { return 1; }
+
+ echo -n "正在编译 libpng ... "
+ compileIt libpng || { return 1; }
+
+ echo -n "正在编译 oniguruma ... "
+ compileIt onig || { return 1; }
+
#echo -n "正在编译 libzip ... "
#compileIt libzip || { exit; }
@@ -205,6 +281,7 @@ function compileAll() {
echo -n "正在编译 swoole ... "
compileIt swoole || { return 1; }
+
return 0
}
@@ -213,7 +290,7 @@ function linkBin(){
ln -s "$_home_dir""runtime/cellar/php/bin/php" "$_home_dir""runtime/bin/php" >/dev/null 2>&1
echo "runtime/cellar/php/bin/php runtime/cellar/composer \$@" > "$_home_dir""runtime/bin/composer" && chmod +x "$_home_dir""runtime/bin/composer"
echo "Done!"
- runtime/bin/composer config repo.packagist composer https://mirrors.aliyun.com/composer/
+ "$_home_dir"runtime/bin/composer config repo.packagist composer https://mirrors.aliyun.com/composer/
}
checkEnv && \
@@ -222,5 +299,7 @@ compileAll && \
linkBin && \
echo "成功部署所有环境!" && \
echo -e "composer更新依赖:\t\"runtime/bin/composer update\"" && \
-echo -e "启动框架(源码模式):\t\"runtime/bin/php bin/start server\"" && \
-echo -e "启动框架(普通模式):\t\"runtime/bin/php vendor/bin/start server\""
+echo -e "启动框架(源码模式):\t\"runtime/bin/php bin/start server\"" && \
+echo -e "启动框架(普通模式):\t\"runtime/bin/php vendor/bin/start server\""
+
+
diff --git a/composer.json b/composer.json
index 05eff3d7..a5b9e90d 100644
--- a/composer.json
+++ b/composer.json
@@ -24,25 +24,30 @@
"ext-json": "*",
"ext-posix": "*",
"ext-pcntl": "*",
- "doctrine/annotations": "~1.10",
+ "doctrine/annotations": "~1.12 || ~1.4.0",
"psy/psysh": "@stable",
- "symfony/polyfill-ctype": "^1.20",
- "symfony/polyfill-mbstring": "^1.20",
- "symfony/console": "^5.1",
- "symfony/routing": "^5.1",
+ "symfony/polyfill-ctype": "^1.19",
+ "symfony/polyfill-mbstring": "^1.19",
+ "symfony/console": "~5.0 || ~4.0 || ~3.0",
+ "symfony/routing": "~5.0 || ~4.0 || ~3.0",
"zhamao/console": "^1.0.10",
"zhamao/config": "^1.0",
"zhamao/request": "^1.1",
- "zhamao/connection-manager": "^1.0"
+ "zhamao/connection-manager": "^1.0",
+ "league/climate": "^3.7"
},
"suggest": {
"ext-ctype": "Use C/C++ extension instead of polyfill will be more efficient",
"ext-mbstring": "Use C/C++ extension instead of polyfill will be more efficient",
+ "ext-pdo_mysql": "If you use mysql in framework, you will need this extension",
+ "ext-redis": "If you use Redis in framework, you will need this extension",
"league/climate": "Display columns and status in terminal"
},
"autoload": {
"psr-4": {
- "ZM\\": "src/ZM"
+ "ZM\\": "src/ZM",
+ "Module\\": "src/Module",
+ "Custom\\": "src/Custom"
},
"files": [
"src/ZM/global_functions.php"
diff --git a/ext/go-cqhttp/go-cqhttp-down.sh b/ext/go-cqhttp/go-cqhttp-down.sh
new file mode 100755
index 00000000..846d49e8
--- /dev/null
+++ b/ext/go-cqhttp/go-cqhttp-down.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+echo "正在检查最新版本的go-cqhttp..."
+
+if [ "$(uname -m)" = "x86_64" ]; then
+ arch_type="amd64"
+elif [ "$(uname -m)" = "i386" ]; then
+ arch_type="386"
+fi
+
+aas=$(uname -s | tr 'A-Z' 'a-z')
+
+ver=$(wget -qO- -t1 -T2 "https://fgit-api.zhamao.me/repos/Mrs4s/go-cqhttp/releases" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
+
+if [ "$ver" != "" ]; then
+ echo "最新版本:"$ver
+ echo -n "是否下载到本地?[y/N] "
+ read option
+ if [ "$option" = "y" ]; then
+ wget https://fgit.zhamao.me/Mrs4s/go-cqhttp/releases/download/$ver/go-cqhttp-$ver-$aas-$arch_type.tar.gz -O temp.tar.gz
+ if [ $? != 0 ]; then
+ wget https://fgit.zhamao.me/Mrs4s/go-cqhttp/releases/download/$ver/go-cqhttp_"$aas""_""$arch_type"".tar.gz" -O temp.tar.gz
+ fi
+ tar -zxvf temp.tar.gz go-cqhttp
+ rm temp.tar.gz
+ echo "下载完成,启动命令:./go-cqhttp"
+ echo "首次启动后先编辑config.hjson文件!"
+ fi
+fi
diff --git a/src/ZM/Annotation/AnnotationBase.php b/src/ZM/Annotation/AnnotationBase.php
index 4f485356..3c6ab548 100644
--- a/src/ZM/Annotation/AnnotationBase.php
+++ b/src/ZM/Annotation/AnnotationBase.php
@@ -12,7 +12,7 @@ abstract class AnnotationBase
public $class;
- public function __toString(): string {
+ public function __toString() {
$str = __CLASS__ . ": ";
foreach ($this as $k => $v) {
$str .= "\n\t" . $k . " => ";
diff --git a/src/ZM/Annotation/AnnotationParser.php b/src/ZM/Annotation/AnnotationParser.php
index a7b8d4d7..6ee85b33 100644
--- a/src/ZM/Annotation/AnnotationParser.php
+++ b/src/ZM/Annotation/AnnotationParser.php
@@ -9,7 +9,12 @@ use ZM\Console\Console;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
-use ZM\Annotation\Http\{HandleAfter, HandleBefore, HandleException, Middleware, MiddlewareClass, RequestMapping};
+use ZM\Annotation\Http\HandleAfter;
+use ZM\Annotation\Http\HandleBefore;
+use ZM\Annotation\Http\HandleException;
+use ZM\Annotation\Http\Middleware;
+use ZM\Annotation\Http\MiddlewareClass;
+use ZM\Annotation\Http\RequestMapping;
use ZM\Annotation\Interfaces\Level;
use ZM\Annotation\Module\Closed;
use ZM\Http\RouteManager;
@@ -125,7 +130,7 @@ class AnnotationParser
Console::debug("解析注解完毕!");
}
- public function generateAnnotationEvents(): array {
+ public function generateAnnotationEvents() {
$o = [];
foreach ($this->annotation_map as $module => $obj) {
foreach (($obj["class_annotations"] ?? []) as $class_annotation) {
diff --git a/src/ZM/Annotation/CQ/CQAfter.php b/src/ZM/Annotation/CQ/CQAfter.php
index e45821a8..75bfbbfe 100644
--- a/src/ZM/Annotation/CQ/CQAfter.php
+++ b/src/ZM/Annotation/CQ/CQAfter.php
@@ -26,7 +26,7 @@ class CQAfter extends AnnotationBase implements Level
/**
* @return mixed
*/
- public function getLevel(): int {
+ public function getLevel() {
return $this->level;
}
diff --git a/src/ZM/Annotation/CQ/CQCommand.php b/src/ZM/Annotation/CQ/CQCommand.php
index a7ec162b..7ec493d7 100644
--- a/src/ZM/Annotation/CQ/CQCommand.php
+++ b/src/ZM/Annotation/CQ/CQCommand.php
@@ -48,6 +48,6 @@ class CQCommand extends AnnotationBase implements Level
/**
* @param int $level
*/
- public function setLevel(int $level) { $this->level = $level; }
+ public function setLevel($level) { $this->level = $level; }
}
diff --git a/src/ZM/Annotation/CQ/CQMessage.php b/src/ZM/Annotation/CQ/CQMessage.php
index e10a7a29..d87f8e62 100644
--- a/src/ZM/Annotation/CQ/CQMessage.php
+++ b/src/ZM/Annotation/CQ/CQMessage.php
@@ -34,7 +34,7 @@ class CQMessage extends AnnotationBase implements Level
public function getLevel(): int { return $this->level; }
- public function setLevel(int $level) {
+ public function setLevel($level) {
$this->level = $level;
}
}
\ No newline at end of file
diff --git a/src/ZM/Annotation/CQ/CQMetaEvent.php b/src/ZM/Annotation/CQ/CQMetaEvent.php
index 3466d779..1da58459 100644
--- a/src/ZM/Annotation/CQ/CQMetaEvent.php
+++ b/src/ZM/Annotation/CQ/CQMetaEvent.php
@@ -32,7 +32,7 @@ class CQMetaEvent extends AnnotationBase implements Level
/**
* @param int $level
*/
- public function setLevel(int $level) {
+ public function setLevel($level) {
$this->level = $level;
}
}
\ No newline at end of file
diff --git a/src/ZM/Annotation/CQ/CQNotice.php b/src/ZM/Annotation/CQ/CQNotice.php
index 9f8e582c..f73ef5be 100644
--- a/src/ZM/Annotation/CQ/CQNotice.php
+++ b/src/ZM/Annotation/CQ/CQNotice.php
@@ -36,7 +36,7 @@ class CQNotice extends AnnotationBase implements Level
/**
* @param int $level
*/
- public function setLevel(int $level) {
+ public function setLevel($level) {
$this->level = $level;
}
}
\ No newline at end of file
diff --git a/src/ZM/Annotation/CQ/CQRequest.php b/src/ZM/Annotation/CQ/CQRequest.php
index a2a7cee7..6d51a459 100644
--- a/src/ZM/Annotation/CQ/CQRequest.php
+++ b/src/ZM/Annotation/CQ/CQRequest.php
@@ -36,7 +36,7 @@ class CQRequest extends AnnotationBase implements Level
/**
* @param int $level
*/
- public function setLevel(int $level) {
+ public function setLevel($level) {
$this->level = $level;
}
}
\ No newline at end of file
diff --git a/src/ZM/Annotation/Interfaces/Level.php b/src/ZM/Annotation/Interfaces/Level.php
index 4846afb2..28cdb931 100644
--- a/src/ZM/Annotation/Interfaces/Level.php
+++ b/src/ZM/Annotation/Interfaces/Level.php
@@ -8,5 +8,5 @@ interface Level
{
public function getLevel();
- public function setLevel(int $level);
+ public function setLevel($level);
}
\ No newline at end of file
diff --git a/src/ZM/Annotation/Swoole/OnSwooleEventBase.php b/src/ZM/Annotation/Swoole/OnSwooleEventBase.php
index e744bca4..f0607e0a 100644
--- a/src/ZM/Annotation/Swoole/OnSwooleEventBase.php
+++ b/src/ZM/Annotation/Swoole/OnSwooleEventBase.php
@@ -43,7 +43,7 @@ abstract class OnSwooleEventBase extends AnnotationBase implements Level, Rule
/**
* @param int $level
*/
- public function setLevel(int $level) {
+ public function setLevel($level) {
$this->level = $level;
}
}
\ No newline at end of file
diff --git a/src/ZM/Command/BuildCommand.php b/src/ZM/Command/BuildCommand.php
index 05dd9817..c3b34f69 100644
--- a/src/ZM/Command/BuildCommand.php
+++ b/src/ZM/Command/BuildCommand.php
@@ -32,23 +32,23 @@ class BuildCommand extends Command
if (mb_strpos($target_dir, "../")) $target_dir = realpath($target_dir);
if ($target_dir === false) {
$output->writeln(TermColor::color8(31) . "Error: No such file or directory (" . __DIR__ . '/../../../resources/' . ")" . TermColor::RESET);
- return Command::FAILURE;
+ return 1;
}
$output->writeln("Target: " . $target_dir . " , Version: " . ($version = json_decode(file_get_contents(__DIR__ . "/../../../composer.json"), true)["version"]));
if (mb_substr($target_dir, -1, 1) !== '/') $target_dir .= "/";
if (ini_get('phar.readonly') == 1) {
$output->writeln(TermColor::color8(31) . "You need to set \"phar.readonly\" to \"Off\"!");
$output->writeln(TermColor::color8(31) . "See: https://stackoverflow.com/questions/34667606/cant-enable-phar-writing");
- return Command::FAILURE;
+ return 1;
}
if (!is_dir($target_dir)) {
$output->writeln(TermColor::color8(31) . "Error: No such file or directory ($target_dir)" . TermColor::RESET);
- return Command::FAILURE;
+ return 1;
}
$filename = "server.phar";
$this->build($target_dir, $filename);
- return Command::SUCCESS;
+ return 0;
}
private function build($target_dir, $filename) {
diff --git a/src/ZM/Command/CheckConfigCommand.php b/src/ZM/Command/CheckConfigCommand.php
index a2a7fa5c..104dd8c7 100644
--- a/src/ZM/Command/CheckConfigCommand.php
+++ b/src/ZM/Command/CheckConfigCommand.php
@@ -20,7 +20,7 @@ class CheckConfigCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int {
if (LOAD_MODE !== 1) {
$output->writeln("仅限在Composer依赖模式中使用此命令!");
- return Command::FAILURE;
+ return 1;
}
$current_cfg = getcwd() . "/config/";
$remote_cfg = include_once FRAMEWORK_ROOT_DIR . "/config/global.php";
@@ -42,7 +42,7 @@ class CheckConfigCommand extends Command
$output->writeln("配置文件暂无更新!");
}
- return Command::SUCCESS;
+ return 0;
}
/**
diff --git a/src/ZM/Command/DaemonCommand.php b/src/ZM/Command/DaemonCommand.php
index 6fe12460..ceffceb4 100644
--- a/src/ZM/Command/DaemonCommand.php
+++ b/src/ZM/Command/DaemonCommand.php
@@ -26,6 +26,6 @@ abstract class DaemonCommand extends Command
die();
}
$this->daemon_file = $file;
- return Command::SUCCESS;
+ return 0;
}
}
\ No newline at end of file
diff --git a/src/ZM/Command/DaemonReloadCommand.php b/src/ZM/Command/DaemonReloadCommand.php
index 9e80385e..7f17513c 100644
--- a/src/ZM/Command/DaemonReloadCommand.php
+++ b/src/ZM/Command/DaemonReloadCommand.php
@@ -19,6 +19,6 @@ class DaemonReloadCommand extends DaemonCommand
parent::execute($input, $output);
system("kill -USR1 " . intval($this->daemon_file["pid"]));
$output->writeln("成功重载!");
- return Command::SUCCESS;
+ return 0;
}
}
diff --git a/src/ZM/Command/DaemonStatusCommand.php b/src/ZM/Command/DaemonStatusCommand.php
index 263b55d2..d1aee2e4 100644
--- a/src/ZM/Command/DaemonStatusCommand.php
+++ b/src/ZM/Command/DaemonStatusCommand.php
@@ -25,6 +25,6 @@ class DaemonStatusCommand extends DaemonCommand
if (isset($stdout[count($stdout) - $i]))
echo $stdout[count($stdout) - $i] . PHP_EOL;
}
- return Command::SUCCESS;
+ return 0;
}
}
diff --git a/src/ZM/Command/DaemonStopCommand.php b/src/ZM/Command/DaemonStopCommand.php
index 98245cb1..ca2ae5d4 100644
--- a/src/ZM/Command/DaemonStopCommand.php
+++ b/src/ZM/Command/DaemonStopCommand.php
@@ -21,6 +21,6 @@ class DaemonStopCommand extends DaemonCommand
system("kill -INT " . intval($this->daemon_file["pid"]));
unlink(DataProvider::getWorkingDir() . "/.daemon_pid");
$output->writeln("成功停止!");
- return Command::SUCCESS;
+ return 0;
}
}
diff --git a/src/ZM/Command/InitCommand.php b/src/ZM/Command/InitCommand.php
index c1c6b8c7..1093e431 100644
--- a/src/ZM/Command/InitCommand.php
+++ b/src/ZM/Command/InitCommand.php
@@ -83,10 +83,10 @@ class InitCommand extends Command
echo PHP_EOL;
} else {
echo("Error occurred. Please check your updates.\n");
- return Command::FAILURE;
+ return 1;
}
$output->writeln("Done!");
- return Command::SUCCESS;
+ return 0;
} elseif (LOAD_MODE === 2) { //从phar启动的框架包,初始化的模式
$phar_link = new Phar(__DIR__);
$current_dir = pathinfo($phar_link->getPath())["dirname"];
@@ -104,7 +104,7 @@ class InitCommand extends Command
}
}
$output->writeln("initialization must be started with composer-project mode!");
- return Command::FAILURE;
+ return 1;
}
private function getExtractFiles(): array {
diff --git a/src/ZM/Command/PureHttpCommand.php b/src/ZM/Command/PureHttpCommand.php
index 4b246712..fe8b1bec 100644
--- a/src/ZM/Command/PureHttpCommand.php
+++ b/src/ZM/Command/PureHttpCommand.php
@@ -89,10 +89,10 @@ class PureHttpCommand extends Command
$server->start();
// return this if there was no problem running the command
// (it's equivalent to returning int(0))
- return Command::SUCCESS;
+ return 0;
// or return this if some error happened during the execution
// (it's equivalent to returning int(1))
- // return Command::FAILURE;
+ // return 1;
}
}
diff --git a/src/ZM/Command/RunServerCommand.php b/src/ZM/Command/RunServerCommand.php
index 9b54b721..50971533 100644
--- a/src/ZM/Command/RunServerCommand.php
+++ b/src/ZM/Command/RunServerCommand.php
@@ -40,10 +40,10 @@ class RunServerCommand extends Command
if (($opt = $input->getOption("env")) !== null) {
if (!in_array($opt, ["production", "staging", "development", ""])) {
$output->writeln(" \"--env\" option only accept production, development, staging and [empty] ! ");
- return Command::FAILURE;
+ return 1;
}
}
(new Framework($input->getOptions()))->start();
- return Command::SUCCESS;
+ return 0;
}
}
diff --git a/src/ZM/Command/SystemdCommand.php b/src/ZM/Command/SystemdCommand.php
index 53e0195b..a03917f8 100644
--- a/src/ZM/Command/SystemdCommand.php
+++ b/src/ZM/Command/SystemdCommand.php
@@ -21,7 +21,7 @@ class SystemdCommand extends Command
$path = $this->generate();
$output->writeln("成功生成 systemd 文件,位置:".$path."");
$output->writeln("有关如何使用 systemd 配置文件,请访问 `https://github.com/zhamao-robot/zhamao-framework/issues/36`");
- return Command::SUCCESS;
+ return 0;
}
private function generate() {
diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php
index e96eb97b..1c011e73 100644
--- a/src/ZM/ConsoleApplication.php
+++ b/src/ZM/ConsoleApplication.php
@@ -19,8 +19,8 @@ use ZM\Command\SystemdCommand;
class ConsoleApplication extends Application
{
- const VERSION_ID = 405;
- const VERSION = "2.4.4";
+ const VERSION_ID = 406;
+ const VERSION = "2.4.5";
public function __construct(string $name = 'UNKNOWN') {
define("ZM_VERSION_ID", self::VERSION_ID);
diff --git a/src/ZM/Event/SwooleEvent/OnClose.php b/src/ZM/Event/SwooleEvent/OnClose.php
index acddcdec..1d5d902e 100644
--- a/src/ZM/Event/SwooleEvent/OnClose.php
+++ b/src/ZM/Event/SwooleEvent/OnClose.php
@@ -28,9 +28,9 @@ class OnClose implements SwooleEvent
/** @noinspection PhpUnreachableStatementInspection */
public function onCall($server, $fd) {
unset(Context::$context[Co::getCid()]);
+ Console::debug("Calling Swoole \"close\" event from fd=" . $fd);
$conn = ManagerGM::get($fd);
if ($conn === null) return;
- Console::debug("Calling Swoole \"close\" event from fd=" . $fd);
set_coroutine_params(["server" => $server, "connection" => $conn, "fd" => $fd]);
$dispatcher1 = new EventDispatcher(OnCloseEvent::class);
diff --git a/src/ZM/Event/SwooleEvent/OnWorkerStart.php b/src/ZM/Event/SwooleEvent/OnWorkerStart.php
index c7ad6440..e58f0933 100644
--- a/src/ZM/Event/SwooleEvent/OnWorkerStart.php
+++ b/src/ZM/Event/SwooleEvent/OnWorkerStart.php
@@ -59,7 +59,7 @@ class OnWorkerStart implements SwooleEvent
try {
register_shutdown_function(function () use ($server) {
$error = error_get_last();
- if ($error["type"] != 0) {
+ if (($error["type"] ?? -1) != 0) {
Console::error("Internal fatal error: " . $error["message"] . " at " . $error["file"] . "({$error["line"]})");
}
//DataProvider::saveBuffer();
diff --git a/src/ZM/global_defines.php b/src/ZM/global_defines.php
index dd96acff..745c3510 100644
--- a/src/ZM/global_defines.php
+++ b/src/ZM/global_defines.php
@@ -8,8 +8,8 @@ define("ZM_DATA", ZMConfig::get("global", "zm_data"));
define("APP_VERSION", LOAD_MODE == 1 ? (json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true)["version"] ?? "unknown") : "unknown");
define("CRASH_DIR", ZMConfig::get("global", "crash_dir"));
define("MAIN_WORKER", ZMConfig::get("global", "worker_cache")["worker"] ?? 0);
-@mkdir(ZM_DATA);
-@mkdir(CRASH_DIR);
+if (!is_dir(ZM_DATA)) @mkdir(ZM_DATA);
+if (!is_dir(CRASH_DIR)) @mkdir(CRASH_DIR);
define("CONN_WEBSOCKET", 0);
define("CONN_HTTP", 1);