mafuth / php-cli
关于简单命令行界面和框架,适用于PHP,注重轻量和简洁
README
php-CLI
此项目需要将PHP作为可执行命令
安装
- 创建项目
composer create-project mafuth/php-cli:dev-main test
- 检查安装
php cli --v
- 配置安装
php cli --config
- 测试数据库连接
php cli test data-base-connection
- 启动本地服务器
php cli --serve
ajax 文件夹
这里是 cli 生成 AJAX 请求文件的所在地
commands 文件夹
这里是 cli 生成所有您运行命令文件的地方
database 文件夹
在 database/create 中包含所有 cli 生成的数据库表控制器
handlers 文件夹
这里是 cli 生成处理文件的地方
views 文件夹
这里是您放置生成前端视图的 PHP 代码文件的地方
索引和主文件
请不要编辑这些文件,因为它们是重要组件
requests 文件
此文件处理所有对服务器的请求,根据需要编辑此文件
要禁用压缩,请更改请求文件编译器,如下所示
echo $COMPILER->output($PAGE,false);
如果您想使用 Blade 模板引擎,可以查看BladeOne的文档
config.ini 文件
这是服务器的主体配置文件
[app configs] appname = "Your App Name" port = "8080" #Your app port default to 8080 [database configs] servername = "Your database server here" username = "server username" password = "server password" dbname = "database name" [Mail server] mailServer = "Your mailserver here" mailUsername = "server username" mailPassword = "servr password" mailport = "server port" [encryption keys] KEY_ONE = "encryption key 1" KEY_TWO = "encryption key 2" [maintanance mode] maintanance = false # true or false [error reporting] error = false # true or false [auto ssl] autossl = false # true or false (true will force ssl on every request)
用法
git 命令
- 配置 git
git config --global user.name "Full Name as on github"
git config --global user.email "Email as on github"
在下一步中按 Enter 键以选择默认值
ssh-keygen -t rsa -C "Email as on github"
Windows
notepad ~/.ssh/id_rsa.pub
mac & Linux
cat ~/.ssh/id_rsa.pub
现在转到https://github.com/settings/keys,并添加您刚刚在记事本上生成的/打开的密钥,保存 SSH 密钥
- 测试 git
ssh -T git@github.com
如果您看到类似“Hi user! You've successfully authenticated, but GitHub does not provide shell access.”的消息,则一切正常
php cli --git
创建命令
创建数据库表(用您选择的任何名称替换‘-- your table name --’)
php cli create table -- your table name --
为 POST 请求创建处理程序(用您选择的任何名称替换‘-- your handler name --’)
php cli create handler -- your handler name --
为所有 XML 请求创建 AJAX 请求处理程序(用您选择的任何名称替换‘-- your handler name --’)
php cli create ajax -- your handler name --
创建新的运行命令(用您选择的任何名称替换‘-- your command name --’)
php cli create run-command -- your command name --
数据库表命令
删除所有表和删除创建函数文件
php cli drop-tables
或使用
php cli drop-table -- your table name --
如果想要编辑表布局,只需编辑(database/create)目录中的表布局文件,然后运行以下命令
php cli recreate-tables
或使用
php cli recreate-table -- your table name --
运行命令
此命令用于运行使用(php cli create run-command -- your command name --)创建的脚本
php cli run -- your command name --
构建数据库查询(参考 'classes/db.class.php')
选择从
$DB->selectFrom($table); $data = $DB->execute(); // this will return an array of all data selected;
选择从...WHERE
$DB->selectFrom($table); $DB->where(array( 'id'=>1, 'name'=>array( 'john', 'doe' ) )); $data = $DB->execute(); // this will return an array of all data selected;
从...删除
$DB->deleteFrom($table); $DB->where(array( 'id'=>1, 'name'=>array( 'john', 'doe' ) )); $data = $DB->execute(); // this will return true if successful and false if failed $error = $data['message]; // this has the error message
从...更新
$DB->updateFrom($table); $DB->set(array( 'name'=>'john' )); $DB->where(array( 'id'=>1 )); $data = $DB->execute(); // this will return true if successful and false if failed $error = $data['message]; // this has the error message
向...插入
$DB->insert(array( 'john' )); $DB->to($table); $data = $DB->execute(); // this will return true if successful and false if failed $error = $data['message]; // this has the error message $DB->insertTo($table,array( 'name'=>'john' )); $data = $DB->execute(); // this will return true if successful and false if failed $error = $data['message]; // this has the error message
PWA 命令
此命令用于为您的网站生成 PWA 代码,此命令需要node js和onderceylan 的 pwa asset generator
PWA 还支持onesignal SDK,它也包含在 php-CLI 中
php cli pwa-code
Composer 命令
安装新的 composer 包(用您选择的任何 composer 包替换‘-- package name --’)
php cli install -- package name --
从 GitHub 部署 FTP
配置GitHub工作流程,方便使用FTP或SFTP将您的网站部署到服务器
php cli --git make ftp deploy
php cli --git make sftp deploy
Docker
为开发设置完整的Docker环境
php cli make docker container
数据库备份
备份数据库
php cli db backup
从备份中恢复数据库
php cli db restore
贡献
贡献使开源社区成为一个如此令人惊叹的学习、灵感和创造的地方。您所做的任何贡献都备受赞赏。非常感谢。
如果您有任何改进建议,请fork仓库并创建一个pull request。您也可以简单地创建一个带有“enhancement”标签的问题。别忘了为项目点个star!再次感谢!