diff --git a/index.php b/index.php
index 47cc9f9d..8ce871c2 100755
--- a/index.php
+++ b/index.php
@@ -16,38 +16,42 @@
use PHPDraft\Parse\JsonToHTML;
define('VERSION', '0');
-$values = UI::main($argv);
-
-$apib = new ApibFileParser($values['file']);
-$apib = $apib->parse();
-
-$json = new DrafterAPI($apib);
-if (!(defined('DRAFTER_ONLINE_MODE') && DRAFTER_ONLINE_MODE === 1))
+try
{
- try
- {
- $json = new Drafter($apib);
- }
- catch (RuntimeException $exception)
+ $values = UI::main($argv);
+ $apib = new ApibFileParser($values['file']);
+ $apib = $apib->parse();
+
+ $json = new DrafterAPI($apib);
+ if (!(defined('DRAFTER_ONLINE_MODE') && DRAFTER_ONLINE_MODE === 1))
{
- file_put_contents('php://stderr', $exception->getMessage() . "\n");
- $options = [
- 'y' => 'Yes',
- 'n' => 'No',
- ];
- $answer = UI::ask('Do you want to use the online version? [y/n]', $options, 'y');
- if (!$answer)
+ try
{
- file_put_contents('php://stderr', 'Could not find a suitable drafter version');
- exit(1);
+ $json = new Drafter($apib);
+ }
+ catch (\PHPDraft\Parse\ResourceException $exception)
+ {
+ file_put_contents('php://stderr', $exception->getMessage() . "\n");
+ $options = [
+ 'y' => 'Yes',
+ 'n' => 'No',
+ ];
+ $answer = UI::ask('Do you want to use the online version? [y/n]', $options, 'y');
+ if (!$answer)
+ {
+ throw new \RuntimeException('Could not find a suitable drafter version', 1);
+ }
}
}
-}
-
-$html = new JsonToHTML($json->parseToJson());
-$html->sorting = $values['sorting'];
-$generator = $html->get_html($values['template'], $values['image'], $values['css'], $values['js']);
+ $html = new JsonToHTML($json->parseToJson());
+ $html->sorting = $values['sorting'];
+ $generator = $html->get_html($values['template'], $values['image'], $values['css'], $values['js']);
+} catch (RuntimeException $exception)
+{
+ file_put_contents('php://stderr', $exception->getMessage().PHP_EOL);
+ exit($exception->getCode());
+}
function phpdraft_var_dump(...$vars)
{
diff --git a/src/PHPDraft/In/ApibFileParser.php b/src/PHPDraft/In/ApibFileParser.php
index b699055a..6460275d 100644
--- a/src/PHPDraft/In/ApibFileParser.php
+++ b/src/PHPDraft/In/ApibFileParser.php
@@ -91,8 +91,7 @@ private function get_apib($filename)
private function file_check($filename)
{
if (!file_exists($filename)) {
- file_put_contents('php://stderr', "API File not found: $filename\n");
- exit(1);
+ throw new \RuntimeException("API File not found: $filename", 1);
}
}
diff --git a/src/PHPDraft/In/Tests/ApibFileParserTest.php b/src/PHPDraft/In/Tests/ApibFileParserTest.php
index af50148d..7efeacf5 100644
--- a/src/PHPDraft/In/Tests/ApibFileParserTest.php
+++ b/src/PHPDraft/In/Tests/ApibFileParserTest.php
@@ -51,6 +51,22 @@ public function testFilenameSetup()
$this->assertSame(__DIR__ . '/ApibFileParserTest.php', $property->getValue($this->class));
}
+ /**
+ * Test if exception when the file doesn't exist
+ * @expectedException \RuntimeException
+ * @expectedExceptionCode 1
+ * @expectedExceptionMessageRegExp "API File not found: [a-zA-Z0-9\/]*\/drafter\/non_existing_including_apib"
+ *
+ * @return void
+ */
+ public function testFilenameSetupWrong()
+ {
+ $property = $this->reflection->getProperty('filename');
+ $property->setAccessible(true);
+ $property->setValue($this->class, TEST_STATICS . '/drafter/non_existing_including_apib');
+ $this->class->parse();
+ }
+
/**
* Test if setup is successful
* @return void
diff --git a/src/PHPDraft/Model/Elements/ArrayStructureElement.php b/src/PHPDraft/Model/Elements/ArrayStructureElement.php
index d769392d..32020193 100644
--- a/src/PHPDraft/Model/Elements/ArrayStructureElement.php
+++ b/src/PHPDraft/Model/Elements/ArrayStructureElement.php
@@ -56,7 +56,7 @@ public function parse($object, &$dependencies)
*/
function __toString()
{
- $return = '
';
+ $return = '';
if (!is_array($this->value))
{
@@ -67,7 +67,7 @@ function __toString()
$type = (in_array($item, self::DEFAULTS)) ? $item : '' . $item . '';
- $return .= '- ' . $type . '
';
+ $return .= '- ' . $type . '
';
}
$return .= '
';
diff --git a/src/PHPDraft/Model/Elements/BasicStructureElement.php b/src/PHPDraft/Model/Elements/BasicStructureElement.php
index 06892dc6..322f6c86 100644
--- a/src/PHPDraft/Model/Elements/BasicStructureElement.php
+++ b/src/PHPDraft/Model/Elements/BasicStructureElement.php
@@ -90,8 +90,8 @@ abstract protected function new_instance();
*/
protected function parse_common($object, &$dependencies)
{
- $this->key = $object->content->key->content;
- $this->type = $object->content->value->element;
+ $this->key = (isset($object->content->key->content)) ? $object->content->key->content : NULL;
+ $this->type = (isset($object->content->value->element)) ? $object->content->value->element : NULL;
$this->description = isset($object->meta->description) ? htmlentities($object->meta->description) : NULL;
$this->status =
isset($object->attributes->typeAttributes) ? join(', ', $object->attributes->typeAttributes) : NULL;
diff --git a/src/PHPDraft/Model/Elements/EnumStructureElement.php b/src/PHPDraft/Model/Elements/EnumStructureElement.php
index ed9eb8be..a3694635 100644
--- a/src/PHPDraft/Model/Elements/EnumStructureElement.php
+++ b/src/PHPDraft/Model/Elements/EnumStructureElement.php
@@ -20,13 +20,16 @@ class EnumStructureElement extends BasicStructureElement
*/
public function parse($object, &$dependencies)
{
- $this->element = (isset($object->element)) ? $object->element : 'array';
+ $this->element = (isset($object->element)) ? $object->element : 'enum';
$this->parse_common($object, $dependencies);
+ $this->key = is_null($this->key) ? $object->content : $this->key;
+ $this->type = is_null($this->type) ? $object->element : $this->type;
+
if(!isset($object->content->value->content))
{
- $this->value = [];
+ $this->value = $this->key;
return $this;
}
@@ -52,7 +55,14 @@ public function parse($object, &$dependencies)
*/
function __toString()
{
- $return = '';
+ $return = '';
diff --git a/src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php b/src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php
index f814fea7..bcdcc1f4 100644
--- a/src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php
+++ b/src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php
@@ -187,7 +187,17 @@ public function testToStringWithArray()
{
$this->class->value = ['string', 'int'];
$return = $this->class->__toString();
- $this->assertSame('', $return);
+ $this->assertSame('', $return);
+ }
+
+ /**
+ * Test setup of new instances
+ */
+ public function testToStringWithString()
+ {
+ $this->class->value = 'hello';
+ $return = $this->class->__toString();
+ $this->assertSame('[ ]', $return);
}
/**
@@ -197,6 +207,6 @@ public function testToStringWithComplexArray()
{
$this->class->value = ['Bike', 'car'];
$return = $this->class->__toString();
- $this->assertSame('', $return);
+ $this->assertSame('', $return);
}
}
\ No newline at end of file
diff --git a/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php b/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php
index c902387c..69864702 100644
--- a/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php
+++ b/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php
@@ -64,7 +64,31 @@ public function testToStringWithArray()
{
$this->class->value = ['hello'=>'string', 'test'=>'int'];
$return = $this->class->__toString();
- $this->assertSame('', $return);
+ $this->assertSame('', $return);
+ }
+
+ /**
+ * Test setup of new instances
+ */
+ public function testToStringWithString()
+ {
+ $this->class->value = 'hello';
+ $this->class->key = 'key';
+ $this->class->element = 'string';
+ $return = $this->class->__toString();
+ $this->assertSame('key | string | |
', $return);
+ }
+
+ /**
+ * Test setup of new instances
+ */
+ public function testToStringWithStringComplex()
+ {
+ $this->class->value = 'hello';
+ $this->class->key = 'key';
+ $this->class->element = 'Car';
+ $return = $this->class->__toString();
+ $this->assertSame('key | Car | |
', $return);
}
/**
@@ -74,7 +98,7 @@ public function testToStringWithComplexArray()
{
$this->class->value = ['hello'=>'bike', 'test'=>'Car'];
$return = $this->class->__toString();
- $this->assertSame('', $return);
+ $this->assertSame('', $return);
}
/**
@@ -122,7 +146,7 @@ public function parseObjectProvider()
$base3 = new EnumStructureElement();
$base3->key = 'car_id_list';
- $base3->value = [];
+ $base3->value = 'car_id_list';
$base3->status = 'optional';
$base3->element = 'member';
$base3->type = 'array';
diff --git a/src/PHPDraft/Model/HTTPRequest.php b/src/PHPDraft/Model/HTTPRequest.php
index 423f8d3c..eb793ec9 100644
--- a/src/PHPDraft/Model/HTTPRequest.php
+++ b/src/PHPDraft/Model/HTTPRequest.php
@@ -157,7 +157,6 @@ public function get_curl_command($base_url, $additional = [])
return htmlspecialchars('curl ' . join(' ', $options) . ' ' . escapeshellarg($this->parent->build_url($base_url, true)));
}
-
/**
* Check if item is the same as other item
*
diff --git a/src/PHPDraft/Model/HTTPResponse.php b/src/PHPDraft/Model/HTTPResponse.php
index 7970e7e2..fbf6587c 100644
--- a/src/PHPDraft/Model/HTTPResponse.php
+++ b/src/PHPDraft/Model/HTTPResponse.php
@@ -69,8 +69,10 @@ public function __construct($parent)
*/
public function parse($object)
{
- if (isset($object->attributes)) {
+ if (isset($object->attributes->statusCode)) {
$this->statuscode = intval($object->attributes->statusCode);
+ }
+ if (isset($object->attributes->headers)) {
$this->parse_headers($object->attributes->headers);
}
diff --git a/src/PHPDraft/Model/Tests/CategoryTest.php b/src/PHPDraft/Model/Tests/CategoryTest.php
index 621d26fb..a1db610b 100644
--- a/src/PHPDraft/Model/Tests/CategoryTest.php
+++ b/src/PHPDraft/Model/Tests/CategoryTest.php
@@ -104,6 +104,26 @@ public function testParseIsCalledObject()
$this->assertNotEmpty($s_property->getValue($this->class));
}
+ /**
+ * Test basic parse functions where 'element=dataStructure'
+ */
+ public function testParseIsCalledObjectMetaID()
+ {
+ $property = $this->reflection->getProperty('parent');
+ $property->setAccessible(TRUE);
+ $property->setValue($this->class, $this->parent);
+
+ $json = '{"content":[{"element":"dataStructure", "content":[{"meta":{"id":4}, "key":{"content":"none"}, "value":{"element":"none"}}]}]}';
+
+ $this->class->parse(json_decode($json));
+
+ $this->assertSame($this->parent, $property->getValue($this->class));
+
+ $s_property = $this->reflection->getProperty('structures');
+ $s_property->setAccessible(TRUE);
+ $this->assertNotEmpty($s_property->getValue($this->class));
+ }
+
/**
* Test basic parse functions where 'element=henk'
*/
diff --git a/src/PHPDraft/Model/Tests/ResourceTest.php b/src/PHPDraft/Model/Tests/ResourceTest.php
index ecec10e2..107dbc21 100644
--- a/src/PHPDraft/Model/Tests/ResourceTest.php
+++ b/src/PHPDraft/Model/Tests/ResourceTest.php
@@ -106,7 +106,7 @@ public function testParseIsCalledIsCopy()
$property->setAccessible(TRUE);
$property->setValue($this->class, $this->parent);
- $obj = '{"content":[{"element":"copy", "content":""},{"element":"hello", "content":""}]}';
+ $obj = '{"content":[{"element":"copy", "content":""},{"element":"hello", "content":""}, {"element":"hello", "content":""}]}';
$this->class->parse(json_decode($obj));
diff --git a/src/PHPDraft/Model/Tests/TransitionTest.php b/src/PHPDraft/Model/Tests/TransitionTest.php
index f71d36be..b4d5917e 100644
--- a/src/PHPDraft/Model/Tests/TransitionTest.php
+++ b/src/PHPDraft/Model/Tests/TransitionTest.php
@@ -209,6 +209,26 @@ public function testParseIsCalledIsArrayContentResponse()
$this->assertSame('something', $href_property->getValue($this->class));
}
+ /**
+ * Test basic parse functions
+ */
+ public function testParseIsCalledIsArrayContentDefault()
+ {
+ $property = $this->reflection->getProperty('parent');
+ $property->setAccessible(TRUE);
+ $property->setValue($this->class, $this->parent);
+
+ $obj = '{"attributes":{"href":"something", "data":"hello"}, "content":[{"element":"123", "content":[{"element":"Cow", "content":[], "attributes":{"statusCode":"1000", "headers":{"content":[]}}}]}]}';
+
+ $this->class->parse(json_decode($obj));
+
+ $this->assertSame($this->parent, $property->getValue($this->class));
+
+ $href_property = $this->reflection->getProperty('href');
+ $href_property->setAccessible(TRUE);
+ $this->assertSame('something', $href_property->getValue($this->class));
+ }
+
/**
* Test basic parse functions
*/
diff --git a/src/PHPDraft/Model/Transition.php b/src/PHPDraft/Model/Transition.php
index 05cff545..43d7fd08 100644
--- a/src/PHPDraft/Model/Transition.php
+++ b/src/PHPDraft/Model/Transition.php
@@ -87,6 +87,7 @@ function parse($object)
$this->href = (isset($object->attributes->href)) ? $object->attributes->href : $this->parent->href;
+
if (isset($object->attributes->hrefVariables)) {
$deps = [];
diff --git a/src/PHPDraft/Out/HTML/material.css b/src/PHPDraft/Out/HTML/material.css
index 0e875ec8..5e8c7033 100644
--- a/src/PHPDraft/Out/HTML/material.css
+++ b/src/PHPDraft/Out/HTML/material.css
@@ -27,6 +27,11 @@ h2.mdl-card__title-text {
display: inline-block;
width: 100%;
}
+li.mdl-list__ite code{
+ font-size: 12px;
+ font-weight: normal;
+}
+
.page-content {
width: 80%;
margin: 0px auto;
@@ -52,7 +57,82 @@ table.table p {
margin-bottom: 0px;
}
+div .mdl-card__supporting-text table {
+ width: 100%;
+ max-width: 100%;
+ border: 0px solid #000000;
+}
+
+div .mdl-card__supporting-text {
+ width: 96%;
+ padding: 2%;
+}
+
+.mdl-card__supporting-text .list-group-item.mdl-list__item{
+ padding: 8px;
+ width: 100%;
+ clear: both;
+ display: block;
+ text-align: end;
+ font-size: 13px;
+ border-bottom: 1px solid #cccccc;
+ line-height: 31px;
+}
+
+.mdl-card__supporting-text .list-group-item.mdl-list__item:last-of-type{
+ border-bottom: 0px solid #cccccc;
+}
+
.showSearch {
background: #122b40 center / cover;
color: #cccccc;
+}
+
+dialog {
+ position: absolute;
+ right: 100%;
+ width: 1000px !important;
+ height: -moz-fit-content;
+ height: -webkit-fit-content;
+ height: fit-content;
+ margin: auto;
+ margin-left: -400px;
+ border: solid;
+ padding: 1em;
+ background: white;
+ color: black;
+ display: block;
+}
+
+dialog textarea {
+ width: 100%;
+ max-width: 100%;
+ line-break: strict;
+ word-break: break-all;
+ border-color: #cccccc;
+ height: 100%;
+}
+dialog .mdl-textfield {
+ width: 100%;
+}
+
+dialog:not([open]) {
+ display: none;
+}
+
+dialog + .backdrop {
+ position: fixed;
+ top: 0; right: 0; bottom: 0; left: 0;
+ background: rgba(0,0,0,0.1);
+}
+
+._dialog_overlay {
+ position: fixed;
+ top: 0; right: 0; bottom: 0; left: 0;
+}
+
+dialog.fixed {
+ position: fixed;
+ top: 50%;
+ transform: translate(0, -50%);
}
\ No newline at end of file
diff --git a/src/PHPDraft/Out/HTML/material.js b/src/PHPDraft/Out/HTML/material.js
index 431e3fba..5f0b24d1 100644
--- a/src/PHPDraft/Out/HTML/material.js
+++ b/src/PHPDraft/Out/HTML/material.js
@@ -1,3 +1,3 @@
/**
* Created by smillernl on 18-5-17.
- */
\ No newline at end of file
+ */
diff --git a/src/PHPDraft/Out/HTML/material.phtml b/src/PHPDraft/Out/HTML/material.phtml
index e05d9aa8..87329730 100644
--- a/src/PHPDraft/Out/HTML/material.phtml
+++ b/src/PHPDraft/Out/HTML/material.phtml
@@ -13,8 +13,11 @@ use PHPDraft\Out\Minifier;
= $this->base_data['TITLE']; ?>
-
+
+
css as $style): ?>
@@ -53,7 +56,7 @@ use PHPDraft\Out\Minifier;
base_structures)): ?>
Objects
base_structures as $key => $structure): ?>
- = $key; ?>
+ = $key; ?>
@@ -187,12 +190,29 @@ use PHPDraft\Out\Minifier;
@@ -233,9 +253,6 @@ if (!empty($extras)):
js as $js): ?>
-