pudongping / hyperf-biz-web-api
Business web api skeleton based on hyperf framework.
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=8.0
- hyperf/async-queue: ~3.0.0
- hyperf/cache: ~3.0.0
- hyperf/command: ~3.0.0
- hyperf/config: ~3.0.0
- hyperf/constants: ~3.0.0
- hyperf/crontab: ^3.0
- hyperf/database: ~3.0.0
- hyperf/db: ^3.0
- hyperf/db-connection: ~3.0.0
- hyperf/elasticsearch: ~3.0.0
- hyperf/framework: ~3.0.0
- hyperf/guzzle: ~3.0.0
- hyperf/http-server: ~3.0.0
- hyperf/logger: ~3.0.0
- hyperf/memory: ~3.0.0
- hyperf/model-cache: ~3.0.0
- hyperf/paginator: ^3.0
- hyperf/process: ~3.0.0
- hyperf/redis: ~3.0.0
- hyperf/translation: ^3.0
- hyperf/validation: ^3.0
- pudongping/hyperf-alarm-clock: ^2.0
- pudongping/hyperf-kit: ^2.0
- pudongping/hyperf-throttle-requests: ^2.0
- pudongping/hyperf-wise-locksmith: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- hyperf/devtool: ~3.0.0
- hyperf/testing: ~3.0.0
- hyperf/watcher: ^3.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.0
- swoole/ide-helper: ^5.0
- symfony/var-dumper: ^6.0
Suggests
- ext-json: Required to use JSON.
- ext-openssl: Required to use HTTPS.
- ext-pdo: Required to use MySQL Client.
- ext-pdo_mysql: Required to use MySQL Client.
- ext-redis: Required to use Redis Client.
README
本项目采用 hyperf 3.0 框架。
服务器要求
- PHP >= 8.0 and <= 8.1
- 以下任一网络引擎
- Swoole PHP 扩展 >= 4.5,并关闭了
Short Name
- Swow PHP 扩展 (Beta)
- Swoole PHP 扩展 >= 4.5,并关闭了
- JSON PHP 扩展
- Pcntl PHP 扩展
- OpenSSL PHP 扩展(如需要使用到 HTTPS)
- PDO PHP 扩展 (如需要使用到 MySQL 客户端)
- Redis PHP 扩展 (如需要使用到 Redis 客户端)
- Protobuf PHP 扩展 (如需要使用到 gRPC 服务端或客户端)
创建项目
# default latest version composer create-project pudongping/hyperf-biz-web-api ~/hyperf-project/example-app # hyperf 2.2 and PHP >= 7.4 composer create-project pudongping/hyperf-biz-web-api:~v2.2.1 ~/hyperf-project/example-app # hyperf 3.0 and PHP >= 8.0 and <= 8.1 composer create-project pudongping/hyperf-biz-web-api:~v3.0.1 ~/hyperf-project/example-app
docker 下运行
# 新建网络 docker network create alex-network # 假设项目安装在 `~/hyperf-project/example-app` docker run --name hyperf-project \ -v ~/hyperf-project:/hyperf-project \ --net=alex-network \ -p 9510-9520:9510-9520 -it \ --privileged -u root \ --entrypoint /bin/sh \ hyperf/hyperf:8.0-alpine-v3.16-swoole # docker 容器内可能要添加阿里云 composer 镜像 composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
启动项目
# 进入 docker 容器 docker exec -it hyperf-project bash # 进入到项目目录 cd /hyperf-project/example-app # 执行项目启动命令 php bin/hyperf.php start
目录规范
- 业务代码全部写在
Services
目录中 Request
和Response
只能在Controller
中使用response
返回的code
和message
信息应全部在Constants
目录下的ErrorCode.php
文件中定义- 请求数据的验证代码逻辑应统一放在
Request
目录下
代码规范
分支或者标签
分支
- 2.2 和 2.2.1 : For hyperf 2.2 (推荐使用 2.2.1 branch)
- 3.0 和 3.0.1 : For hyperf 3.0 (推荐使用 3.0.1 branch)
标签
- 1.x: For hyperf 2.2 (没有 bug 的情况下,不再更新)
- 2.x: For hyperf 2.2 (持续更新)
- 3.x: For hyperf 3.0 (持续更新)
关于分支和标签,可详见
其他
本项目许多核心功能均来自 pudongping/hyperf-kit 扩展包。
以下文件可能在你项目中用不上,建议拉取代码之后进行删除。
app/Controller/DemoController.php
test/Cases/DemoTest.php