Skip to content

Commit 55989ac

Browse files
committed
Fix #133
1 parent e6ba581 commit 55989ac

File tree

11 files changed

+844
-390
lines changed

11 files changed

+844
-390
lines changed

phpdraft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use PHPDraft\Parse\ParserFactory;
1919
use PHPDraft\Parse\ResourceException;
2020

2121
define('VERSION', '0');
22-
#define('ID_STATIC', 'SOME_ID');
22+
//define('ID_STATIC', 'SOME_ID');
2323
try
2424
{
2525
// Define the cli options.

src/PHPDraft/Model/Resource.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Resource extends HierarchyElement
2727
/**
2828
* URL variables.
2929
*
30-
* @var ObjectStructureElement|null
30+
* @var ObjectStructureElement[]
3131
*/
32-
public $url_variables = null;
32+
public $url_variables = [];
3333

3434
/**
3535
* Resource constructor.
@@ -58,8 +58,10 @@ public function parse(stdClass $object): self
5858

5959
if (isset($object->attributes->hrefVariables)) {
6060
$deps = [];
61-
$struct = new ObjectStructureElement();
62-
$this->url_variables = $struct->parse($object->attributes->hrefVariables, $deps);
61+
foreach ($object->attributes->hrefVariables->content as $variable) {
62+
$struct = new ObjectStructureElement();
63+
$this->url_variables[] = $struct->parse($variable, $deps);
64+
}
6365
}
6466

6567
foreach ($object->content as $item) {

src/PHPDraft/Model/Tests/TransitionTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testParseIsCalledIssetHrefVariables(): void
7171
{
7272
$this->set_reflection_property_value('parent', $this->parent);
7373

74-
$json = '{"attributes":{"href":"something", "hrefVariables":{"hello":"world"}}, "content":[]}';
74+
$json = '{"attributes":{"href":"something", "hrefVariables":{"content": [{"element": "member", "hello":"world"}]}}, "content":[]}';
7575
$obj = json_decode($json);
7676
$this->class->parse($obj);
7777

@@ -86,7 +86,7 @@ public function testParseIsCalledIssetData(): void
8686
{
8787
$this->set_reflection_property_value('parent', $this->parent);
8888

89-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[]}';
89+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[]}';
9090

9191
$this->class->parse(json_decode($obj));
9292

@@ -101,7 +101,7 @@ public function testParseIsCalledIsNotArrayContent(): void
101101
{
102102
$this->set_reflection_property_value('parent', $this->parent);
103103

104-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":""}';
104+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":""}';
105105

106106
$this->class->parse(json_decode($obj));
107107

@@ -116,7 +116,7 @@ public function testParseIsCalledIsArrayContentNoChild(): void
116116
{
117117
$this->set_reflection_property_value('parent', $this->parent);
118118

119-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":{}}]}';
119+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":{}}]}';
120120

121121
$this->class->parse(json_decode($obj));
122122

@@ -131,7 +131,7 @@ public function testParseIsCalledIsArrayContentWrongChild(): void
131131
{
132132
$this->set_reflection_property_value('parent', $this->parent);
133133

134-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"test"}]}]}';
134+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"test"}]}]}';
135135

136136
$this->class->parse(json_decode($obj));
137137

@@ -146,7 +146,7 @@ public function testParseIsCalledIsArrayContentRequest(): void
146146
{
147147
$this->set_reflection_property_value('parent', $this->parent);
148148

149-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpRequest", "attributes":{"method":"TEST"}, "content":{}}]}]}';
149+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpRequest", "attributes":{"method":"TEST"}, "content":{}}]}]}';
150150

151151
$this->class->parse(json_decode($obj));
152152

@@ -161,7 +161,7 @@ public function testParseIsCalledIsArrayContentResponse(): void
161161
{
162162
$this->set_reflection_property_value('parent', $this->parent);
163163

164-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpResponse", "content":[], "attributes":{"statusCode":"1000", "headers":{"content":[]}}}]}]}';
164+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpResponse", "content":[], "attributes":{"statusCode":"1000", "headers":{"content":[]}}}]}]}';
165165

166166
$this->class->parse(json_decode($obj));
167167

@@ -176,7 +176,7 @@ public function testParseIsCalledIsArrayContentDefault(): void
176176
{
177177
$this->set_reflection_property_value('parent', $this->parent);
178178

179-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"Cow", "content":[], "attributes":{"statusCode":"1000", "headers":{"content":[]}}}]}]}';
179+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"Cow", "content":[], "attributes":{"statusCode":"1000", "headers":{"content":[]}}}]}]}';
180180

181181
$this->class->parse(json_decode($obj));
182182

@@ -202,7 +202,7 @@ public function testParseIsCalledIsArrayContentRequestList(): void
202202
$req_property->setAccessible(true);
203203
$req_property->setValue($this->class, $requests);
204204

205-
$obj = '{"attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpRequest", "attributes":{"method":"TEST"}}]}]}';
205+
$obj = '{"element": "dataStructure", "attributes":{"href":"something", "data":{"content":{"hello":"world"}}}, "content":[{"element":"123", "content":[{"element":"httpRequest", "attributes":{"method":"TEST"}}]}]}';
206206

207207
$this->class->parse(json_decode($obj));
208208

@@ -375,12 +375,9 @@ public function testBuildURLVars(): void
375375
->will($this->returnValue('STRING'));
376376
$var1->key = $key1;
377377

378-
$vars = new \stdClass();
379-
$vars->value = [ $var1 ];
380-
381378
$property = $this->reflection->getProperty('url_variables');
382379
$property->setAccessible(true);
383-
$property->setValue($this->class, $vars);
380+
$property->setValue($this->class, [$var1]);
384381

385382
$req_property = $this->reflection->getProperty('href');
386383
$req_property->setAccessible(true);

src/PHPDraft/Model/Transition.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class Transition extends HierarchyElement
3737
/**
3838
* URL variables.
3939
*
40-
* @var ObjectStructureElement|null
40+
* @var StructureElement[]
4141
*/
42-
public $url_variables = null;
42+
public $url_variables = [];
4343

4444
/**
4545
* Data variables.
4646
*
47-
* @var array|StructureElement|null
47+
* @var StructureElement|null
4848
*/
4949
public $data_variables = null;
5050

@@ -65,7 +65,7 @@ class Transition extends HierarchyElement
6565
/**
6666
* Structures used (if any).
6767
*
68-
* @var ObjectStructureElement[]
68+
* @var StructureElement[]
6969
*/
7070
public $structures = [];
7171

@@ -74,7 +74,7 @@ class Transition extends HierarchyElement
7474
*
7575
* @param \PHPDraft\Model\Resource $parent A reference to the parent object
7676
*/
77-
public function __construct(Resource &$parent)
77+
public function __construct(\PHPDraft\Model\Resource &$parent)
7878
{
7979
$this->parent = $parent;
8080
}
@@ -95,13 +95,15 @@ public function parse(stdClass $object): self
9595

9696
if (isset($object->attributes->hrefVariables)) {
9797
$deps = [];
98-
$struct = new ObjectStructureElement();
99-
$this->url_variables = $struct->parse($object->attributes->hrefVariables, $deps);
98+
foreach ($object->attributes->hrefVariables->content as $variable) {
99+
$struct = (new ObjectStructureElement())->get_class($variable->element);
100+
$this->url_variables[] = $struct->parse($variable, $deps);
101+
}
100102
}
101103

102104
if (isset($object->attributes->data)) {
103105
$deps = [];
104-
$struct = new ObjectStructureElement();
106+
$struct = (new ObjectStructureElement())->get_class($object->element);
105107
$this->data_variables = $struct->parse($object->attributes->data->content, $deps);
106108
}
107109

@@ -169,23 +171,23 @@ public function build_url(string $base_url = '', bool $clean = false): string
169171
}
170172
$tpl = new UriTemplate($url);
171173
$vars = [];
172-
if ($this->url_variables !== null) {
173-
foreach ($this->url_variables->value as $item) {
174-
$urlvalue = $item->value;
175-
if (is_subclass_of($item, BasicStructureElement::class)) {
176-
$urlvalue = $item->string_value();
174+
if ($this->url_variables !== []) {
175+
foreach ($this->url_variables as $item) {
176+
if (!is_subclass_of($item, BasicStructureElement::class)) {
177+
continue;
177178
}
178179

180+
$urlvalue = $item->string_value();
179181
$vars[$item->key->value] = $urlvalue;
180182
}
181183
}
182-
if ($this->parent->url_variables !== null) {
183-
foreach ($this->parent->url_variables->value as $item) {
184-
$urlvalue = $item->value;
185-
if (is_subclass_of($item, BasicStructureElement::class)) {
186-
$urlvalue = $item->string_value(true);
184+
if ($this->parent->url_variables !== []) {
185+
foreach ($this->parent->url_variables as $item) {
186+
if (!is_subclass_of($item, BasicStructureElement::class)) {
187+
continue;
187188
}
188189

190+
$urlvalue = $item->string_value();
189191
$vars[$item->key->value] = $urlvalue;
190192
}
191193
}

src/PHPDraft/Out/HTML/default.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
$(function () {
2-
$('[data-toggle="popover"]').popover();
2+
$('[data-toggle="popover"]').popover({
3+
html: true,
4+
sanitize: false,
5+
});
36
$('[data-toggle="tooltip"]').tooltip();
47
$('body').on('click', function (e) {
58
$('[data-toggle="popover"]').each(function () {

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use PHPDraft\Out\Minifier;
1212
<title><?= $this->base_data['TITLE']; ?></title>
1313
<meta charset="utf-8">
1414
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
15-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
15+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
1616
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css" integrity="sha384-Bfad6CLCknfcloXFOyFnlgtENryhrpZCe29RTifKEixXQZ38WheV+i/6YWSzkz3V" crossorigin="anonymous">
1717
<?php foreach ($this->css as $style): ?><link rel="stylesheet" href="<?= $style ?>"><?php endforeach; ?>
1818
<style><?= Minifier::minify_css(file_get_contents($this->find_include_file($this->template, 'css'), true));?></style>
@@ -69,7 +69,7 @@ use PHPDraft\Out\Minifier;
6969
<?php endforeach; ?>
7070
<?php if ($this->base_structures !== []): ?>
7171
<nav id="nav-datastructures" class="navbar navbar-light structures" aria-label="Data structures">
72-
<a class="navbar-brand" href="#<?= $category->get_href(); ?>">Data Structures</a>
72+
<a class="navbar-brand" href="#data-structures">Data Structures</a>
7373
<?php foreach ($this->base_structures as $key => $structure): ?>
7474
<nav class="nav nav-pills flex-column structure" aria-label="Structure <?= $key?>">
7575
<a class="nav-link" href="#object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
@@ -104,7 +104,14 @@ use PHPDraft\Out\Minifier;
104104
<?php if ($resource->url_variables !== null): ?>
105105
<h5>URI Parameters</h5>
106106
<div class="row">
107-
<?= $resource->url_variables; ?>
107+
<table class="table table-striped mdl-data-table mdl-js-data-table ">
108+
<thead><tr><td>key</td><td>type</td><td>status</td><td>description</td><td>value</td></tr></thead>
109+
<tbody>
110+
<?php foreach ($resource->url_variables as $url_variable): ?>
111+
<?= $url_variable; ?>
112+
<?php endforeach;?>
113+
</tbody>
114+
</table>
108115
</div>
109116
<?php endif; ?>
110117
<?php foreach ($resource->children as $transition): ?>
@@ -152,10 +159,8 @@ use PHPDraft\Out\Minifier;
152159
data-content="<textarea rows='8' cols='75'><?= $transition->get_curl_command($this->base_data['HOST']); ?></textarea>">
153160
<span class="fas fa-copy"></span>
154161
</a>
155-
<?php if ($transition->url_variables !== []): ?>
156-
<h5>Example URI</h5>
157-
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
158-
<?php endif; ?>
162+
<h5>Example URI</h5>
163+
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
159164
<?php if ($request->headers !== []): ?>
160165
<h5>Headers</h5>
161166
<ul class="headers list-unstyled">
@@ -188,10 +193,17 @@ use PHPDraft\Out\Minifier;
188193
</div>
189194
<?php endif; ?>
190195

191-
<?php if ($transition->url_variables !== null): ?>
196+
<?php if ($transition->url_variables !== []): ?>
192197
<h5>URI Parameters</h5>
193198
<div class="row">
194-
<?= $transition->url_variables; ?>
199+
<table class="table table-striped mdl-data-table mdl-js-data-table ">
200+
<thead><tr><td>key</td><td>type</td><td>status</td><td>description</td><td>value</td></tr></thead>
201+
<tbody>
202+
<?php foreach ($transition->url_variables as $url_variable): ?>
203+
<?= $url_variable; ?>
204+
<?php endforeach;?>
205+
</tbody>
206+
</table>
195207
</div>
196208
<?php endif; ?>
197209

@@ -248,6 +260,9 @@ use PHPDraft\Out\Minifier;
248260
$response->get_id() . '-' . $response->statuscode . '-' . str_replace([
249261
'/',
250262
'+',
263+
'; ',
264+
';',
265+
'=',
251266
], '-', $response_key); ?>
252267
<h5 class="response-body"
253268
data-toggle="collapse"
@@ -310,10 +325,11 @@ if ($extras !== []):
310325
<?php foreach ($this->js as $js): ?>
311326
<script src="<?= $js ?>"></script>
312327
<?php endforeach; ?>
313-
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
314-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha256-/ijcOLwFf26xEYAjW75FizKVo5tnTYiQddPZoLUHHZ8=" crossorigin="anonymous"></script>
328+
<!-- JS, Popper.js, and jQuery -->
329+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
315330
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.2.2/anchor.min.js" integrity="sha256-E4RlfxwyJVmkkk0szw7LYJxuPlp6evtPSBDlWHsYYL8=" crossorigin="anonymous"></script>
316-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
331+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
332+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
317333
<script><?= Minifier::minify_js(file_get_contents($this->find_include_file($this->template, 'js'), true)); ?></script>
318334
</body>
319335
</html>

0 commit comments

Comments
 (0)