Download the PHP package hehex/hehep-hformat without Composer

On this page you can find all versions of the php package hehex/hehep-hformat. 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 hehep-hformat

hehep-hformat

介绍

hehep-hformat 是一个PHP 格式器工具组件,对数据列的集中处理,减少foreach 循环的编写,可通过自定义方法,满足不同场景以及业务需求
比如状态id转对应名称,http 的转换,统计量,json 字符串转数组等等,重用代码,并节省大量遍历处理的时间
支持多个格式器
支持直接使用格式器
支持添加自定义格式器

概念理解

格式器: 将数据格式化成指定的格式
格式器集合器: 将多个格式器组合成一个集合,方便使用
格式化规则:将数据列与格式器关联起来,形成固定的格式
格式管理器:对外提供格式化相关功能,比如:创建格式器,注册格式器,注册格式化集合器,数据格式化
字典数据源: 二维数组或数据库数据,如:[ ['id'=>1,'name'=>'正常'] ]

安装

组件配置

基本示例

格式化规则格式

['规则名称',[['格式器1','格式器1属性1'=>'','格式1属性2'=>''],['格式器2','格式器2属性1'=>'','格式器2属性2'=>''] ],'格式规则属性1'=>'','格式规则属性2'=>''],
比如:['ctime',[['date','params'=>['Y年m月d日 H:i']],['trim'],'alias'=>'created_time' ]]

格式化规则属性:
name:规则名称
alias:别名,即新的键名,指定新键名,"status_xxxx_name",":_text2" 冒号表示原始键名,比如"status_text2"
defval:如格式器无对应值,则为默认值
dataid:数据id键名,如未设置,则默认读取"规则名称"name

格式化示例

格式器直接使用

扩展格式器

基类: hehe\core\hformat\base\Formator, 格式器类必须继承该基类,并实现getValue方法
格式器属性:
alias:格式器别名,默认为方法名,如:trim
params:格式器方法参数,方法:date($value,$format = 'Y-m-d'),格式:['date','params'=>['Y-m-d']]

格式器定义

格式化集合器定义

集合器中定义的格式器方法名必须带后缀"Formator",如:trimFormator
属性:
alias:格式器别名,默认为方法名,如:trim
params:格式器方法参数,如:date($value,$format = 'Y-m-d'),参数必须放在数组中,如:['date','params'=>['Y-m-d']]
格式器注册格式如下:
类静态方法方式:common\extend\formats\CustomFormats@@res
对象方法方式:common\extend\formats\CustomFormats@res
数组函数方式:['对象','方法名']
闭包方式:function($value){return $value;}

注册格式器

格式化模型

格式化模型即是事先定义好格式化规则,然后通过格式化模型进行数据格式化
格式化模型规则:与常规"格式化规则"一致,但支持通过isdef属性设置是否为默认规则,默认规则必执行

定义格式化模型

格式化模型示例

字典格式器

基类: hehe\core\hformat\base\DictFormator, 字典格式器类必须继承此基类
可重写获取字典数据方法buildData(Rule $rule,array $datas)方法
字典格式器属性:
id:字典数据id,如:1
name:字典数据名称,如:admin
cache:缓存key,如果两个规则设置了相同的缓存key,则只读取一次字典数据,避免重复读取
data:获取字典数据方法,方法第一个参数是从数据中获取的id(dataid)集合,格式:['类名获对象','方法']
返回数据格式:[ ['id'=>1,'name'=>'超级管理员'], ['id'=>2,'name'=>'管理员'] ]
args:字典数据方法参数,如:['args'=>['Y-m-d']]

安装格式器

注解格式器

类名: hehe\core\hformat\annotation\AnnFormator
注解: @AnnFormator, @AnnFormator("别名")

默认格式器

格式器 说明 规则示例
int 强制整型 ['name', ['int'] ]
float 浮点型 ['name', ['float'] ]
jsonEncode 数组json ['name', ['jsonEncode'] ]
jsonDecode json字符串转数组 ['name', ['jsonDecode'] ]
date 日期格式 ['name', ['date','params'=>['Y-m-d']] ]
toArr 字符串转数组 ['name', ['toArr'] ]
trim 字符串去掉两边空格 ['name', ['trim'] ]
dict 字典数组列值转换 ['name', ['dict','id'=>'','name'=>''] ]

All versions of hehep-hformat with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
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 hehex/hehep-hformat contains the following files

Loading the files please wait ...