Swoft 生成命令

准备工作

$ docker-machine ls 
$ docker-machine start default
$ docker-machine ssh default
docker@default ~$ docker ps -a
docker@default ~$ docker exec -it myswoft bash
root@2e7ca4e64edf:/var/www/swoft#

生成文件类型

root@2e7ca4e64edf:/var/www/swoft# php bin/swoft gen
描述:
  生成常用应用内置模板类

用法:
  gen:{command} [arguments] [options]

命令:
  command     生成CLI命令控制器类
  controller  生成HTTP控制器类
  websocket   生成WebSocket控制器类
  rpcService  生成RPC服务类
  listener    生成一个事件监听器类
  middleware  生成HTTP中间件类
  task        生成用户任务类
  process     生成用户进程类
  entity      生成数据库实体类

选项:
  -h, --help  显示命令组或专用命令操作的帮助信息

可通过php bin/swoft gen:{command} -h查看命令帮助信息

生成HTTP控制器类

root@2e7ca4e64edf:/var/www/swoft# php bin/swoft gen:controller -h
描述:
  生成HTTP控制器类

用法:
  bin/swoft gen:controller CLASS_NAME SAVE_DIR [--option ...]

参数:
  name       类名,无需后缀和文件扩展名
  dir        类文件保存目录,默认@app/Controllers

选项:
  -y, --yes BOOL             文件生成写入时无需确认,默认为假
  -o, --override BOOL        强制覆盖已存在的文件,默认为假
  -n, --namespace STRING     类的命名空间,默认为App\Controllers
  --rest BOOL                类包含增删改查操作方法,默认假
  --prefix STRING            类路由的前缀,默认为类名
  --suffix STRING            类名后缀,默认为Controller
  --tpl-file STRING          模板文件名称,默认为command.stub
  --tpl-dir STRING           模板文件目录路径,默认为devtool/res/templates

示例:
  bin/swoft gen:controller demo --prefix /demo -y          Gen DemoController class to `@app/Controllers`
  bin/swoft gen:controller user --prefix /users --rest     Gen UserController class to `@app/Controllers`(RESTFul type)

生成HTTP中间件类

root@2e7ca4e64edf:/var/www/swoft# php bin/swoft middleware -h
描述:
  生成HTTP中间件类

用法:
  bin/swoft gen:middleware CLASS_NAME SAVE_DIR [--option ...]

参数:
  name       类名,无需后缀和文件扩展名
  dir        类文件保存目录,默认@app/Middlewares

选项:
  -y, --yes BOOL             文件生成写入时无需确认,默认为假
  -o, --override BOOL        强制覆盖已存在的文件,默认为假
  -n, --namespace STRING     类的命名空间,默认为App\Middlewares
  --suffix STRING            类名后缀,默认为Middleware
  --tpl-file STRING          模板文件名称,默认为middleware.stub
  --tpl-dir STRING           模板文件目录路径,默认为devtool/res/templates

示例:
  bin/swoft gen:middleware demo     为@app/Middlewares生成DemoMiddleware类

生成数据库实体类

root@2e7ca4e64edf:/var/www/swoft# php bin/swoft entity -h
描述:
  生成实体类

用法:
  bin/swoft gen:entity -d test [--option ...]

选项:
  -d, --database STRING      Must to set database. `,` symbol is used  to separated by multiple databases
  -i, --include STRING       Set the included tables, `,` symbol is used  to separated by multiple tables. default is: all tables
  -e, --exclude STRING       Set the excluded tables, `,` symbol is used  to separated by multiple tables. default is: empty
  -p, --path STRING          Specified entity generation path, default is: @app/Models/Entity
  --driver STRING            Specify database driver(mysql/pgsql/mongodb), default is: mysql
  --table-prefix STRING      Specify the table prefix that needs to be removed, default is: empty
  --field-prefix STRING      Specify the field prefix that needs to be removed, default is: empty
  --tpl-file STRING          The template file name. default is: entity.stub
  --tpl-dir STRING           The template file dir path.(default: devtool/res/templates)

示例:
  bin/swoft gen:entity -d test     为`@app/Models/Entity`生成DemoProcess类

创建数据实体

root@2e7ca4e64edf:/var/www/swoft# php bin/swoft entity:create -h
描述:
  通过数据表结构自动创建数据实体文件

用法:
  entity:create -d[|--database] 
  entity:create -d[|--database]  [table]
  entity:create -d[|--database]  -i[|--include] 
  entity:create -d[|--database]  -i[|--include] 
  entity:create -d[|--database]  -i[|--include]  -e[|--exclude] 
  entity:create -d[|--database]  -i[|--include]  -e[|--exclude] 

选项:
  -d                    数据库
  --database            数据库
  -i                    指定特定的数据表,多表之间用逗号分隔
  --include             指定特定的数据表,多表之间用逗号分隔
  -e                    排除指定的数据表,多表之间用逗号分隔
  --exclude             排除指定的数据表,多表之间用逗号分隔
  --remove-table-prefix 去除表前缀
  --entity-file-path    实体路径(必须在以@app开头并且在app目录下存在的目录,否则将会重定向到@app/Models/Entity)

示例:
  php bin/swoft entity:create -d test

例如:为test数据库中的web_account表创建对应实体类,创建成功会生成app/Models/Entity/WebAccount类文件。

$ php bin/swoft entity:create -d test web_account

你可能感兴趣的:(Swoft 生成命令)