Skip to content

Commit cfccd75

Browse files
authored
Merge pull request #2 from SMillerDev/fix/cleanup
Fix/cleanup
2 parents 94fa25c + fbfd940 commit cfccd75

24 files changed

+232
-61
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
# JIRA plugin
88
atlassian-ide-plugin.xml
99

10+
config.json

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
# PHP-Drafter
1+
# PHPDraft
22
This is a parser for API Blueprint files in PHP.
33

44
## Usage
55
For direct usage you can run:
66
```bash
7-
$ ./php-drafter.phar blueprint-file.apib > blueprint-webpage.html
7+
$ ./phpdraft.phar blueprint-file.apib > blueprint-webpage.html
88
```
99
You can also install it first:
1010
```bash
11-
$ cp php-drafter.phar /usr/bin/php-drafter
12-
$ chmod +x /usr/bin/php-drafter
13-
$ php-drafter blueprint-file.apib > blueprint-webpage.html
11+
$ cp phpdraft.phar /usr/bin/phpdraft
12+
$ chmod +x /usr/bin/phpdraft
13+
$ phpdraft blueprint-file.apib > blueprint-webpage.html
1414
```
1515

16+
## Including Files
17+
It is possible to include other files in your blueprint by using a special include directive with a path to the included file relative to the current file's directory. Included files can be written in API Blueprint, Markdown or HTML (or JSON for response examples). Included files can include other files, so be careful of circular references.
18+
19+
```markdown
20+
<!-- include(filename.md) -->
21+
```
22+
23+
For tools that do not support this include directive it will just render out as an HTML comment. API Blueprint may support its own mechanism of including files in the future, and this syntax was chosen to not interfere with the [external documents proposal](https://github.com/apiaryio/api-blueprint/issues/20) while allowing `PHPDraft` users to include documents today.
24+
25+
_Thanks to [aglio](https://github.com/danielgtaylor/aglio) for the idea._
26+
1627
## Writing API documentation
1728

1829
For writing API documentation using [API Blueprint](http://apiblueprint.org/) syntax. You can read about its [specification](https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md).
@@ -65,7 +76,7 @@ Return the information for the Person
6576

6677

6778
## Dependencies
68-
PHP-Drafter requires [drafter](https://github.com/apiaryio/drafter) to be installed. Refer to the drafter page for the installation details.
79+
PHPDraft requires [drafter](https://github.com/apiaryio/drafter) to be installed. Refer to the drafter page for the installation details.
6980

7081
## Libraries
7182
This app usage the following libraries:

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"tmpdir": "/tmp/drafter"
2+
"tmpdir": "/tmp/drafter",
3+
"logo": "/home/smillernl/Documents/5acf473a9e6a3deb8e98a2b6373d0a83.png"
34
}

config.json.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tmpdir": "/tmp/drafter",
3+
"logo": "/path/to/some/logo.png"
4+
}

index.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
<?php
2+
/**
3+
* Set up include path for source handling
4+
*/
25
set_include_path(get_include_path().":".__DIR__.'/src/');
36
$config = json_decode(file_get_contents(__DIR__."/config.json"));
7+
8+
/**
9+
* Set up required classes (with the autoloader)
10+
*/
411
require_once 'PHPDraft/Core/Autoloader.php';
512
use PHPDraft\In\ApibFileParser;
613
use PHPDraft\Parse\ApibToJson;
714
use PHPDraft\Parse\JsonToHTML;
15+
16+
if($argc < 1)
17+
{
18+
file_put_contents('php://stderr', "Missing file to parse\n");
19+
exit(2);
20+
}
21+
822
$apib = new ApibFileParser($argv[1]);
923
$json = new ApibToJson($apib);
1024
$json->parseToJson();
1125
$html = new JsonToHTML($json);
12-
echo $html->get_html();
26+
$html->get_html();
1327
?>

src/PHPDraft/In/ApibFileParser.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010

1111
class ApibFileParser
1212
{
13-
protected $out_string;
13+
/**
14+
* Complete API Blueprint
15+
* @var string
16+
*/
17+
protected $full_apib;
1418

19+
/**
20+
* Location of the API Blueprint to parse
21+
* @var string
22+
*/
1523
protected $location;
1624

1725
/**
@@ -21,8 +29,8 @@ class ApibFileParser
2129
*/
2230
public function __construct($filename = 'index.apib')
2331
{
24-
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';
25-
$this->out_string = $this->get_apib($filename);
32+
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';
33+
$this->full_apib = $this->get_apib($filename);
2634
}
2735

2836
/**
@@ -52,7 +60,7 @@ function get_apib($filename)
5260
*/
5361
function __toString()
5462
{
55-
return $this->out_string;
63+
return $this->full_apib;
5664
}
5765

5866
}

src/PHPDraft/Model/APIBlueprintElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class APIBlueprintElement
4141
protected $parent = NULL;
4242

4343
/**
44-
* Parse an object to an element
44+
* Parse a JSON object to an element
4545
*
4646
* @param \stdClass $object an object to parse
4747
*

src/PHPDraft/Model/Category.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* This file contains the Category.php
44
*
5-
* @package php-drafter\SOMETHING
5+
* @package PHPDraft\Model
66
* @author Sean Molenaar<[email protected]>
77
*/
88

@@ -17,25 +17,11 @@ class Category extends APIBlueprintElement
1717
public $structures = [];
1818

1919
/**
20-
* Add a struct dependency
20+
* Fill class values based on JSON object
2121
*
22-
* @param string $object Name of the struct to add
22+
* @param \stdClass $object JSON object
2323
*
24-
* @internal param string $name Name of the type
25-
*/
26-
public function add_struct($object)
27-
{
28-
echo "<pre>";
29-
var_dump($object);
30-
echo "</pre>";
31-
}
32-
33-
/**
34-
* Parse the category
35-
*
36-
* @param \stdClass $object
37-
*
38-
* @return $this
24+
* @return $this self-reference
3925
*/
4026
function parse($object)
4127
{

src/PHPDraft/Model/DataStructureElement.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* This file contains the DataStructureElement.php
44
*
5-
* @package php-drafter\SOMETHING
5+
* @package PHPDraft\Model
66
* @author Sean Molenaar<[email protected]>
77
*/
88

@@ -15,26 +15,31 @@ class DataStructureElement
1515
* @var string
1616
*/
1717
public $key;
18+
1819
/**
1920
* Object JSON type
2021
* @var string
2122
*/
2223
public $type;
24+
2325
/**
2426
* Object description
2527
* @var string
2628
*/
2729
public $description;
30+
2831
/**
2932
* Type of element
3033
* @var string
3134
*/
3235
public $element = NULL;
36+
3337
/**
3438
* Object value
3539
* @var mixed|DataStructureElement[]
3640
*/
3741
public $value = NULL;
42+
3843
/**
3944
* Object status (required|optional)
4045
* @var string
@@ -48,7 +53,7 @@ class DataStructureElement
4853
public $deps;
4954

5055
/**
51-
* Unreported datatypes
56+
* Default datatypes
5257
* @var array
5358
*/
5459
protected $defaults = ['boolean', 'string', 'number', 'object', 'array'];

src/PHPDraft/Model/RequestBodyElement.php renamed to src/PHPDraft/Model/Elements/RequestBodyElement.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* @author Sean Molenaar<[email protected]>
77
*/
88

9-
namespace PHPDraft\Model;
9+
namespace PHPDraft\Model\Elements;
1010

11+
use PHPDraft\Model\DataStructureElement;
1112

1213
class RequestBodyElement extends DataStructureElement
1314
{
@@ -62,6 +63,13 @@ public function parse($object, &$dependencies)
6263
return $this;
6364
}
6465

66+
/**
67+
* Print the request body as a string
68+
*
69+
* @param string $type The type of request
70+
*
71+
* @return string Request body
72+
*/
6573
public function print_request($type = 'application/x-www-form-urlencoded')
6674
{
6775
if (is_array($this->value))

0 commit comments

Comments
 (0)