Skip to content

Commit 1b0d5e7

Browse files
committed
update to 2.3 version
1 parent 80f3d4e commit 1b0d5e7

File tree

7 files changed

+255
-9
lines changed

7 files changed

+255
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ zm.json
44
/zm_data/
55
composer.lock
66
.DS_Store
7+
/runtime/

build-runtime.sh

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/usr/bin/env bash
2+
3+
_php_ver="7.4.16"
4+
_libiconv_ver="1.15"
5+
_openssl_ver="1.1.1j"
6+
_swoole_ver="4.6.3"
7+
_home_dir=$(pwd)"/"
8+
9+
function checkEnv() {
10+
echo -n "检测核心组件... "
11+
_msg="请通过包管理安装此依赖!"
12+
type git >/dev/null 2>&1 || { echo "失败,git 不存在!"$_msg; return 1; }
13+
type gcc >/dev/null 2>&1 || { echo "失败,gcc 不存在!"$_msg; return 1; }
14+
type g++ >/dev/null 2>&1 || { echo "失败,g++ 不存在!"$_msg; return 1; }
15+
type unzip >/dev/null 2>&1 || { echo "失败,unzip 不存在!"$_msg; return 1; }
16+
type autoconf >/dev/null 2>&1 || { echo "失败,autoconf 不存在!"; return 1; }
17+
type pkg-config >/dev/null 2>&1 || { echo "失败,pkg-config 不存在!"$_msg; return 1; }
18+
type wget >/dev/null 2>&1 || type curl >/dev/null 2>&1 || { echo "失败,curl/wget 不存在!"$_msg; return 1; }
19+
echo "完成!"
20+
echo "如果下载过程中出现错误,请删除 runtime/ 文件夹重试!"
21+
echo "此脚本安装的php/swoole均为最小版本,不含其他扩展(如zip、xml、gd)等!"
22+
echo -n "如果编译过程缺少依赖,请通过包管理安装对应的依赖![按回车继续] "
23+
# shellcheck disable=SC2034
24+
read ents
25+
}
26+
27+
function downloadIt() {
28+
downloader="wget"
29+
type wget >/dev/null 2>&1 || { downloader="curl"; }
30+
if [ "$downloader" = "wget" ]; then
31+
_down_prefix="O"
32+
else
33+
_down_prefix="o"
34+
fi
35+
_down_symbol=0
36+
if [ ! -f "$2" ]; then
37+
$downloader "$1" -$_down_prefix "$2" >/dev/null 2>&1 && \
38+
echo "完成!" && _down_symbol=1
39+
else
40+
echo "已存在!" && _down_symbol=1
41+
fi
42+
if [ $_down_symbol == 0 ]; then
43+
echo "失败!请检查网络连接!"
44+
rm -rf "$2"
45+
return 1
46+
fi
47+
return 0
48+
}
49+
50+
function downloadAll() {
51+
# 创建文件夹
52+
mkdir "$_home_dir""runtime" >/dev/null 2>&1
53+
mkdir "$_home_dir""runtime/tmp_download" >/dev/null 2>&1
54+
mkdir "$_home_dir""runtime/cellar" >/dev/null 2>&1
55+
_down_dir=$_home_dir"runtime/tmp_download/"
56+
57+
# 下载PHP
58+
echo -n "正在下载 php 源码... "
59+
downloadIt "http://mirrors.sohu.com/php/php-$_php_ver.tar.gz" "$_down_dir""php.tar.gz" || { exit; }
60+
61+
# 下载libiconv
62+
echo -n "正在下载 libiconv 源码... "
63+
downloadIt "https://mirrors.tuna.tsinghua.edu.cn/gnu/libiconv/libiconv-$_libiconv_ver.tar.gz" "$_down_dir""libiconv.tar.gz" || { exit; }
64+
65+
echo -n "正在下载 openssl 源码... "
66+
downloadIt "http://mirrors.cloud.tencent.com/openssl/source/openssl-$_openssl_ver.tar.gz" "$_down_dir""openssl.tar.gz" || { exit; }
67+
68+
echo -n "正在下载 swoole 源码... "
69+
downloadIt "https://dl.zhamao.me/swoole/swoole-$_swoole_ver.tgz" "$_down_dir""swoole.tar.gz" || { exit; }
70+
71+
echo -n "正在下载 composer ... "
72+
downloadIt "https://mirrors.aliyun.com/composer/composer.phar" "$_home_dir""runtime/cellar/composer" || { exit; }
73+
74+
#echo -n "正在下载 libcurl 源码... "
75+
#downloadIt "https://curl.se/download/curl-7.75.0.tar.gz" "$_down_dir""libcurl.tar.gz" || { exit; }
76+
}
77+
78+
function compileIt() {
79+
_down_dir="$_home_dir""runtime/tmp_download/"
80+
_source_dir="$_home_dir""runtime/tmp_source/"
81+
_cellar_dir="$_home_dir""runtime/cellar/"
82+
case $1 in
83+
"libiconv")
84+
if [ -f "$_cellar_dir""libiconv/bin/iconv" ]; then
85+
echo "已编译!" && return
86+
fi
87+
tar -xf "$_down_dir""libiconv.tar.gz" -C "$_source_dir" && \
88+
cd "$_source_dir""libiconv-"$_libiconv_ver && \
89+
./configure --prefix="$_cellar_dir""libiconv" >/dev/null 2>&1 && \
90+
make -j4 >/dev/null 2>&1 && \
91+
make install >/dev/null 2>&1 && \
92+
echo "完成!"
93+
;;
94+
"libzip")
95+
if [ -f "$_cellar_dir""libzip/bin/libzip" ]; then
96+
echo "已编译!" && return
97+
fi
98+
tar -xf "$_down_dir""libzip.tar.gz" -C "$_source_dir" && \
99+
cd "$_source_dir""libzip-1.7.3" && \
100+
./configure --prefix="$_cellar_dir""libzip" && \
101+
make -j4 && \
102+
make install && \
103+
echo "完成!"
104+
;;
105+
"libcurl")
106+
if [ -f "$_cellar_dir""libcurl/bin/libcurl" ]; then
107+
echo "已编译!" && return
108+
fi
109+
tar -xf "$_down_dir""libcurl.tar.gz" -C "$_source_dir" && \
110+
cd "$_source_dir""libcurl-7.75.0" && \
111+
./configure --prefix="$_cellar_dir""libcurl" && \
112+
make -j4 && \
113+
make install && \
114+
echo "完成!"
115+
;;
116+
"php")
117+
if [ -f "$_cellar_dir""php/bin/php" ]; then
118+
echo "已编译!" && return
119+
fi
120+
tar -xf "$_down_dir""php.tar.gz" -C "$_source_dir" && \
121+
cd "$_source_dir""php-"$_php_ver && \
122+
./buildconf --force && \
123+
PKG_CONFIG_PATH="$_cellar_dir""openssl/lib/pkgconfig" ./configure --prefix="$_cellar_dir""php" \
124+
--with-config-file-path="$_home_dir""runtime/etc" \
125+
--disable-fpm \
126+
--enable-cli \
127+
--enable-posix \
128+
--enable-ctype \
129+
--enable-mysqlnd \
130+
--enable-pdo \
131+
--enable-pcntl \
132+
--with-openssl="$_cellar_dir""openssl" \
133+
--enable-sockets \
134+
--disable-xml \
135+
--disable-xmlreader \
136+
--disable-xmlwriter \
137+
--without-libxml \
138+
--disable-dom \
139+
--without-sqlite3 \
140+
--without-pdo-sqlite \
141+
--disable-simplexml \
142+
--with-pdo-mysql=mysqlnd \
143+
--with-zlib \
144+
--with-iconv="$_cellar_dir""libiconv" \
145+
--enable-phar && \
146+
make -j4 && \
147+
make install && \
148+
cp "$_source_dir""php-$_php_ver/php.ini-production" "$_home_dir""runtime/etc/php.ini" && \
149+
echo "完成!"
150+
;;
151+
"openssl")
152+
if [ -f "$_cellar_dir""openssl/bin/openssl" ]; then
153+
echo "已编译!" && return
154+
fi
155+
tar -xf "$_down_dir""openssl.tar.gz" -C "$_source_dir" && \
156+
cd "$_source_dir""openssl-""$_openssl_ver" && \
157+
./config --prefix="$_cellar_dir""openssl" && \
158+
make -j4 && \
159+
make install && \
160+
echo "完成!"
161+
;;
162+
"swoole")
163+
"$_home_dir"runtime/cellar/php/bin/php --ri swoole >/dev/null 2>&1
164+
# shellcheck disable=SC2181
165+
if [ $? == 0 ]; then
166+
echo "已编译!" && return
167+
fi
168+
tar -xf "$_down_dir""swoole.tar.gz" -C "$_source_dir" && \
169+
cd "$_source_dir""swoole-""$_swoole_ver" && \
170+
PATH="$_cellar_dir""php/bin:$PATH" phpize && \
171+
PATH="$_cellar_dir""php/bin:$PATH" ./configure --prefix="$_cellar_dir""php" \
172+
--enable-sockets \
173+
--enable-http2 \
174+
--enable-openssl \
175+
--with-openssl-dir="$_cellar_dir""openssl" \
176+
--enable-mysqlnd && \
177+
make -j4 && \
178+
make install && \
179+
echo "extension=swoole.so" >> "$_home_dir""runtime/etc/php.ini" && \
180+
echo "完成!"
181+
;;
182+
esac
183+
}
184+
185+
function compileAll() {
186+
_down_dir=$_home_dir"runtime/tmp_download/"
187+
_source_dir=$_home_dir"runtime/tmp_source/"
188+
mkdir "$_source_dir" >/dev/null 2>&1
189+
mkdir "$_home_dir""runtime/etc" >/dev/null 2>&1
190+
191+
echo -n "正在编译 libiconv ... "
192+
compileIt libiconv || { return 1; }
193+
194+
#echo -n "正在编译 libcurl ... "
195+
#compileIt libcurl || { exit; }
196+
197+
echo -n "正在编译 openssl ... "
198+
compileIt openssl || { return 1; }
199+
200+
#echo -n "正在编译 libzip ... "
201+
#compileIt libzip || { exit; }
202+
203+
echo -n "正在编译 php ... "
204+
compileIt php || { return 1; }
205+
206+
echo -n "正在编译 swoole ... "
207+
compileIt swoole || { return 1; }
208+
return 0
209+
}
210+
211+
function linkBin(){
212+
mkdir "$_home_dir""runtime/bin" >/dev/null 2>&1
213+
ln -s "$_home_dir""runtime/cellar/php/bin/php" "$_home_dir""runtime/bin/php" >/dev/null 2>&1
214+
echo "runtime/cellar/php/bin/php runtime/cellar/composer \$@" > "$_home_dir""runtime/bin/composer" && chmod +x "$_home_dir""runtime/bin/composer"
215+
echo "Done!"
216+
runtime/bin/composer config repo.packagist composer https://mirrors.aliyun.com/composer/
217+
}
218+
219+
checkEnv && \
220+
downloadAll && \
221+
compileAll && \
222+
linkBin && \
223+
echo "成功部署所有环境!" && \
224+
echo -e "composer更新依赖:\t\"runtime/bin/composer update\"" && \
225+
echo -e "启动框架(源码模式):\t\"runtime/bin/php bin/start server\"" && \
226+
echo -e "启动框架(普通模式):\t\"runtime/bin/php vendor/bin/start server\""

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "composer project of zhamao-framework-starter",
44
"minimum-stability": "stable",
55
"license": "Apache-2.0",
6-
"version": "2.2",
6+
"version": "2.3",
77
"type": "project",
88
"prefer-stable": true,
99
"scripts": {
@@ -21,6 +21,12 @@
2121
"require-dev": {
2222
"swoole/ide-helper": "@dev"
2323
},
24+
"repositories": {
25+
"packagist": {
26+
"type": "composer",
27+
"url": "https://mirrors.aliyun.com/composer/"
28+
}
29+
},
2430
"autoload": {
2531
"psr-4": {
2632
"Module\\": "src/Module",

config/global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/** 对应swoole的server->set参数 */
2828
$config['swoole'] = [
2929
'log_file' => $config['crash_dir'] . 'swoole_error.log',
30-
'worker_num' => swoole_cpu_num(), //如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算,则可把这里改为1使用全局变量
30+
//'worker_num' => swoole_cpu_num(), //如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算,则可把这里改为1使用全局变量
3131
'dispatch_mode' => 2, //包分配原则,见 https://wiki.swoole.com/#/server/setting?id=dispatch_mode
3232
'max_coroutine' => 300000,
3333
//'task_worker_num' => 4,

config/motd.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
______
2-
|__ / |__ __ _ _ __ ___ __ _ ___
3-
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
4-
/ /_| | | | (_| | | | | | | (_| | (_) |
5-
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
1+
______
2+
|__ / |__ __ _ _ __ ___ __ _ ___
3+
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
4+
/ /_| | | | (_| | | | | | | (_| | (_) |
5+
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
66

src/Custom/global_function.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php #plain
1+
<?php /** @noinspection PhpFullyQualifiedNameUsageInspection */ #plain
22

33
//这里写你的全局函数
44
function pgo(callable $func, $name = "default") {

src/Module/Example/Hello.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ZM\Annotation\CQ\CQCommand;
1212
use ZM\Annotation\Http\RequestMapping;
1313
use ZM\Event\EventDispatcher;
14+
use ZM\Requests\ZMRequest;
1415
use ZM\Utils\ZMUtil;
1516

1617
/**
@@ -45,6 +46,18 @@ public function hello() {
4546
return "你好啊,我是由炸毛框架构建的机器人!";
4647
}
4748

49+
/**
50+
* 一个最基本的第三方 API 接口使用示例
51+
* @CQCommand("一言")
52+
*/
53+
public function hitokoto() {
54+
$api_result = ZMRequest::get("https://v1.hitokoto.cn/");
55+
if ($api_result === false) return "接口请求出错,请稍后再试!";
56+
$obj = json_decode($api_result, true);
57+
if ($obj === null) return "接口解析出错!可能返回了非法数据!";
58+
return $obj["hitokoto"] . "\n----「" . $obj["from"] . "";
59+
}
60+
4861
/**
4962
* 一个简单随机数的功能demo
5063
* 问法1:随机数 1 20
@@ -89,7 +102,7 @@ public function index() {
89102
* @return string
90103
*/
91104
public function paramGet($param) {
92-
return "Hello, ".$param["name"];
105+
return "Hello, " . $param["name"];
93106
}
94107

95108
/**

0 commit comments

Comments
 (0)