diff --git a/index.php b/index.php index 5770ceb2..7e5c1f01 100755 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /** * Set up include path for source handling */ -set_include_path(get_include_path().":".__DIR__.'/src/'); +set_include_path(get_include_path() . ":" . __DIR__ . '/src/'); /** * Set up required classes (with the autoloader) @@ -14,13 +14,23 @@ use PHPDraft\Parse\JsonToHTML; define('VERSION', '0'); - $values = UI::main($argv); $apib = new ApibFileParser($values['file']); $json = new Drafter($apib); $html = new JsonToHTML($json->parseToJson()); -$html->get_html($values['template'], $values['image']); +$html->sorting = $values['sorting']; +$html->get_html($values['template'], $values['image'], $values['css'], $values['js']); + +function phpdraft_var_dump($var) +{ + if (defined('__PHPDRAFT_PHAR__')) { + return; + } + echo '
'; + var_dump($var); + echo ''; +} ?> diff --git a/src/PHPDraft/In/ApibFileParser.php b/src/PHPDraft/In/ApibFileParser.php index 11ab555f..bd2bf343 100644 --- a/src/PHPDraft/In/ApibFileParser.php +++ b/src/PHPDraft/In/ApibFileParser.php @@ -12,12 +12,14 @@ class ApibFileParser { /** * Complete API Blueprint + * * @var string */ protected $full_apib; /** * Location of the API Blueprint to parse + * * @var string */ protected $location; @@ -29,7 +31,7 @@ class ApibFileParser */ public function __construct($filename = 'index.apib') { - $this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/'; + $this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/'; $this->full_apib = $this->get_apib($filename); } @@ -49,7 +51,8 @@ function get_apib($filename) $matches = []; preg_match_all('', $file, $matches); foreach ($matches[1] as $value) { - $file = str_replace('', $this->get_apib($this->location . $value . '.apib'), $file); + $file = str_replace('', + $this->get_apib($this->location . $value . '.apib'), $file); } return $file; @@ -57,8 +60,7 @@ function get_apib($filename) private function file_check($filename) { - if(!file_exists($filename)) - { + if (!file_exists($filename)) { file_put_contents('php://stderr', "API File not found: $filename\n"); exit(1); } diff --git a/src/PHPDraft/Model/Category.php b/src/PHPDraft/Model/Category.php index 2e7f54c6..3a22b8ec 100644 --- a/src/PHPDraft/Model/Category.php +++ b/src/PHPDraft/Model/Category.php @@ -14,6 +14,7 @@ class Category extends HierarchyElement { /** * API Structure element + * * @var DataStructureElement[] */ public $structures = []; @@ -28,10 +29,8 @@ class Category extends HierarchyElement function parse($object) { parent::parse($object); - foreach ($object->content as $key => $item) - { - switch ($item->element) - { + foreach ($object->content as $key => $item) { + switch ($item->element) { case 'resource': $resource = new Resource($this); $this->children[] = $resource->parse($item); @@ -42,12 +41,9 @@ function parse($object) $struct->deps = $deps; $struct->parse($item, $deps); - if (isset($item->content[0]->meta->id)) - { + if (isset($item->content[0]->meta->id)) { $this->structures[$item->content[0]->meta->id] = $struct; - } - else - { + } else { $this->structures[] = $struct; } diff --git a/src/PHPDraft/Model/Elements/ArrayStructureElement.php b/src/PHPDraft/Model/Elements/ArrayStructureElement.php index 73f980f1..46453edf 100644 --- a/src/PHPDraft/Model/Elements/ArrayStructureElement.php +++ b/src/PHPDraft/Model/Elements/ArrayStructureElement.php @@ -13,18 +13,22 @@ class ArrayStructureElement extends DataStructureElement implements StructureElement { + /** + * Type of objects in the array + * + * @var + */ + public $type_of; + public function parse($item, &$dependencies) { $this->element = (isset($item->element)) ? $item->element : 'array'; - $this->value = (isset($item->content)) ? $item->content : NULL; + $this->value = (isset($item->content)) ? $item->content : null; - if (isset($item->content)) - { - foreach ($item->content as $key => $sub_item) - { + if (isset($item->content)) { + foreach ($item->content as $key => $sub_item) { $this->type[$key] = $sub_item->element; - switch ($sub_item->element) - { + switch ($sub_item->element) { case 'array': $value = new ArrayStructureElement(); $this->value[$key] = $value->parse($sub_item, $dependencies); @@ -38,7 +42,7 @@ public function parse($item, &$dependencies) $this->value[$key] = $value->parse($sub_item, $dependencies); break; default: - $this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : NULL; + $this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : null; break; } } @@ -49,18 +53,17 @@ public function parse($item, &$dependencies) function __toString() { - if (!is_array($this->type)) - { + if (!is_array($this->type)) { return ''; } $return = '
' . $this->value . ' | ' . - ''.$type.' | ' . - '' . $this->description . ' | ' . - '' . $this->value . ' | ' . + '' . $type . ' | ' . + '' . $this->description . ' | ' . + ''; + return $return; } - /** - * Parse the description to HTML - * - * @return string - */ - public function description_as_html() + function simple_string() { - $this->description = Markdown::defaultTransform($this->description); + $return = '' . $this->value . ""; + + if (!empty($this->description)) { + $return .= ' - ' . $this->description; + } + + + return $return; + } + + function strval() + { + if (is_array($this->value)) { + $key = rand(0, count($this->value)); + if (is_subclass_of($this->value[$key], StructureElement::class)) { + return $this->value[$key]->strval(); + } + + return $this->value[$key]; + } + + return $this->value; } } \ No newline at end of file diff --git a/src/PHPDraft/Model/Elements/RequestBodyElement.php b/src/PHPDraft/Model/Elements/RequestBodyElement.php index 6ef01025..1962d747 100644 --- a/src/PHPDraft/Model/Elements/RequestBodyElement.php +++ b/src/PHPDraft/Model/Elements/RequestBodyElement.php @@ -22,15 +22,12 @@ class RequestBodyElement extends DataStructureElement implements StructureElemen */ public function parse($object, &$dependencies) { - if (empty($object) || !isset($object->content)) - { + if (empty($object) || !isset($object->content)) { return $this; } $this->element = $object->element; - if (isset($object->content) && is_array($object->content)) - { - foreach ($object->content as $value) - { + if (isset($object->content) && is_array($object->content)) { + foreach ($object->content as $value) { $struct = new RequestBodyElement(); $this->value[] = $struct->parse($value, $dependencies); } @@ -40,33 +37,30 @@ public function parse($object, &$dependencies) $this->key = $object->content->key->content; $this->type = $object->content->value->element; - $this->description = isset($object->meta->description) ? $object->meta->description : NULL; + $this->description = isset($object->meta->description) ? htmlentities($object->meta->description) : null; $this->description_as_html(); - $this->status = - isset($object->attributes->typeAttributes[0]) ? $object->attributes->typeAttributes[0] : NULL; + $this->status = + isset($object->attributes->typeAttributes[0]) ? $object->attributes->typeAttributes[0] : null; - if (!in_array($this->type, parent::DEFAULTS)) - { + if (!in_array($this->type, parent::DEFAULTS)) { $dependencies[] = $this->type; } - if ($this->type === 'object') - { - $value = isset($object->content->value->content) ? $object->content->value : NULL; + if ($this->type === 'object') { + $value = isset($object->content->value->content) ? $object->content->value : null; $this->value = new RequestBodyElement(); $this->value = $this->value->parse($value, $dependencies); return $this; } - if ($this->type === 'array') - { + if ($this->type === 'array') { $this->value = '[]'; return $this; } - $this->value = isset($object->content->value->content) ? $object->content->value->content : NULL; + $this->value = isset($object->content->value->content) ? $object->content->value->content : null; return $this; } @@ -80,14 +74,11 @@ public function parse($object, &$dependencies) */ public function print_request($type = 'application/x-www-form-urlencoded') { - if (is_array($this->value)) - { + if (is_array($this->value)) { $return = '