-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9756d00
commit 683433f
Showing
9 changed files
with
374 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
/vendor/ | ||
zm.json | ||
/zm_data/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# zhamao-framework-starter | ||
炸毛框架的composer-project模板 | ||
|
||
用法: | ||
```bash | ||
composer create-project zhamao/framework-starter | ||
cd framework-starter | ||
vendor/bin/start server | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"ai": "application/postscript", | ||
"aif": "audio/x-aiff", | ||
"aifc": "audio/x-aiff", | ||
"aiff": "audio/x-aiff", | ||
"asc": "text/plain", | ||
"au": "audio/basic", | ||
"avi": "video/x-msvideo", | ||
"bcpio": "application/x-bcpio", | ||
"bin": "application/octet-stream", | ||
"bmp": "image/bmp", | ||
"cdf": "application/x-netcdf", | ||
"class": "application/octet-stream", | ||
"cpio": "application/x-cpio", | ||
"cpt": "application/mac-compactpro", | ||
"csh": "application/x-csh", | ||
"css": "text/css", | ||
"dcr": "application/x-director", | ||
"dir": "application/x-director", | ||
"djv": "image/vnd.djvu", | ||
"djvu": "image/vnd.djvu", | ||
"dll": "application/octet-stream", | ||
"dms": "application/octet-stream", | ||
"doc": "application/msword", | ||
"dvi": "application/x-dvi", | ||
"dxr": "application/x-director", | ||
"eps": "application/postscript", | ||
"etx": "text/x-setext", | ||
"exe": "application/octet-stream", | ||
"ez": "application/andrew-inset", | ||
"gif": "image/gif", | ||
"gtar": "application/x-gtar", | ||
"hdf": "application/x-hdf", | ||
"hqx": "application/mac-binhex40", | ||
"htm": "text/html", | ||
"html": "text/html", | ||
"ice": "x-conference/x-cooltalk", | ||
"ief": "image/ief", | ||
"iges": "model/iges", | ||
"igs": "model/iges", | ||
"jpe": "image/jpeg", | ||
"jpeg": "image/jpeg", | ||
"jpg": "image/jpeg", | ||
"js": "application/x-javascript", | ||
"kar": "audio/midi", | ||
"latex": "application/x-latex", | ||
"lha": "application/octet-stream", | ||
"lzh": "application/octet-stream", | ||
"m3u": "audio/x-mpegurl", | ||
"man": "application/x-troff-man", | ||
"me": "application/x-troff-me", | ||
"mesh": "model/mesh", | ||
"mid": "audio/midi", | ||
"midi": "audio/midi", | ||
"mif": "application/vnd.mif", | ||
"mov": "video/quicktime", | ||
"movie": "video/x-sgi-movie", | ||
"mp2": "audio/mpeg", | ||
"mp3": "audio/mpeg", | ||
"mpe": "video/mpeg", | ||
"mpeg": "video/mpeg", | ||
"mpg": "video/mpeg", | ||
"mpga": "audio/mpeg", | ||
"ms": "application/x-troff-ms", | ||
"msh": "model/mesh", | ||
"mxu": "video/vnd.mpegurl", | ||
"nc": "application/x-netcdf", | ||
"oda": "application/oda", | ||
"pbm": "image/x-portable-bitmap", | ||
"pdb": "chemical/x-pdb", | ||
"pdf": "application/pdf", | ||
"pgm": "image/x-portable-graymap", | ||
"pgn": "application/x-chess-pgn", | ||
"png": "image/png", | ||
"pnm": "image/x-portable-anymap", | ||
"ppm": "image/x-portable-pixmap", | ||
"ppt": "application/vnd.ms-powerpoint", | ||
"ps": "application/postscript", | ||
"qt": "video/quicktime", | ||
"ra": "audio/x-realaudio", | ||
"ram": "audio/x-pn-realaudio", | ||
"ras": "image/x-cmu-raster", | ||
"rgb": "image/x-rgb", | ||
"rm": "audio/x-pn-realaudio", | ||
"roff": "application/x-troff", | ||
"rpm": "audio/x-pn-realaudio-plugin", | ||
"rtf": "text/rtf", | ||
"rtx": "text/richtext", | ||
"sgm": "text/sgml", | ||
"sgml": "text/sgml", | ||
"sh": "application/x-sh", | ||
"shar": "application/x-shar", | ||
"silo": "model/mesh", | ||
"sit": "application/x-stuffit", | ||
"skd": "application/x-koan", | ||
"skm": "application/x-koan", | ||
"skp": "application/x-koan", | ||
"skt": "application/x-koan", | ||
"smi": "application/smil", | ||
"smil": "application/smil", | ||
"snd": "audio/basic", | ||
"so": "application/octet-stream", | ||
"spl": "application/x-futuresplash", | ||
"src": "application/x-wais-source", | ||
"sv4cpio": "application/x-sv4cpio", | ||
"sv4crc": "application/x-sv4crc", | ||
"swf": "application/x-shockwave-flash", | ||
"t": "application/x-troff", | ||
"tar": "application/x-tar", | ||
"tcl": "application/x-tcl", | ||
"tex": "application/x-tex", | ||
"texi": "application/x-texinfo", | ||
"texinfo": "application/x-texinfo", | ||
"tif": "image/tiff", | ||
"tiff": "image/tiff", | ||
"tr": "application/x-troff", | ||
"tsv": "text/tab-separated-values", | ||
"txt": "text/plain", | ||
"ustar": "application/x-ustar", | ||
"vcd": "application/x-cdlink", | ||
"vrml": "model/vrml", | ||
"wav": "audio/x-wav", | ||
"wbmp": "image/vnd.wap.wbmp", | ||
"wbxml": "application/vnd.wap.wbxml", | ||
"wml": "text/vnd.wap.wml", | ||
"wmlc": "application/vnd.wap.wmlc", | ||
"wmls": "text/vnd.wap.wmlscript", | ||
"wmlsc": "application/vnd.wap.wmlscriptc", | ||
"wrl": "model/vrml", | ||
"xbm": "image/x-xbitmap", | ||
"xht": "application/xhtml+xml", | ||
"xhtml": "application/xhtml+xml", | ||
"xls": "application/vnd.ms-excel", | ||
"xml": "text/xml", | ||
"xpm": "image/x-xpixmap", | ||
"xsl": "text/xml", | ||
"xwd": "image/x-xwindowdump", | ||
"xyz": "chemical/x-xyz", | ||
"zip": "application/zip", | ||
"": "application/octet-stream" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
global $config; | ||
|
||
/** bind host */ | ||
$config['host'] = '0.0.0.0'; | ||
|
||
/** bind port */ | ||
$config['port'] = 20001; | ||
|
||
/** 框架开到公网或外部的HTTP访问链接,通过 DataProvider::getFrameworkLink() 获取 */ | ||
$config['http_reverse_link'] = "http://127.0.0.1:" . $config['port']; | ||
|
||
/** 框架是否启动debug模式 */ | ||
$config['debug_mode'] = false; | ||
|
||
/** 存放框架内文件数据的目录 */ | ||
$config['zm_data'] = realpath(__DIR__ . "/../") . '/zm_data/'; | ||
|
||
/** 存放各个模块配置文件的目录 */ | ||
$config['config_dir'] = $config['zm_data'] . 'config/'; | ||
|
||
/** 存放崩溃和运行日志的目录 */ | ||
$config['crash_dir'] = $config['zm_data'] . 'crash/'; | ||
|
||
/** 对应swoole的server->set参数 */ | ||
$config['swoole'] = [ | ||
'log_file' => $config['crash_dir'] . 'swoole_error.log', | ||
'worker_num' => 1, | ||
'dispatch_mode' => 2, | ||
'task_worker_num' => 0 | ||
]; | ||
|
||
/** MySQL数据库连接信息,host留空则启动时不创建sql连接池 */ | ||
$config['sql_config'] = [ | ||
'sql_host' => '', | ||
'sql_port' => 3306, | ||
'sql_username' => 'name', | ||
'sql_database' => 'db_name', | ||
'sql_password' => '', | ||
'sql_enable_cache' => true, | ||
'sql_reset_cache' => '0300' | ||
]; | ||
|
||
/** CQHTTP连接约定的token */ | ||
$config["access_token"] = ""; | ||
|
||
/** HTTP服务器固定请求头的返回 */ | ||
$config['http_header'] = [ | ||
'X-Powered-By' => 'zhamao-framework', | ||
'Content-Type' => 'text/html; charset=utf-8' | ||
]; | ||
|
||
/** HTTP服务器在指定状态码下回复的页面(默认) */ | ||
$config['http_default_code_page'] = [ | ||
'404' => '404.html' | ||
]; | ||
|
||
/** zhamao-framework在框架启动时初始化的atomic们 */ | ||
$config['init_atomics'] = [ | ||
'in_count' => 0, //消息接收message的统计数量 | ||
'out_count' => 0, //消息发送(调用send_*_msg的统计数量) | ||
'reload_time' => 0, //调用reload功能统计数量 | ||
'wait_msg_id' => 0, //协程挂起id自增 | ||
'info_level' => 2, //终端显示的log等级 | ||
]; | ||
|
||
/** 自动保存的缓存保存时间(秒) */ | ||
$config['auto_save_interval'] = 900; | ||
|
||
/** 上下文接口类 implemented from ContextInterface */ | ||
$config['context_class'] = \ZM\Context\Context::class; | ||
|
||
/** 静态文件访问 */ | ||
$config['static_file_server'] = [ | ||
'status' => false, | ||
'document_root' => realpath(__DIR__ . "/../") . '/resources/html', | ||
'document_index' => [ | ||
'index.html' | ||
] | ||
]; | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
______ | ||
|__ / |__ __ _ _ __ ___ __ _ ___ | ||
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \ | ||
/ /_| | | | (_| | | | | | | (_| | (_) | | ||
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// 这里写你的全局方法 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
|
||
namespace Module\Example; | ||
|
||
|
||
use Framework\Console; | ||
use ZM\Annotation\CQ\CQCommand; | ||
use ZM\Annotation\Http\Middleware; | ||
use ZM\Annotation\Http\RequestMapping; | ||
use ZM\Annotation\Swoole\SwooleEventAt; | ||
use ZM\Connection\CQConnection; | ||
use ZM\Utils\ZMUtil; | ||
|
||
/** | ||
* Class Hello | ||
* @package Module\Example | ||
* @since 1.5 | ||
*/ | ||
class Example | ||
{ | ||
/** | ||
* 在机器人连接后向终端输出信息 | ||
* @SwooleEventAt("open",rule="connectType:qq") | ||
* @param $conn | ||
*/ | ||
public function onConnect(CQConnection $conn) { | ||
Console::info("机器人 " . $conn->getQQ() . " 已连接!"); | ||
} | ||
|
||
/** | ||
* 向机器人发送"你好",即可回复这句话 | ||
* @CQCommand("你好") | ||
*/ | ||
public function hello() { | ||
return "你好啊,我是由炸毛框架构建的机器人!"; | ||
} | ||
|
||
/** | ||
* @CQCommand(".reload") | ||
*/ | ||
public function reload() { | ||
context()->reply("reloading..."); | ||
ZMUtil::reload(); | ||
} | ||
|
||
/** | ||
* @CQCommand("随机数") | ||
* @CQCommand(regexMatch="*从*到*的随机数") | ||
* @param $arg | ||
*/ | ||
public function randNum($arg) { | ||
// 获取第一个数字类型的参数 | ||
$num1 = context()->getArgs($arg, ZM_MATCH_NUMBER, "请输入第一个数字"); | ||
// 获取第二个数字类型的参数 | ||
$num2 = context()->getArgs($arg, ZM_MATCH_NUMBER, "请输入第二个数字"); | ||
$a = min(intval($num1), intval($num2)); | ||
$b = max(intval($num1), intval($num2)); | ||
// 回复用户结果 | ||
context()->reply("随机数是:".mt_rand($a, $b)); | ||
} | ||
|
||
/** | ||
* 中间件测试的一个示例函数 | ||
* @RequestMapping("/httpTimer") | ||
* @Middleware("timer") | ||
*/ | ||
public function timer() { | ||
return "This page is used as testing TimerMiddleware! Do not use it in production."; | ||
} | ||
|
||
/** | ||
* 默认示例页面 | ||
* @RequestMapping("/index") | ||
* @RequestMapping("/") | ||
*/ | ||
public function index() { | ||
return "Hello Zhamao!"; | ||
} | ||
|
||
|
||
/** | ||
* 框架会默认关闭未知的WebSocket链接,因为这个绑定的事件,你可以根据你自己的需求进行修改 | ||
* @SwooleEventAt(type="open",rule="connectType:unknown") | ||
*/ | ||
public function closeUnknownConn() { | ||
Console::info("Unknown connection , I will close it."); | ||
context()->getConnection()->close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Module\Middleware; | ||
|
||
use Framework\Console; | ||
use ZM\Annotation\Http\After; | ||
use ZM\Annotation\Http\Before; | ||
use ZM\Annotation\Http\MiddlewareClass; | ||
use ZM\Http\MiddlewareInterface; | ||
|
||
/** | ||
* Class AuthMiddleware | ||
* 示例中间件:用于统计路由函数运行时间用的 | ||
* @package Module\Middleware | ||
* @MiddlewareClass() | ||
*/ | ||
class TimerMiddleware implements MiddlewareInterface | ||
{ | ||
private $starttime; | ||
|
||
/** | ||
* @Before() | ||
* @return bool | ||
*/ | ||
public function onBefore() { | ||
$this->starttime = microtime(true); | ||
return true; | ||
} | ||
|
||
/** | ||
* @After() | ||
*/ | ||
public function onAfter() { | ||
Console::info("Using " . round((microtime(true) - $this->starttime) * 1000, 2) . " ms."); | ||
} | ||
|
||
public function getName() { return "timer"; } | ||
} |