Skip to content

Commit a8c1f63

Browse files
committed
Allow body in other calls then PUT/POST
Issue GH-77
1 parent d40d31d commit a8c1f63

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.idea/
2+
/.phpintel/
23

34
# IntelliJ
45
/build/coverage
@@ -16,4 +17,4 @@ composer.lock
1617
# JIRA plugin
1718
atlassian-ide-plugin.xml
1819

19-
*.pem
20+
*.pem

src/PHPDraft/Model/Elements/BasicStructureElement.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,17 @@ protected function parse_common(stdClass $object, array &$dependencies): void
9393
$this->key = $object->content->key->content ?? NULL;
9494
$this->type = $object->content->value->element ?? NULL;
9595
$this->description = NULL;
96-
if (isset($object->meta->description->content)){
96+
if (isset($object->meta->description->content)) {
9797
$this->description = htmlentities($object->meta->description->content);
9898
} elseif (isset($object->meta->description)) {
9999
$this->description = htmlentities($object->meta->description);
100100
}
101101

102102
$this->status = NULL;
103-
if (isset($object->attributes->typeAttributes->content)){
104-
$data = array_map(function ($item) { return $item->content; }, $object->attributes->typeAttributes->content);
103+
if (isset($object->attributes->typeAttributes->content)) {
104+
$data = array_map(function ($item) {
105+
return $item->content;
106+
}, $object->attributes->typeAttributes->content);
105107
$this->status = join(', ', $data);
106108
} elseif (isset($object->attributes->typeAttributes)) {
107109
$this->status = join(', ', $object->attributes->typeAttributes);

src/PHPDraft/Model/HTTPRequest.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ class HTTPRequest implements Comparable
5353
public $parent;
5454

5555
/**
56-
* Body of the request (if POST or PUT).
56+
* Body of the request.
5757
*
5858
* @var mixed
5959
*/
60-
public $body = null;
60+
public $body = NULL;
6161

6262
/**
63-
* Schema of the body of the request (if POST or PUT).
63+
* Schema of the body of the request.
6464
*
6565
* @var mixed
6666
*/
67-
public $body_schema = null;
67+
public $body_schema = NULL;
6868
/**
69-
* Structure of the request (if POST or PUT).
69+
* Structure of the request.
7070
*
7171
* @var RequestBodyElement
7272
*/
@@ -99,9 +99,9 @@ public function __construct(Transition &$parent)
9999
public function parse(stdClass $object): self
100100
{
101101
$this->method = $object->attributes->method->content ?? $object->attributes->method;
102-
$this->title = isset($object->meta->title) ? $object->meta->title : null;
102+
$this->title = isset($object->meta->title) ? $object->meta->title : NULL;
103103

104-
if (($this->method === 'POST' || $this->method === 'PUT') && !empty($object->content)) {
104+
if (!empty($object->content)) {
105105
foreach ($object->content as $value) {
106106
if ($value->element === 'dataStructure') {
107107
$this->parse_structure($value);
@@ -117,20 +117,20 @@ public function parse(stdClass $object): self
117117
continue;
118118
}
119119
if (is_array($value->meta->classes) && in_array('messageBody', $value->meta->classes)) {
120-
$this->body[] = (isset($value->content)) ? $value->content : null;
120+
$this->body[] = (isset($value->content)) ? $value->content : NULL;
121121
$this->headers['Content-Type'] = (isset($value->attributes->contentType)) ? $value->attributes->contentType : '';
122122
continue;
123123
}
124124

125125
if (isset($value->meta->classes->content)
126126
&& is_array($value->meta->classes->content)
127127
&& $value->meta->classes->content[0]->content === 'messageBody') {
128-
$this->body[] = (isset($value->content)) ? $value->content : null;
128+
$this->body[] = (isset($value->content)) ? $value->content : NULL;
129129
$this->headers['Content-Type'] = (isset($value->attributes->contentType->content)) ? $value->attributes->contentType->content : '';
130130
} elseif (isset($value->meta->classes->content)
131131
&& is_array($value->meta->classes->content)
132132
&& $value->meta->classes->content[0]->content === 'messageBodySchema') {
133-
$this->body_schema = (isset($value->content)) ? $value->content : null;
133+
$this->body_schema = (isset($value->content)) ? $value->content : NULL;
134134
}
135135
}
136136
}
@@ -141,7 +141,7 @@ public function parse(stdClass $object): self
141141
}
142142
}
143143

144-
if ($this->body === null) {
144+
if ($this->body === NULL) {
145145
$this->body = &$this->struct;
146146
}
147147

@@ -174,15 +174,15 @@ public function get_id(): string
174174
* @param string $base_url URL to the base server
175175
* @param array $additional Extra options to pass to cURL
176176
*
177-
* @return string An executable cURL command
178177
* @throws Exception
179178
*
179+
* @return string An executable cURL command
180180
*/
181181
public function get_curl_command(string $base_url, array $additional = []): string
182182
{
183183
$options = [];
184184

185-
$type = $this->headers['Content-Type'] ?? null;
185+
$type = $this->headers['Content-Type'] ?? NULL;
186186

187187
$options[] = '-X' . $this->method;
188188
if (empty($this->body)) {
@@ -205,7 +205,7 @@ public function get_curl_command(string $base_url, array $additional = []): stri
205205
$options = array_merge($options, $additional);
206206

207207
return htmlspecialchars('curl ' . join(' ', $options) . ' ' . escapeshellarg($this->parent->build_url($base_url,
208-
true)));
208+
TRUE)));
209209
}
210210

211211
/**
@@ -226,17 +226,17 @@ public function is_equal_to($b): bool
226226
* @param string $base_url URL to the base server
227227
* @param array $additional Extra options to pass to the service
228228
*
229-
* @return string
230229
* @throws Exception
231230
*
231+
* @return string
232232
*/
233233
public function get_hurl_link(string $base_url, array $additional = []): string
234234
{
235235
$options = [];
236236

237-
$type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : null;
237+
$type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : NULL;
238238

239-
$url = $this->parent->build_url($base_url, true);
239+
$url = $this->parent->build_url($base_url, TRUE);
240240
$url = explode('?', $url);
241241
if (isset($url[1])) {
242242
$params = [];

src/PHPDraft/Out/BaseTemplateGenerator.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace PHPDraft\Out;
1111

12-
1312
use Lukasoppermann\Httpstatus\Httpstatus;
1413
use PHPDraft\Model\Elements\ObjectStructureElement;
1514

@@ -50,7 +49,7 @@ abstract class BaseTemplateGenerator
5049
*
5150
* @var string
5251
*/
53-
protected $image = null;
52+
protected $image = NULL;
5453
/**
5554
* The base URl of the API.
5655
*
@@ -69,4 +68,4 @@ abstract class BaseTemplateGenerator
6968
* @var ObjectStructureElement[]
7069
*/
7170
protected $base_structures = [];
72-
}
71+
}

src/PHPDraft/Out/LegacyTemplateGenerator.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Lukasoppermann\Httpstatus\Httpstatus;
1313
use Michelf\MarkdownExtra;
1414
use PHPDraft\Model\Category;
15-
use PHPDraft\Model\Elements\ObjectStructureElement;
1615
use PHPDraft\Parse\ExecutionException;
1716

1817
class LegacyTemplateGenerator extends BaseTemplateGenerator

src/PHPDraft/Parse/BaseHtmlGenerator.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHPDraft\Parse;
1111

12-
1312
use PHPDraft\Out\BaseTemplateGenerator;
14-
use PHPDraft\Out\TemplateGenerator;
1513
use stdClass;
1614

1715
abstract class BaseHtmlGenerator
@@ -38,6 +36,7 @@ abstract class BaseHtmlGenerator
3836
public function init(stdClass $json): self
3937
{
4038
$this->object = $json;
39+
4140
return $this;
4241
}
4342

@@ -53,5 +52,5 @@ public function __toString()
5352
return $this->get_html();
5453
}
5554

56-
public abstract function get_html(string $template = 'default', ?string $image = NULL, ?string $css = NULL, ?string $js = NULL): BaseTemplateGenerator;
57-
}
55+
abstract public function get_html(string $template = 'default', ?string $image = NULL, ?string $css = NULL, ?string $js = NULL): BaseTemplateGenerator;
56+
}

0 commit comments

Comments
 (0)