PHPackages                             goez/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. goez/drafter-php

AbandonedArchivedLibrary

goez/drafter-php
================

PHP wrapper around drafter binary

7.0.1(3y ago)037.4k1MITPHPPHP &gt;=8.0

Since Sep 3Pushed 3y agoCompare

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

READMEChangelogDependencies (4)Versions (17)Used By (1)

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

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 77.1% 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 ~190 days

Recently: every ~202 days

Total

14

Last Release

1441d ago

Major Versions

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

v6.1.1 → 7.0.02022-06-07

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

v2.0.0PHP &gt;=5.6

7.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/000012ed8f10873694d29e2f60b7b71171c088d6fd655a695210dd2fe46172b9?d=identicon)[jaceju](/maintainers/jaceju)

---

Top Contributors

[![hendrikmaus](https://avatars.githubusercontent.com/u/188284?v=4)](https://github.com/hendrikmaus "hendrikmaus (54 commits)")[![jaceju](https://avatars.githubusercontent.com/u/310474?v=4)](https://github.com/jaceju "jaceju (7 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/goez-drafter-php/health.svg)

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

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[illuminate/process

The Illuminate Process package.

44699.5k65](/packages/illuminate-process)[statamic/cli

Statamic CLI Tool

7587.7k](/packages/statamic-cli)

PHPackages © 2026

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