PHPackages                             ifui/webman-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ifui/webman-module

ActiveLibrary

ifui/webman-module
==================

Webman plugin ifui/webman-module

1.0.5(3y ago)9761MITPHPPHP &gt;=7.2

Since Aug 18Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ifui/webman-module)[ Packagist](https://packagist.org/packages/ifui/webman-module)[ RSS](/packages/ifui-webman-module/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

Webman Module 应用模块插件（社区版）
=========================

[](#webman-module-应用模块插件社区版)

> 基于 `Webman` 的一款应用模块插件，与普通插件的主要区别在于它是一款面向生产环境下的应用级解决方案，例如问答、博客、新闻等应用程序

介绍
--

[](#介绍)

`ifui/webman-module` 是一个 `webman` 插件，它可以使用模块化、搭积木的方式来管理你的应用程序。

一个模块就像是一个应用，该插件严格参照官方的 [应用插件说明](https://www.workerman.net/doc/webman/plugin/app.html) 规范开发。

相比于普通插件的一大好处是内置支持了 `测试` 功能，可以方便快捷的测试应用程序在实际应用场景下的情况。

安装
--

[](#安装)

```
composer require ifui/webman-module ^1.0.5
```

版本升级
----

[](#版本升级)

```
# 升级配置文件
php webman plugin:install ifui/webman-module
```

快速上手
----

[](#快速上手)

### 1.创建模块

[](#1创建模块)

执行：`php webman module:create`

模块名应遵循`PSR4`规范，这里不作过多限制

```
 请输入应用名（必填）:
 > apple

 请输入作者名（必填）:
 > ifui

 请输入邮箱地址（选填）:
 > xx@xx.com

 请输入应用简介（选填）:
 > apple

 请输入主页地址（选填）:
 > apple

```

按照操作提示输入相应的内容即可，将会创建如下目录格式

```
/plugin/
  ├── apple/
      ├── app/
          ├── controller/
              ├── Index.php
          ├── middleware/
          ├── model/
          ├── providers/
              ├── AppServerProvider.php
          ├── view/
          ├── functions.php
      ├── config/
          ├── app.php
      ├── database/
          ├── migrations/
          ├── seeds/
      ├── route
          ├── admin.php
          ├── api.php
          ├── web.php
      ├── tests/
      ├── composer.json
      ├── module.json
      ├── README.md
      ├── LICENSE.md

```

### 2. 启动 `webman` 服务，并访问默认的应用模块URL

[](#2-启动-webman-服务并访问默认的应用模块url)

1. 启动 `webman` 服务 `php start.php start`
2. 使用浏览器访问 `/app/apple/index`（其中 `apple` 是你新建的模块名）
3. 看到: hello webman module 问候提示语则表示插件已成功运行

接下来和开发一个`webman`项目体验基本一致

配置说明
----

[](#配置说明)

模块的配置文件都在模块根目录下的 `module.json` 文件内

```
{
    "name": "apple", // 应用模块名
    "activity": true, // 是否启动该模块
    "author": "ifui", // 作者名
    "email": "", // 邮箱地址
    "homepage": "", // 模块主页地址
    "type": "", // 模块类型
    "version": "0.1.0", // 模块版本号
    "description": "", // 模块简介
    "keywords": [], // 模块关键词
    "route": {
        "autoRoute": true, // 是否开启自动路由
        "urlPrefix": "/app/apple" // 路由前缀
    }
}
```

命令介绍
----

[](#命令介绍)

### 模块命令

[](#模块命令)

#### 1. 启动模块 module:start

[](#1-启动模块-modulestart)

```
php webman module:start apple
```

#### 2. 暂停模块 module:stop

[](#2-暂停模块-modulestop)

```
php webman module:stop apple
```

#### 3. 查看模块列表 module:list

[](#3-查看模块列表-modulelist)

```
php webman module:list
```

```
+------------+--------+---------+--------+
| name       | author | version | status |
+------------+--------+---------+--------+
| apple      | ifui   | 0.1.0   | false  |
| blog       | ifui   | 0.1.0   | true   |
| peach      | ifui   | 0.1.0   | true   |
| watermelon | ifui   | 0.1.0   | false  |
+------------+--------+---------+--------+

```

### 4. 创建一个模块 module:create

[](#4-创建一个模块-modulecreate)

```
php webman module:create
```

### 常用命令

[](#常用命令)

> 其中 `--module` 亦可以不填，系统会提示选择对应的模块，输入对应的序号即可

#### 1. 创建一个模型文件 module:make-model

[](#1-创建一个模型文件-modulemake-model)

```
php webman module:make-model Post --module=apple
```

将会创建 `/plugin/apple/app/model/Post.php` 文件

#### 2. 创建一个控制器文件 module:make-controller

[](#2-创建一个控制器文件-modulemake-controller)

```
php webman module:make-controller Admin/Post --module=apple
```

将会创建 `/plugin/apple/app/controller/Admin/Post.php` 文件

#### 3. 创建一个中间件文件 make-middleware

[](#3-创建一个中间件文件-make-middleware)

```
php webman module:make-middleware LimitVisitMiddleware --module=apple
```

将会创建 `/plugin/apple/app/middleware/LimitVisitMiddleware.php` 文件

#### 4. 创建一个测试文件 module:make-test

[](#4-创建一个测试文件-modulemake-test)

```
php webman module:make-test unit/AppleTest --module=apple
```

将会创建 `/plugin/apple/tests/unit/AppleTest.php` 文件

### 数据库迁移命令

[](#数据库迁移命令)

主要使用了数据库迁移工具 `Phinx`，

`Phinx` 项目地址：

官方中文文档地址：

使用数据库迁移命令前，请确保`webman` 根目录下的 `config/plugin/ifui/webman-module/phink.php` 配置是否正确

```
