2017 © Pedro Peláez
 

library drafter-php

PHP wrapper around drafter binary

image

hmaus/drafter-php

PHP wrapper around drafter binary

  • Friday, July 20, 2018
  • by hendrikmaus
  • Repository
  • 2 Watchers
  • 24 Stars
  • 7,863 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 11 Versions
  • 18 % Grown

The README.md

Drafter PHP Wrapper

PHP wrapper for Drafter API Blueprint Parser harness., (*1)

Minimum PHP Version codecov.io , (*2)

What is Drafter-php?

Drafter-php allows you to use use the drafter API Blueprint Parser harness with your PHP application., (*3)

In a nutshell: you can convert API Blueprint files to parse result., (*4)

API Blueprint is a webservice documentation language built on top of Markdown., (*5)

Requirements

What Is What

Drafter is a C++ tool to parse API Blueprint.
Drafter-php is a PHP wrapper around the Drafter command line tool., (*6)

Installation

The recommended way to install Drafter-php is by using composer:, (*7)

$ composer require hmaus/drafter-php

This will install the PHP package with your application.
Please keep in mind that Drafter is not included., (*8)

Install Drafter Command Line Tool using Composer

Head over to hmaus/drafter-installer., (*9)

Usage of Drafter-php

  1. Get an instance of the \DrafterPhp\DrafterInterface implementation, \DrafterPhp\Drafter 1.1 You will need to pass the path to your drafter binary to the constructor 1.2 It is recommended to solve this using a dependency injection container
  2. Set the input file and options on your \DrafterPhp\Drafter instance 2.1 Drafter-php currently does not support passing blueprint code directly to Drafter; it has to be stored in a file at this time
  3. Run your command

Input / Output Examples

Note: drafter-php does not assert the structure of the output. If you see differences in the examples to your actual output, please refer to the official drafter docs., (*10)

Given this api blueprint source:, (*11)

# GET /message
+ Response 200 (text/plain)

        Hello World!

The result will look similar (json refract):, (*12)

{
  "element": "parseResult",
  "content": [
    {
      "element": "category",
      "meta": {
        "classes": [
          "api"
        ],
        "title": ""
      },
      "content": [
        {
          "element": "category",
          "meta": {
            "classes": [
              "resourceGroup"
            ],
            "title": ""
          },
          "content": [
            {
              "element": "resource",
              "meta": {
                "title": ""
              },
              "attributes": {
                "href": "/message"
              },
              "content": [
                {
                  "element": "transition",
                  "meta": {
                    "title": ""
                  },
                  "content": [
                    {
                      "element": "httpTransaction",
                      "content": [
                        {
                          "element": "httpRequest",
                          "attributes": {
                            "method": "GET"
                          },
                          "content": []
                        },
                        {
                          "element": "httpResponse",
                          "attributes": {
                            "statusCode": "200",
                            "headers": {
                              "element": "httpHeaders",
                              "content": [
                                {
                                  "element": "member",
                                  "content": {
                                    "key": {
                                      "element": "string",
                                      "content": "Content-Type"
                                    },
                                    "value": {
                                      "element": "string",
                                      "content": "text/plain"
                                    }
                                  }
                                }
                              ]
                            }
                          },
                          "content": [
                            {
                              "element": "asset",
                              "meta": {
                                "classes": [
                                  "messageBody"
                                ]
                              },
                              "attributes": {
                                "contentType": "text/plain"
                              },
                              "content": "Hello World!\n"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Code Examples

Found something wrong? Feel free to contribute, (*13)

Make sure it works

To make sure it works, we'll ask Drafter for the current version., (*14)

$version = $drafter
    ->version()
    ->run();

// Reset options on the command
$drafter->resetOptions();

$version should now contain a string like v1.0.0. If something is wrong, an exception will have been thrown most likely., (*15)

Keep in mind that Drafter-php is designed to keep its state, run \DrafterPhp\DrafterInterface::resetOptions to get rid of the version option you just set for the next call on the instance., (*16)

Parse your-service.apib into your-service.refract.json

Make sure your input path is correct and readable, and your output path is writable., (*17)

$drafter
    ->input('your-service.apib')
    ->format('json')
    ->type('refract')
    ->output('your-service.refract.json')
    ->run();

Parse your-service.apib into your-service.ast.json

Make sure your input path is correct and readable, and your output path is writable., (*18)

$drafter
    ->input('your-service.apib')
    ->format('json')
    ->output('your-service.ast.json')
    ->run();

Parse your-service.apib into a PHP data structure

$refract = $drafter
    ->input('your-service.apib')
    ->format('json')
    ->run();

$phpObj = json_decode($refract);
$phpArr = json_decode($refract, true);

Parse your-service.apib into YAML format

$drafter
    ->input('your-service.apib')
    ->format('yaml') // optional as yaml is the default
    ->output('your-service.ast.yml')
    ->run();

Get Process before it is run

$process = $drafter
    ->input('your-service.apib')
    ->format('json')
    ->output('your-service.refract.json')
    ->build();

// do stuff with the process

$drafter
    ->run($process);

Feature Roadmap

Do not hesitate to contribute., (*19)

  • [ ] support passing raw api blueprint code into \DrafterPhp\DrafterInterface::input, rather than always a file path

License

Drafter-php is licensed under the MIT License - see the LICENSE file for details, (*20)

The Versions

20/07 2018

dev-master

9999999-dev

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

20/07 2018

v5.0.1

5.0.1.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

08/07 2018

dev-php72

dev-php72

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

16/06 2018

v5.0.0

5.0.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

20/09 2016

v4.0.1

4.0.1.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

20/09 2016

dev-introduce-drafter-installer

dev-introduce-drafter-installer

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

06/08 2016

v4.0.0

4.0.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

31/03 2016

v3.0.0

3.0.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

07/11 2015

v2.0.0

2.0.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

04/10 2015

v1.0.0

1.0.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus

03/09 2015

v0.1.0

0.1.0.0

PHP wrapper around drafter binary

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hendrik Maus