PHPackages                             hmaus/drafter-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hmaus/drafter-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hmaus/drafter-php
=================

PHP wrapper around drafter binary

v6.1.1(6y ago)32127.0k↓14.3%9[1 issues](https://github.com/hendrikmaus/drafter-php/issues)5MITPHPPHP &gt;=5.6CI failing

Since Sep 3Pushed 6y ago2 watchersCompare

[ Source](https://github.com/hendrikmaus/drafter-php)[ Packagist](https://packagist.org/packages/hmaus/drafter-php)[ RSS](/packages/hmaus-drafter-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (14)Used By (5)

Drafter PHP Wrapper
===================

[](#drafter-php-wrapper)

PHP wrapper for [Drafter](https://github.com/apiaryio/drafter) API Blueprint Parser harness.

[![Minimum PHP Version](https://camo.githubusercontent.com/4cbdbfeca62402b9ca3d48503f2bf66fc9809569bcd6de47196d39fecff71e72/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e362d3838393242462e737667)](https://php.net/)[![codecov.io](https://camo.githubusercontent.com/3c6e39957d06937c90fbed161df28811eeeff30d33f93cf54de690191dba55ed/687474703a2f2f636f6465636f762e696f2f6769746875622f68656e6472696b6d6175732f647261667465722d7068702f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/hendrikmaus/drafter-php?branch=master)[![](https://camo.githubusercontent.com/1d7ab510d5732b0adac602fb655754b9e5f302ac1cab39c171b7a35744cc2676/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66393939613530386264316266386630636266372f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/hendrikmaus/drafter-php/maintainability)

What is Drafter-php?
--------------------

[](#what-is-drafter-php)

Drafter-php allows you to use use the [drafter](https://github.com/apiaryio/drafter) API Blueprint Parser harness with your PHP application.

In a nutshell: you can convert [API Blueprint](http://apiblueprint.org/) files to parse result.

[API Blueprint](http://apiblueprint.org/) is a webservice documentation language built on top of [Markdown](https://en.wikipedia.org/wiki/Markdown).

Requirements
------------

[](#requirements)

- PHP 5.6 or greater
- Drafter [command line tool](https://github.com/apiaryio/drafter#drafter-command-line-tool)

What Is What
------------

[](#what-is-what)

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

Installation
------------

[](#installation)

The recommended way to install Drafter-php is by using [composer](https://getcomposer.org):

```
$ composer require hmaus/drafter-php
```

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

### Install Drafter Command Line Tool using Composer

[](#install-drafter-command-line-tool-using-composer)

Head over to [hmaus/drafter-installer](https://github.com/hendrikmaus/drafter-installer).

Usage of Drafter-php
--------------------

[](#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

[](#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.

Given this api blueprint source:

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

        Hello World!
```

The result will look similar (json refract):

```
{
  "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

[](#code-examples)

> Found something wrong? Feel free to [contribute](https://github.com/hendrikmaus/drafter-php/blob/master/CONTRIBUTING.md)

#### Make sure it works

[](#make-sure-it-works)

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

```
$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.

> 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.

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

[](#parse-your-serviceapib-into-your-servicerefractjson)

Make sure your input path is correct and readable, and your output path is writable.

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

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

[](#parse-your-serviceapib-into-your-serviceastjson)

Make sure your input path is correct and readable, and your output path is writable.

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

#### Parse your-service.apib into a PHP data structure

[](#parse-your-serviceapib-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

[](#parse-your-serviceapib-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

[](#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
---------------

[](#feature-roadmap)

Do not hesitate to [contribute](https://github.com/hendrikmaus/drafter-php/blob/master/CONTRIBUTING.md).

- support passing raw api blueprint code into `\DrafterPhp\DrafterInterface::input`, rather than always a file path

License
-------

[](#license)

Drafter-php is licensed under the MIT License - see the [LICENSE](https://github.com/hendrikmaus/drafter-php/blob/master/LICENSE) file for details

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~166 days

Recently: every ~161 days

Total

11

Last Release

2249d ago

Major Versions

v1.0.0 → v2.0.02015-11-07

v2.0.0 → v3.0.02016-03-31

v3.0.0 → v4.0.02016-08-06

v4.0.1 → v5.0.02018-06-16

v5.0.1 → v6.0.02019-12-09

PHP version history (2 changes)v0.1.0PHP &gt;=5.4

v2.0.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed0b339a154b415594b6480f1a0ee0ac45fd395033123ea484cfe78f29f13dae?d=identicon)[hendrikmaus](/maintainers/hendrikmaus)

![](https://avatars.githubusercontent.com/u/711773?v=4)[Michael Schmidt-Voigt](/maintainers/m165437)[@M165437](https://github.com/M165437)

---

Top Contributors

[![hendrikmaus](https://avatars.githubusercontent.com/u/188284?v=4)](https://github.com/hendrikmaus "hendrikmaus (54 commits)")[![M165437](https://avatars.githubusercontent.com/u/711773?v=4)](https://github.com/M165437 "M165437 (6 commits)")[![leemcd56](https://avatars.githubusercontent.com/u/1885663?v=4)](https://github.com/leemcd56 "leemcd56 (2 commits)")[![Grummfy](https://avatars.githubusercontent.com/u/668804?v=4)](https://github.com/Grummfy "Grummfy (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hmaus-drafter-php/health.svg)

```
[![Health](https://phpackages.com/badges/hmaus-drafter-php/health.svg)](https://phpackages.com/packages/hmaus-drafter-php)
```

###  Alternatives

[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[spatie/typescript-transformer

This is my package typescript-transformer

3706.5M16](/packages/spatie-typescript-transformer)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[shivas/versioning-bundle

Symfony application versioning, simple console command to manage version (with providers e.g. git tag) of your application using Semantic Versioning 2.0.0 recommendations

1121.2M1](/packages/shivas-versioning-bundle)[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[shyim/danger-php

Port of danger to PHP

8544.9k](/packages/shyim-danger-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
