PHP code example of yiiman / apistorm

1. Go to this page and download the library: Download yiiman/apistorm 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/ */

    

yiiman / apistorm example snippets


$sdk->addsrv(
[
    'serid' => 0,
    'slave_server' => 1, // Pass the slave server ID if you want to create VPS on the Slave Server
    'virt' => 'kvm',
    'uid' => 0,
    'user_email' => '[email protected]',
    'user_pass' => 'test123',
    'fname' => '',
    'lname' => '',
    'plid' => 0,
    'osid' => 88,
    'hostname' => 'test12345.com',
    'rootpass' => 'test123',
    'ips' => ['192.168.111.49'],
    'num_ips6' => 0,
    'num_ips6_subnet' => 0,
    'stid' => 1,
    'space' => [
                0=>[
                     'size' => 2,
                     'st_uuid'=>'ngavdbegidnbme2d'
                   ],
                1=>[
                    'size'=>2,
                    'st_uuid'=>'ngavdbegidnbme2d'
                   ],
                   
                ],//For VPS with Multi-Disk
    'ram' => 1024,
    'swapram' => 0,
    'bandwidth' => 0,
    'network_speed' => 0,
    'cpu' => 1000,
    'cores' => 4,
    'cpu_percent' => 100.00,
    'vnc' => 1,
    'vncpass' => 'test123',
    'kvm_cache' => 0,
    'io_mode' => 0,
    'vnc_keymap' => 'en-us',
    'nic_type' => 'default',
    'osreinstall_limit' => 0,
]
);

$api = new TestApi();//This is a test API SDK class
$response=$api->createProduct(//This method will send data to server
    [//Our data is an array!
        'name'=>'Pen',//We dont know this parameter is e'=>3000
    ]
);
//$response is an array! and we dont know what is happening in every method without read documents

$api = new TestApi();//This is a test API SDK class
$data = new PostCreateProduct();//This is our input Class that extended from apiStorm classes

$data->name0 = 'Pen';//This is an at's mean this field is  if ($response && $response->isSuccess()) {//Here we check status of sent request
        echo $response->created_id;//If success we have classified response 
    }else{
        var_export($response->getError());//If error, we have classified error
    }
}

class TestApi
{
    public $protocol = 'https';
    public $baseURl = 'n8.yiiman.ir/webhook';
}

    /**
     * @param  YiiMan\ApiStorm\Post\BasePostData  $dataClass
     * @return YiiMan\ApiStorm\Core\Res
     */
    private function call($path, $dataClass, $method = 'post')
    {
        $servedArrayOfDataClass = $dataClass->serve();
        $connection = new YiiMan\ApiStorm\Core\Connection();
        $connection->baseURL = $this->baseURl;
        $connection->protocol = 'https';

        return $connection->call($path, [], $servedArrayOfDataClass, [],$method);
    }


class TestApi
{
    public $protocol = 'https';
    public $baseURl = 'n8.yiiman.ir/webhook';
    
    
    /**
     * @param  YiiMan\ApiStorm\Post\BasePostData  $dataClass
     * @return YiiMan\ApiStorm\Core\Res
     */
    private function call($path, $dataClass, $method = 'post')
    {
        $servedArrayOfDataClass = $dataClass->serve();
        $connection = new YiiMan\ApiStorm\Core\Connection();
        $connection->baseURL = $this->baseURl;
        $connection->protocol = 'https';

        return $connection->call($path, [], $servedArrayOfDataClass, [],$method);
    }
    
    
    
    /**
     * @param  PostCreateProduct  $product
     * @return CreateProductResponse|bool
     */
    public function createProduct(PostCreateProduct $product)
    {
        if ($product->validated()) {

            // you will send $product to your server
            $response = $this->call('6c81aa91-63a1-43d9-abb6-6b5398716f81', $product,'get');


            if ($response->isSuccess()) {
                $response = new CreateProductResponse($response);
            }

            return $response;
            // </ Here, you will classify response >
        } else {
            return false;
        }
    }

     /**
     * @param  PostCreateProduct  $product
     * @return CreateProductResponse|bool
     */
    public function createProduct2(PostCreateProduct $product)
    {
        if ($product->validated()) {

            // you will send $product to your server
            $response = $this->call('6c81aa91-63a1-43d9-abb6-6b5398716f81', $product);


            if ($response->isSuccess()) {
                $response = new CreateProductResponse($response);
            }

            return $response;
            // </ Here, you will classify response >
        } else {
            return false;
        }
    }
}

---src\
    |
    ---Responses\
        |
        ---ResponseClass1.php                      // extended from YiiMan\ApiStorm\Response\BaseResponse
        |--- public $responseField1='int';         // you can define one of this data types : int|string|float|serialize|json|array|class|classArray
        |--- public $responseField2='';            // if you set empty string, its main string type
        |
        ---ResponseClass2.php                      // extended from YiiMan\ApiStorm\Response\BaseResponse
        |--- public $responseField1='int';         // you can define one of this data types : int|string|float|serialize|json|array|class|classArray
        |--- public $responseField2='';            // if you set empty string, its main string type
        |
        .
        .
        .
    |
    ---Posts\
       |
       ---PostClass1.php                          // extended from YiiMan\ApiStorm\Post\BasePostData
       |--- public int    $field0;                // Required fields will ends by "0"
       |--- public string $anotherField='test';   // Optional field
       |--- public function rules(): array
                {
                    return
                        [
                            'field'             => 'int',//You should define input field type: int|string|array|float|object
                            'anotherField'      => 'string',
                        ];
                }
       |
       ---PostClass2.php                          // extended from YiiMan\ApiStorm\Post\BasePostData
       |--- public array $field0;                 // Required fields will ends by "0"
       |--- public int   $anotherField=2;         // Optional field
       |--- public function rules(): array
                {
                    return
                        [
                            'field'             => 'float',//You should define input field type: int|string|array|float|object
                            'anotherField'      => 'int',
                        ];
                }
       |
       |
       .
       .
       .
    |
    --- SDKClass.php
    |--- public $protocol = 'https';
    |--- public $baseURl = 'someURL';
    |--- firstMethod(PostClass1 $data):ResponseClass1{
        if ($data->validated()) {

            // you will send $data to your server
            $response = $this->call('path/to/api/url', $data);


            if ($response->isSuccess()) {
                $response = new CreateProductResponse($response);
            }
            // <  Here, you have classified response >
              return $response;
            // </ Here, you have classified response >
        } else {
            return false;
        }
    }
    |
    .
    .
    .