PHP code example of mvaliolahi / sibdoc

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

    

mvaliolahi / sibdoc example snippets


$api =  new SibDoc([
    'url'         => 'http://127.0.0.1:8000',
    'title'       => 'Our Awesome API',
    'description' => 'Generate API Document Using Lovely PHP.',
]);

   
$api->post('transactions/{id}', function (Request $request) {

    //  Define Request.
    $request->title('Show transaction.');
    $request->version("v1"); // Optional

    $request->parameters([
        'token' => 'status'     => 'PAID | UNPAID',
            'created_at' =>  'timestamp', 
        ]);        
        
    // Assings Reaponses to the Request.
    $request->response($success);
    
});


      
$api->group('app', function(SibDoc $api) {
    
    $api->delete('posts/{id}', function (Request $request) {
        // Define request and response.
    });
        
});


$api->model('user', [
    'id'     => 'numeric',
    'name'   => 'string',
    'family' => 'string',
    'avatar' => 'url',
]);

$api->get('users', function (Request $request) {

    $request->title('Get all users');
    $request->version(1.2);
    $request->description('...');
    $request->parameters(['token' => 'cond argument is null it will act as getter.
        ]);    
        
    $fail = (new Response())
        ->title('Fail')
        ->description('...')
        ->code(404)
        ->body([
            'data'  => []
        ]); 
        
    $request->response($success);    
    $request->response($fail);    
                   
});


$api->saveTo('/home/meysam/');


/**
 * Class FakeGenerator
 * @package Tests\Generators
 */
class FakeGenerator extends DocumentGenerator
{
    /**
     * @param $path
     * @return mixed
     */
    public function format($path)
    {
        return 'fake generator!';
    }
}

$api = new SibDoc([
    'url'         => 'http://127.0.0.1:8000',
    'title'       => 'SibDoc Document Generator',
    'description' => 'Generate Api Document Using Pure PHP.',
    'generator'   => [
        'fake_generator' => FakeGenerator::class
    ],
]);

// define you groups and endpoints

$api->saveTo('/home/user/', 'fake_generator');