Download the PHP package yhs/hyperf-scaffold without Composer

On this page you can find all versions of the php package yhs/hyperf-scaffold. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hyperf-scaffold

使用规范:

1、常量

常量在app\Constants目录下,常量文件命名方式以Constant为后缀,如UriConstant、CommonConstant等等

比如使用UriConstant用作路由uri的常量,代码如下

2、控制器

定义路由我们使用注解来进行定义,尽可能不用配置文件就不用配置文件能使用注解就使用注解

注解介绍

注解是swagger的注解用于Api文档接口说明,详细可以到https://github.com/tw2066/api-docs 查看用法

注解就是在请求体中添加请求头的参数

注解就是定义接口路由,详细可以到官网查看https://hyperf.wiki/3.1/#/zh-cn/router

Controller继承AbstractController抽象类,主要是返回使用返回json结果。

这是脚手架中编写好的日志工具类

这是调用服务的写法,可以参考官网https://hyperf.wiki/3.1/#/zh-cn/quick-start/overview?id=通过-inject-注解注入 类似springboot的@Resource和@Autowired那样

post请求,对于路由Uri路径还有

注解是swapper中uri的标题

注解是swagger响应的返回对象参数,如返回的json是 那么写法可以

重点1: 注解是获取json的请求体,然后序列化转对象的注解,所有的请求参数都与对接接收,不要用数组接收,这是规范。该注解参考与springboot中的的注解

是校验参数的注解

重点2: 返回的类型是BusinessResponse对象,必须所有的响应体返回该对象,该对象字段有code响应码、message响应信息、data响应体。

BusinessResponse对象主要方法:isSuccess()判断响应是否成功,ok(mixed $data)返回成功的响应,fail(int $code = 50000, string $message = 'service exception', mixed $data = null)返回错误的响应,toArray()转数组

另外有个公共类app\Common\BusinessResult.php,返回的也是BusinessResponse对象,在BusinessResponse的基础多了个failForEnum(BaseObject $baseObject)的方法,该返回传递参数是枚举,根据枚举返回错误信息,枚举案例代码如下:

使用案例

3、VO,PO,DTO定义

VO请求体/响应体定义

目录规范:app\POHO\VO\Request是请求目录,app\POJO\VO\Response是响应体目录,所有文件命名以VO为后缀

如:请求的VO,命名为:代码如下

自动生成get和set的方法。

请求体的说明

是字段说明

是校验说明

是数组的泛型

作用用于序列化使用,输出日志自动转json格式

如:响应体vo,命名为:,代码如下

PO数据库字段定义对象

目录规范:app\POJO\PO\UserPO.php,代码如下

BaseEntity是数据库默认字段定义,所以创建数据库时必须要有id、created_date_time、created_by、updated_date_time、updated_by。

数据库字段命名分隔下划线"_",那么po的字段必须是驼峰式才能接收,id字段是字符类型使用uuid32位

DTO

DTO是应用架构中不同层之间传输数据,目录在app\POJO\DTO下

4、服务逻辑编写

服务类在创建服务的接口,在创建实现服务接口的服务方法,如:

用户服务:app\Service\UserService.php

实现用户服务:app\Service\Impl\UserServiceImpl.php

是将服务注入到框架,类似Java的的注解,详细可以查看https://github.com/lazychanger/hyperf-helper-dependency 因hyperf-helper-dependency项目长久没有更新,导致不兼容新的版本,所以我在它基础上修复了该BUG,项目代码是https://github.com/yhs19900902/hyperf-helper-dependency

LoginVerification是数据校验层,LoginLogic是数据逻辑实现层。我的项目开发设计理想是Controller->Service->Verification->Logic->BussinessResponse,意思是Api控制层接收参数 开始调用服务 在服务中校验参数 参数通过开始执行逻辑 最终输出结果。

因此,在Service目录中也有app\Service\Impl\Verification和app\Service\Impl\Logic的目录。

校验的文件也是以目录为后缀app\Service\Impl\Verification\LoginVerification,代码:

逻辑层文件app\Service\Impl\Logic\LoginLogic

重点3: 代码中查询数据库后得到的数据反射给UserPO对象,该写法中map查询是使用了枚举的callback来实现,枚举代码是

.env配置文件

配置nacos配置中心的配置文件、数据库、redis

框架的工具类

在app\Utils目录下有部分写好的工具类

是日期的使用类,可以简化日期的使用

是打印日志的工具类

是计算接口的时间,使用案例可以查看Controller层

是常用的一些工具类,如生成uuid、获取ip地址等等

是用于手动回滚使用,该工具类可以在Controller层结合BusinessResponse对象返回的isSuccess()方法判断用户手动回滚。该工具留给大家自己实现

整体demo案例流程

Controller路由入口

Constant常量目录

Enum枚举

Model数据库层

PO层

vo层

Service服务层

Service服务Impl层

Verification校验层

Logic逻辑层


All versions of hyperf-scaffold with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
free2one/hyperf-php-accessor Version *
hyperf/cache Version ~3.1.0
hyperf/command Version ~3.1.0
hyperf/config Version ~3.1.0
hyperf/config-aliyun-acm Version *
hyperf/config-apollo Version *
hyperf/config-center Version *
hyperf/config-etcd Version *
hyperf/config-nacos Version *
hyperf/config-zookeeper Version *
hyperf/constants Version ~3.1.0
hyperf/database Version ~3.1.0
hyperf/db-connection Version ~3.1.0
hyperf/engine Version ^2.10
hyperf/framework Version ~3.1.0
hyperf/grpc Version 3.1.*
hyperf/guzzle Version ~3.1.0
hyperf/http-server Version ~3.1.0
hyperf/http2-client Version 3.1.*
hyperf/json-rpc Version ~3.1.0
hyperf/logger Version ~3.1.0
hyperf/memory Version ~3.1.0
hyperf/model-cache Version ~3.1.0
hyperf/phar Version *
hyperf/process Version ~3.1.0
hyperf/redis Version ~3.1.0
hyperf/rpc Version ~3.1.0
hyperf/rpc-client Version ~3.1.0
hyperf/rpc-server Version ~3.1.0
hyperf/validation Version *
tangwei/apidocs Version *
tangwei/knife4j-ui Version *
yhs-hyperf-helper/dependency Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yhs/hyperf-scaffold contains the following files

Loading the files please wait ....