Skip to content

Commit 3fa9dbb

Browse files
committed
Fix requests being allowed more than once
1 parent 5f6463f commit 3fa9dbb

File tree

11 files changed

+2631
-2111
lines changed

11 files changed

+2631
-2111
lines changed

src/PHPDraft/Model/HTTPRequest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class HTTPRequest implements Comparable
2929
*/
3030
public $method;
3131

32+
/**
33+
* Title of the request.
34+
*
35+
* @var string
36+
*/
37+
public $title;
38+
3239
/**
3340
* Description of the request.
3441
*
@@ -49,6 +56,14 @@ class HTTPRequest implements Comparable
4956
* @var mixed
5057
*/
5158
public $body = NULL;
59+
60+
/**
61+
* Identifier for the request
62+
*
63+
* @var string
64+
*/
65+
protected $id;
66+
5267
/**
5368
* Structure of the request (if POST or PUT).
5469
*
@@ -75,7 +90,9 @@ public function __construct(&$parent)
7590
*/
7691
public function parse($object)
7792
{
93+
$this->id = md5(microtime());
7894
$this->method = $object->attributes->method;
95+
$this->title = isset($object->meta->title) ? $object->meta->title : NULL;
7996

8097
if (($this->method === 'POST' || $this->method === 'PUT') && !empty($object->content)) {
8198
foreach ($object->content as $value) {
@@ -122,6 +139,11 @@ private function parse_structure($objects)
122139
$this->struct = $struct;
123140
}
124141

142+
public function get_id()
143+
{
144+
return $this->id;
145+
}
146+
125147
/**
126148
* Generate a cURL command for the HTTP request.
127149
*

src/PHPDraft/Model/HTTPResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class HTTPResponse implements Comparable
2828
*/
2929
public $description;
3030

31+
/**
32+
* Identifier for the request
33+
*
34+
* @var string
35+
*/
36+
protected $id;
37+
3138
/**
3239
* Response headers.
3340
*
@@ -58,6 +65,7 @@ class HTTPResponse implements Comparable
5865

5966
public function __construct($parent)
6067
{
68+
$this->id = md5(microtime());
6169
$this->parent = &$parent;
6270
}
6371

@@ -82,6 +90,11 @@ public function parse($object)
8290
return $this;
8391
}
8492

93+
public function get_id()
94+
{
95+
return $this->id;
96+
}
97+
8598
/**
8699
* Parse request headers.
87100
*

src/PHPDraft/Model/Transition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public function parse($object)
152152
* @param bool $clean Get the URL without HTML
153153
*
154154
* @return string a HTML representation of the transition URL
155+
* @throws \QL\UriTemplate\Exception
155156
*/
156157
public function build_url($base_url = '', $clean = FALSE)
157158
{

src/PHPDraft/Out/HTML/default.css

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ div.main-url {
1212
line-break: loose;
1313
word-break: break-all;
1414
}
15-
button.extra-info.btn{
15+
16+
button.extra-info.btn {
1617
position: fixed;
1718
bottom: 10px;
1819
left: 10px;
1920
border-radius: 30px;
2021
}
22+
2123
button.extra-info.btn:focus {
2224
border-width: 0px;
2325
box-shadow: none;
2426
outline: 0;
2527
}
28+
2629
.request-card > code, .popover-content {
2730
word-break: break-all;
2831
}
@@ -31,7 +34,8 @@ body .media h1.media-heading {
3134
margin-top: 20px;
3235
margin-bottom: 10px;
3336
}
34-
body .media h1.media-heading .form-control{
37+
38+
body .media h1.media-heading .form-control {
3539
display: flex;
3640
width: auto;
3741
float: right;
@@ -95,22 +99,6 @@ body .col-md-10 h3:first-child {
9599
line-height: 22px;
96100
}
97101

98-
.POST:not(.structure) > .card-header, span.POST {
99-
background: #62c462;
100-
}
101-
102-
.GET:not(.structure) > .card-header, span.GET {
103-
background: #5bc0de;
104-
}
105-
106-
.DELETE:not(.structure) > .card-header, span.DELETE {
107-
background: #ee5f5b;
108-
}
109-
110-
.PUT:not(.structure) > .card-header, span.PUT {
111-
background: #f89406;
112-
}
113-
114102
.example-value {
115103
color: rgba(0, 0, 0, 0.4);
116104
text-align: right;
@@ -145,17 +133,66 @@ a.code {
145133
position: absolute;
146134
top: 15px;
147135
}
136+
148137
.curl.btn {
149138
right: 15px;
150139
border-top-left-radius: 0px;
151140
border-bottom-left-radius: 0px
152141
}
142+
153143
.hurl.btn {
154144
right: 54px;
155145
border-top-right-radius: 0px;
156146
border-bottom-right-radius: 0px
157147
}
158148

159-
/*h5.response-body, h4.request {
160-
cursor: pointer;
161-
}*/
149+
body {
150+
--put-color: rgb(248, 148, 6);
151+
--post-color: rgb(98, 196, 98);
152+
--get-color: rgb(91, 192, 222);
153+
--delete-color: rgb(238, 95, 91);
154+
--head-color: rgb(222, 121, 91);
155+
--patch-color: rgb(196, 98, 196);
156+
}
157+
158+
.PUT:not(.structure) > .card-header{
159+
background: var(--put-color);
160+
}
161+
span.PUT {
162+
color: var(--put-color);
163+
}
164+
165+
.POST:not(.structure) > .card-header{
166+
background: var(--post-color);
167+
}
168+
span.POST {
169+
color: var(--post-color);
170+
}
171+
172+
.GET:not(.structure) > .card-header{
173+
background: var(--get-color);
174+
}
175+
span.GET {
176+
color: var(--get-color);
177+
}
178+
179+
.DELETE:not(.structure) > .card-header{
180+
background: var(--delete-color);
181+
}
182+
span.DELETE {
183+
color: var(--delete-color);
184+
}
185+
186+
.HEAD:not(.structure) > .card-header{
187+
background: var(--head-color);
188+
}
189+
span.HEAD {
190+
color: var(--head-color);
191+
}
192+
193+
.PATCH:not(.structure) > .card-header{
194+
background: var(--patch-color);
195+
}
196+
span.PATCH {
197+
color: var(--patch-color);
198+
}

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,45 @@ use Enjoy\HttpStatusCode\Statuscodes;
146146
</h5>
147147
</div>
148148
<div class="card-body">
149-
<a class="btn btn-default curl"
150-
role="button"
151-
title="cURL command"
152-
tabindex="0"
153-
data-placement="left"
154-
data-toggle="popover"
155-
data-html="true"
156-
data-content="<textarea rows='8' cols='75'><?= $transition->get_curl_command($this->base_data['HOST']); ?></textarea>">
157-
<i class="fas fa-copy"></i>
158-
</a>
159-
<?php if (THIRD_PARTY_ALLOWED): ?>
160-
<a class="btn btn-default hurl"
161-
role="button"
162-
title="Try request"
163-
target="_blank"
164-
href="<?= $transition->get_hurl_link($this->base_data['HOST']); ?>"
165-
tabindex="0">
166-
<i class="fas fa-play"></i>
167-
</a>
168-
<?php endif;?>
169149
<p class="lead"><?= $transition->description; ?></p>
170150
<?php if (!empty($transition->requests)): ?>
171151
<?php foreach ($transition->requests as $key => $request): ?>
172152
<div class="card">
173153
<div class="card-header">
174154
<h6 class="request card-title"
175155
data-toggle="collapse"
176-
data-target="#request-coll-<?= $transition->get_href(); ?>">Request
156+
data-target="#request-coll-<?= $request->get_id(); ?>">Request
157+
<?php if (!empty($request->title)): ?>
158+
<var><?= $request->title;?></var>
159+
<?php endif;?>
177160
<i class="fas indicator fa-angle-down float-right"></i>
178161
</h6>
179162
</div>
180163

181164
<div
182165
class="collapse <?php if ($key < 1): ?>show<?php endif; ?> request-card card-body"
183-
id="request-coll-<?= $transition->get_href(); ?>">
166+
id="request-coll-<?= $request->get_id(); ?>">
184167
<?= $request->description; ?>
168+
<a class="btn btn-default curl"
169+
role="button"
170+
title="cURL command"
171+
tabindex="0"
172+
data-placement="left"
173+
data-toggle="popover"
174+
data-html="true"
175+
data-content="<textarea rows='8' cols='75'><?= $transition->get_curl_command($this->base_data['HOST']); ?></textarea>">
176+
<i class="fas fa-copy"></i>
177+
</a>
178+
<?php if (THIRD_PARTY_ALLOWED): ?>
179+
<a class="btn btn-default hurl"
180+
role="button"
181+
title="Try request"
182+
target="_blank"
183+
href="<?= $transition->get_hurl_link($this->base_data['HOST']); ?>"
184+
tabindex="0">
185+
<i class="fas fa-play"></i>
186+
</a>
187+
<?php endif;?>
185188
<?php if ($transition->url_variables !== []): ?>
186189
<h5>Example URI</h5>
187190
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
@@ -274,19 +277,19 @@ use Enjoy\HttpStatusCode\Statuscodes;
274277
<?php foreach ($response->content as $key => $value): ?>
275278
<div>
276279
<?php $href =
277-
$transition->get_href() . '-' . $response->statuscode . '-' . str_replace([
280+
$response->get_id() . '-' . $response->statuscode . '-' . str_replace([
278281
'/',
279282
'+',
280283
], '-', $key); ?>
281284
<h5 class="response-body"
282285
data-toggle="collapse"
283-
data-target="#request-<?= $href ?>">
286+
data-target="#response-<?= $href ?>">
284287
<i class="fas indicator fa-angle-up"></i>
285288
<?= $key; ?>
286289

287290
</h5>
288291
<pre class="collapse response-body"
289-
id="request-<?= $href ?>"><?= $value; ?></pre>
292+
id="response-<?= $href ?>"><?= $value; ?></pre>
290293
</div>
291294
<?php endforeach; ?>
292295
</div>

src/PHPDraft/Out/HTML/material.css

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.demo-layout-transparent {
1+
.phpdrafter-layout-transparent {
22
background: rgba(0,0,0,0) center / cover;
33
}
4-
.demo-layout-transparent .mdl-layout__header,
5-
.demo-layout-transparent .mdl-layout__drawer-button {
4+
.phpdrafter-layout-transparent .mdl-layout__header,
5+
.phpdrafter-layout-transparent .mdl-layout__drawer-button {
66
/* This background is dark, so we set text to white. Use 87% black instead if
77
your background is light. */
88
color: white;
@@ -11,16 +11,16 @@ main {
1111
width: 100%;
1212
}
1313

14-
.demo-card-wide.mdl-card {
14+
.phpdrafter-card-wide.mdl-card {
1515
width: 100%;
1616
margin-bottom: 30px;
1717
}
18-
.demo-card-wide > .mdl-card__title {
18+
.phpdrafter-card-wide > .mdl-card__title {
1919
color: #fff;
2020
height: 176px;
2121
background: #cccccc center / cover;
2222
}
23-
.demo-card-wide > .mdl-card__menu {
23+
.phpdrafter-card-wide > .mdl-card__menu {
2424
color: #fff;
2525
}
2626
h2.mdl-card__title-text {
@@ -89,14 +89,11 @@ div .mdl-card__supporting-text {
8989
}
9090

9191
dialog {
92-
position: absolute;
93-
right: 100%;
9492
width: 1000px !important;
9593
height: -moz-fit-content;
9694
height: -webkit-fit-content;
9795
height: fit-content;
9896
margin: auto;
99-
margin-left: -400px;
10097
border: solid;
10198
padding: 1em;
10299
background: white;
@@ -135,4 +132,36 @@ dialog.fixed {
135132
position: fixed;
136133
top: 50%;
137134
transform: translate(0, -50%);
135+
}
136+
137+
body {
138+
--put-color: rgb(248, 148, 6);
139+
--post-color: rgb(98, 196, 98);
140+
--get-color: rgb(91, 192, 222);
141+
--delete-color: rgb(238, 95, 91);
142+
--head-color: rgb(222, 121, 91);
143+
--patch-color: rgb(196, 98, 196);
144+
}
145+
146+
.mdl-card__title a {
147+
color: inherit;
148+
}
149+
150+
.PUT .mdl-card__title {
151+
background: var(--put-color);
152+
}
153+
.POST .mdl-card__title {
154+
background: var(--post-color);
155+
}
156+
.GET .mdl-card__title {
157+
background: var(--get-color);
158+
}
159+
.DELETE .mdl-card__title {
160+
background: var(--delete-color);
161+
}
162+
.HEAD .mdl-card__title {
163+
background: var(--head-color);
164+
}
165+
.PATCH .mdl-card__title {
166+
background: var(--patch-color);
138167
}

0 commit comments

Comments
 (0)