1. Go to this page and download the library: Download chaz6chez/structure library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chaz6chez / structure example snippets
namespace YoursNamespace;
use Structure\Struct;
class User extends Struct {
// 当id为非null值时,必须满足int 10 < id < 20
/**
* @rule int,min:10,max:20|id format error:1001
*/
public $id;
// name为必填,必须满足string 1 < name长度 < 20
/**
* @rule string,min:1,max:20|name format error:2001
* @
/**
* @default func:is_array 会找到is_array函数
* @default method:_set 会定位当前类的_set方法
* @default method:Handler\Help,get 会定位Handler\Help类的get方法
*/
public $name;
public static function _set(){
return 'abc';
}
// 以name的@default标签为string:John举例
/**
* @default string:John
*/
public $name;
$struct = new Struct();
// @default无法生效,值为null
$struct->name;
// @default可以生效,值为字符串John
$struct()->name;
/**
* @lic $name;
/**
* @rule string,min:10,max:20|name format error
* @rule int,min:10,max:20|name format error
* @rule float,min:1.0,max:2.1,scale:3|name format error
* @rule bool,true|name format error
* @rule object,class:|name format error
* @rule array,min:10,max:20,values:string|name format error
* @rule map,min:1,max:5,keys:string,values:int|name format error
* @rule url,path:true,query:true|name format error
* @rule ip,ipv4:false,ipv6:false,private:false,reserved:false|name format error
* @rule regex,min:10,max:20,regex:/.?/|name format error
*/
public $name;
/**
* @rule func:_set 会找到_set函数
* @rule method:_set 会定位当前类的_set方法
* @rule method:Handler\Help,get 会定位Handler\Help类的get方法
*/
public $name;
public static function _set($value) : bool
{
return $value === '_method';
}
}
function _set($value) : bool
{
return $value === '_func';
}