sergey-shandar / restapi-core-php-poc
PHP REST API 核心库(概念验证)
dev-master
2023-05-05 04:53 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-23 14:28:46 UTC
README
PHP REST API 核心库(概念验证)
支持运行时
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM 3.6
需要的 Windows 扩展
php_mbstring.dll
php_openssl.dll
支持的请求类型
反射
支持的类型
JSON
- 序列化:PHP 类型 > 字符串
- 反序列化:字符串 > PHP JSON 类型 > PHP 类型
约定
每个用户类应实现
- 一个默认构造函数。
- 一个返回
\RestApiCore\Reflection\Types\ClassInfo
的createClassInfo
静态函数。
例如
<?php use \RestApiCore\Reflection\Types\ClassInfo; use \RestApiCore\Reflection\Types\NumberInfo; use \RestApiCore\Reflection\Types\StringInfo; class SampleClass { /** * @var int $a */ public $a; /** * @var string[][][] $b */ public $b; /** * @var int[] $c */ public $c; /** * An optional parameter. * * @var string|null $d */ public $d; /** * @var SampleSubClass $sub */ public $sub; /** * @var SampleSubClass[] $subArray */ public $subArray; /** * SampleClass constructor. * * @param int|null $a * @param string[][][]|null $b * @param int[]|null $c * @param string|null $d * @param SampleSubClass|null $sub * @param SampleSubClass[]|null $subArray */ public function __construct( $a = null, array $b = null, array $c = null, $d = null, $sub = null, array $subArray = null) { $this->a = $a; $this->b = $b; $this->c = $c; $this->d = $d; $this->sub = $sub; $this->subArray = $subArray; } /** * @return ClassInfo */ public static function createClassInfo() { return ClassInfo::create(self::class) ->withProperty('a', 'a', NumberInfo::create()) ->withProperty('b', 'b', StringInfo::create()->createArray()->createArray()->createArray()) ->withProperty('c', 'CCC', NumberInfo::create()->createArray()) ->withProperty('d', 'd', StringInfo::create()) ->withProperty('sub', 'sub', SampleSubClass::createClassType()) ->withProperty('subArray', 'subArray', SampleSubClass::createClassType()->createArray()); } }