1 Star 0 Fork 0

vee7z/Veecmf-PHP全栈人的瑞士军刀

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
think 11.13 KB
一键复制 编辑 原始数据 按行查看 历史
vee7z 提交于 2021-12-18 23:40 +08:00 . v0.5
#!/usr/bin/env php
<?php
namespace think;
// 命令行入口文件
// 加载基础文件
require __DIR__ . '/vendor/autoload.php';
// 应用初始化
(new App())->console->run();
//使用说明
//启动内置服务器
//php think run
//php think run -H tp.com -p 80
//查看版本
//php think version
//生成应用目录
//php think build demo
//如果需要自定义生成结构,在app目录下新建build.php文件
//return [
// // 需要自动创建的文件
// '__file__' => [],
// // 需要自动创建的目录
// '__dir__' => ['controller', 'model', 'view'],
// // 需要自动创建的控制器
// 'controller' => ['Index'],
// // 需要自动创建的模型
// 'model' => ['User'],
// // 需要自动创建的模板
// 'view' => ['index/index'],
//]
//生成控制器
//php think make:controller admin@Blog admin是应用名称,可以添加 --plain 表示生成空的控制器,默认是资源控制器
//生成模型
//php think make:model index@Blog
//生成中间件 app\middleware\Auth
//php think make:middleware Auth
//生成验证器
//php think make:validate index@User
//清除缓存文件
//php think clear
//--dir表示删除空目录
//--log表示清除日志
//--log --dir表示清除日志目录并删除空目录
//--cache表示清除缓存目录
//--cache --dir表示清除缓存目录并删除空目录
//清除指定目录下的文件
//php think clear --path d:\www\tp\runtime\log\
//生成数据库字段缓存
//php think optimize:schema --connection mysql
//更新数据库字段缓存
//php think optimize:schema --table demo.think_user (demo是库名)
//生成路由缓存
//php think optimize:route index (index是应用名)
//查看路由列表
//php think route:list index (index是应用名)
//-m 输出详细信息
//########## 创建自定义指令(已创建了一个案例)
//php think make:command Test mytest (app/command/Test)
//配置config/console.php下加入 'mytest' => 'app\command\Test',
//运行php think mytest yhw --city GuiZhou
//########## 数据库迁移扩展
//安装扩展(该案例项目已安装)
//composer require topthink/think-migration
//创建迁移文件
//php think migrate:create AnyClassNameYouWant (必须是大驼峰写法)
//运行迁移文件
//php think migrate:run
//########## 助手函数扩展
//安装扩展(该案例项目已安装) composer require topthink/think-helper
//Str
//字符串操作
//use think\\helper\\Str;
// 检查字符串中是否包含某些字符串
//Str::contains($haystack, $needles)
// 检查字符串是否以某些字符串结尾
//Str::endsWith($haystack, $needles)
// 获取指定长度的随机字母数字组合的字符串
//Str::random($length = 16)
// 字符串转小写
//Str::lower($value)
// 字符串转大写
//Str::upper($value)
// 获取字符串的长度
//Str::length($value)
// 截取字符串
//Str::substr($string, $start, $length = null)
// 驼峰转下划线
//Str::snake($value, $delimiter = '_')
// 下划线转驼峰(首字母小写)
//Str::camel($value)
// 下划线转驼峰(首字母大写)
//Str::studly
// 转为首字母大写的标题格式
//Str::title($value)
//Arr
//数组操作
//use think\\helper\\Arr;
//判断能否当做数组一样访问
//数组返回真
//模型查询的结果也为真
//Arr::accessible($value)
//向数组添加一个元素,支持"点"分割
//Arr::add($array, $key, $value)
////如下操作
//$arr = [];
//$arr = Arr::add($arr,'name.3.ss','thinkphp'); //本行结果$arr['name'][3]['ss'] = 'thinkphp'
//Arr::add($arr,'name','thinkphp2');//本行不会产生影响,因为'name'已存在.
//将数据集管理类转换为数组
//Arr::collapse($array)
//排列数组组合
//$arr = Arr::crossJoin(['dd'],['ff'=>'gg'],[2],[['a'=>'mm','kk'],'5']);
//上面行没有什么意义,但是可以看到该函数的作用,数组索引被忽略,数组得值被全部组合
//$arr = Arr::crossJoin(['a','b','c'],['aa','bb','cc','dd']);
//这一行可以看到组合的效果,返回一个二维数组,第二维每个数组是的给定值排列,比如(a,aa),(a,bb),(a,cc)...直到(c,dd)
//########## 验证码扩展(必须开启session)
//安装扩展(该案例项目已安装)
//composer require topthink/think-captcha
//前端添加 <div>{:captcha_img()}</div> 或 <div><img src="{:captcha_src()}" alt="captcha" /></div>
//控制器添加验证类或独立验证
//$this->validate($data,[
// 'captcha|验证码'=>'require|captcha'
//]);
//助手函数
//if(!captcha_check($captcha)){
// // 验证失败
//};
//多应用模式需要注册验证码路由 Route::get('captcha/[:config]','\\think\\captcha\\CaptchaController@index');
//配置config/captcha.php
//Captcha类带有默认的配置参数,支持自定义配置。这些参数包括:
//参数 描述 默认
//codeSet 验证码字符集合 略
//expire 验证码过期时间(s) 1800
//math 使用算术验证码 false
//useZh 使用中文验证码 false
//zhSet 中文验证码字符串 略
//useImgBg 使用背景图片 false
//fontSize 验证码字体大小(px) 25
//useCurve 是否画混淆曲线 true
//useNoise 是否添加杂点 true
//imageH 验证码图片高度,设置为0为自动计算 0
//imageW 验证码图片宽度,设置为0为自动计算 0
//length 验证码位数 5
//fontttf 验证码字体,不设置是随机获取 空
//bg 背景颜色 [243, 251, 254]
//reset 验证成功后是否重置 true
//自定义验证码
//做一个自定义的验证码控制器(多应用下记得注册路由) Route::get('verify','index/verify');
//<?php
//namespace app\index\controller;
//use think\captcha\facade\Captcha;
//class Index
//{
// public function verify()
// {
// return Captcha::create();
// }
//}
//访问 http://serverName/index/index/verify(没有路由的单应用情况下)
//验证码检测
// 检测输入的验证码是否正确,$value为用户输入的验证码字符串
//$captcha = new Captcha();
//if( !$captcha->check($value))
//{
// // 验证失败
//}
//或
// 检测输入的验证码是否正确,$value为用户输入的验证码字符串
//if( !captcha_check($value ))
//{
// // 验证失败
//}
//########## workerman扩展
//安装扩展 composer require topthink/think-worker
//HttpServer服务开启 端口2346
//php think worker
//linux下面可以支持下面指令
//php think worker [start|stop|reload|restart|status]
//SocketServer服务开启 端口2345
//php think worker:server
//配置config/worker_server.php
//配置参数 描述
//protocol 协议
//host 监听地址
//port 监听端口
//socket 完整的socket地址
//事件回调:
//eturn [
// 'socket' => 'http://127.0.0.1:8000',
// 'name' => 'thinkphp',
// 'count' => 4,
// 'onMessage' => function($connection, $data) {
// $connection->send(json_encode($data));
// },
//];
//或自定入口
//namespace app\http;
//use think\worker\Server;
//class Worker extends Server
//{
// protected $socket = 'http://0.0.0.0:2346';
// public function onMessage($connection,$data)
// {
// $connection->send(json_encode($data));
// }
//}
//配置修改为
//return [
// 'worker_class' => 'app\http\Worker',
//];
//########## swoole扩展
//php-swoole扩展版本依赖4.3.1+
//安装扩展(该案例项目已安装)
//composer require topthink/think-swoole
//配置文件:config/swoole.php
//##### 开启一个HTTP服务 端口80
//php think swoole
//启动HTTP服务(默认)
//php think swoole start
//停止服务
//php think swoole stop
//重启服务
//php think swoole restart
//reload服务
//php think swoole reload
//##### RPC
//准备两个项目,tp1,tp2
//--------tp1
//创建一个接口 app/rpc/MyRpcInterface.php
//<?php
//namespace app\rpc;
//interface MyRpcInterface
//{
// public function demo();
//}
//接着在同一目录下创建 MyRpc.php 文件,代码如下:
//<?php
//namespace app\rpc;
//class MyRpc implements MyRpcInterface
//{
// public function demo(){
// return 'myrpc';
// }
//}
//将接口添加到配置文件中
//'rpc' => [
// 'services' => [
// \app\rpc\MyRpc::class
// ],
//]
//然后开启服务 php think swoole
//--------tp2
//修改配置文件
//'rpc' => [
// 'client' => [
// 'tp1' => [ //别名,可自定义
// 'host' => '127.0.0.1',
// 'port' => 9000
// ],
// ],
//]
//控制台运行 php think rpc:interface 会在app目录下生成rpc.php文件
//控制器中开始测试rpc是否成功
//use rpc\contract\tp1\MyRpcInterface;
//public function index(MyRpcInterface $rpc)
//{
// return $rpc->demo();
//}
//启动tp2服务端 php think swoole
//访问tp2的该控制器,如果正常将显示myrpc
//##### websocket
//配置文件开启
//'websocket' => [
// 'enable' => true,
//],
//创建三个监听者
//php think make:listener SwWsConnect
//php think make:listener SwWsClose
//php think make:listener SwWsMessage
//绑定事件 app/event.php
// 'listen' => [
// ........
// // 监听链接
// 'swoole.websocket.Connect' => [
// \app\listener\SwWsConnect::class
// ],
// //关闭连接
// 'swoole.websocket.Close' => [
// \app\listener\SwWsClose::class
// ],
// //发送消息场景
// 'swoole.websocket.Message' => [
// \app\listener\SwWsMessage::class
// ]
// ],
//扩展的配置绑定
//'listen' => [
// 'connect'=>\app\listener\SwWsConnect::class,
// 'close'=>\app\listener\SwWsClose::class,
// 'message'=> \app\listener\SwWsMessage::class
//],
//编写监听者 app\listener\SwWsConnect.php 连接事件
//public function handle($event, \think\swoole\websocket $ws)
//{
// // 获取当前发送者的fd
// $fd = $ws->getSender();
// echo "server: handshake success with fd{$fd}\n";
//}
//编写监听者 app\listener\SwWsClose.php 关闭事件
//public function handle($event, \think\swoole\websocket $ws)
//{
// $fd = $ws->getSender();
// echo "client {$fd} closed\n";
//}
//编写监听者 app\listener\SwWsMessage.php 消息事件
//public function handle($event, \think\swoole\websocket $ws)
//{
// $fd = $ws->getSender();
// $data = json_encode($event);
// echo "receive from {$fd}:{$data}\n";
// $ws->emit("this is server", $fd);
//}
//方法总结:
////给自己发消息
//$ws->emit("this is server", $ws->getSender());
////给指定一个fd发消息
//$ws->to($to)->emit("messagecallback",$data);
////给指定多个人发消息
//$ws->to([1,2,3])->emit("messagecallback",$data);
////发送给所有的(不包含自己)
//$ws->broadcast()->emit("messagecallback",$data);
////模拟formfd 给tofd 发送消息
//$ws->setSender($formfd)->to($tofd)->emit("messagecallback",$data);
//如果你发现你think-swoole中有些没有swoole中的方法可以这么干
//$sw = app('swoole.server');
//$sw = app("think\swoole\Manager")->getServer();
////以上二选一
//$es = $sw->isEstablished($fd); //检查连接是否为有效的WebSocket客户端连接
//var_dump($es);
//聊天室案例见《think-swoole聊天室案例》
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/vee7z/veecmf.git
git@gitee.com:vee7z/veecmf.git
vee7z
veecmf
Veecmf-PHP全栈人的瑞士军刀
master

搜索帮助