sergey-shandar/restapi-core-php-poc

REST API Core for PHP (Proof of concept)

dev-master 2023-05-05 04:53 UTC

This package is not auto-updated.

Last update: 2024-09-09 14:22:20 UTC


README

REST API Core for PHP (Proof of concept)

Build Status

Latest Unstable Version

Supported Run Times

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • HHVM 3.6

Required Windows Extensions

  • php_mbstring.dll
  • php_openssl.dll

Supported Request Types

Reflection

Supported Types

JSON

  • Serialization: PHP Type => string
  • Deserialization: string => PHP JSON Type => PHP Type

Conventions

Each user class should implement

  1. A default constructor.
  2. A createClassInfo static function which returns \RestApiCore\Reflection\Types\ClassInfo.

For example

<?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());
    }
}