From a8c1f63f92c6b0deb34fd7e637aa5d547ab186b5 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sat, 16 Nov 2019 21:21:02 +0100 Subject: [PATCH] Allow body in other calls then PUT/POST Issue GH-77 --- .gitignore | 3 +- .../Model/Elements/BasicStructureElement.php | 8 +++-- src/PHPDraft/Model/HTTPRequest.php | 34 +++++++++---------- src/PHPDraft/Out/BaseTemplateGenerator.php | 5 ++- src/PHPDraft/Out/LegacyTemplateGenerator.php | 1 - src/PHPDraft/Parse/BaseHtmlGenerator.php | 7 ++-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index e94f2a88..debbc5b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ +/.phpintel/ # IntelliJ /build/coverage @@ -16,4 +17,4 @@ composer.lock # JIRA plugin atlassian-ide-plugin.xml -*.pem \ No newline at end of file +*.pem diff --git a/src/PHPDraft/Model/Elements/BasicStructureElement.php b/src/PHPDraft/Model/Elements/BasicStructureElement.php index 30766222..10291d6f 100644 --- a/src/PHPDraft/Model/Elements/BasicStructureElement.php +++ b/src/PHPDraft/Model/Elements/BasicStructureElement.php @@ -93,15 +93,17 @@ protected function parse_common(stdClass $object, array &$dependencies): void $this->key = $object->content->key->content ?? NULL; $this->type = $object->content->value->element ?? NULL; $this->description = NULL; - if (isset($object->meta->description->content)){ + if (isset($object->meta->description->content)) { $this->description = htmlentities($object->meta->description->content); } elseif (isset($object->meta->description)) { $this->description = htmlentities($object->meta->description); } $this->status = NULL; - if (isset($object->attributes->typeAttributes->content)){ - $data = array_map(function ($item) { return $item->content; }, $object->attributes->typeAttributes->content); + if (isset($object->attributes->typeAttributes->content)) { + $data = array_map(function ($item) { + return $item->content; + }, $object->attributes->typeAttributes->content); $this->status = join(', ', $data); } elseif (isset($object->attributes->typeAttributes)) { $this->status = join(', ', $object->attributes->typeAttributes); diff --git a/src/PHPDraft/Model/HTTPRequest.php b/src/PHPDraft/Model/HTTPRequest.php index ab726259..4712025e 100644 --- a/src/PHPDraft/Model/HTTPRequest.php +++ b/src/PHPDraft/Model/HTTPRequest.php @@ -53,20 +53,20 @@ class HTTPRequest implements Comparable public $parent; /** - * Body of the request (if POST or PUT). + * Body of the request. * * @var mixed */ - public $body = null; + public $body = NULL; /** - * Schema of the body of the request (if POST or PUT). + * Schema of the body of the request. * * @var mixed */ - public $body_schema = null; + public $body_schema = NULL; /** - * Structure of the request (if POST or PUT). + * Structure of the request. * * @var RequestBodyElement */ @@ -99,9 +99,9 @@ public function __construct(Transition &$parent) public function parse(stdClass $object): self { $this->method = $object->attributes->method->content ?? $object->attributes->method; - $this->title = isset($object->meta->title) ? $object->meta->title : null; + $this->title = isset($object->meta->title) ? $object->meta->title : NULL; - if (($this->method === 'POST' || $this->method === 'PUT') && !empty($object->content)) { + if (!empty($object->content)) { foreach ($object->content as $value) { if ($value->element === 'dataStructure') { $this->parse_structure($value); @@ -117,7 +117,7 @@ public function parse(stdClass $object): self continue; } if (is_array($value->meta->classes) && in_array('messageBody', $value->meta->classes)) { - $this->body[] = (isset($value->content)) ? $value->content : null; + $this->body[] = (isset($value->content)) ? $value->content : NULL; $this->headers['Content-Type'] = (isset($value->attributes->contentType)) ? $value->attributes->contentType : ''; continue; } @@ -125,12 +125,12 @@ public function parse(stdClass $object): self if (isset($value->meta->classes->content) && is_array($value->meta->classes->content) && $value->meta->classes->content[0]->content === 'messageBody') { - $this->body[] = (isset($value->content)) ? $value->content : null; + $this->body[] = (isset($value->content)) ? $value->content : NULL; $this->headers['Content-Type'] = (isset($value->attributes->contentType->content)) ? $value->attributes->contentType->content : ''; } elseif (isset($value->meta->classes->content) && is_array($value->meta->classes->content) && $value->meta->classes->content[0]->content === 'messageBodySchema') { - $this->body_schema = (isset($value->content)) ? $value->content : null; + $this->body_schema = (isset($value->content)) ? $value->content : NULL; } } } @@ -141,7 +141,7 @@ public function parse(stdClass $object): self } } - if ($this->body === null) { + if ($this->body === NULL) { $this->body = &$this->struct; } @@ -174,15 +174,15 @@ public function get_id(): string * @param string $base_url URL to the base server * @param array $additional Extra options to pass to cURL * - * @return string An executable cURL command * @throws Exception * + * @return string An executable cURL command */ public function get_curl_command(string $base_url, array $additional = []): string { $options = []; - $type = $this->headers['Content-Type'] ?? null; + $type = $this->headers['Content-Type'] ?? NULL; $options[] = '-X' . $this->method; if (empty($this->body)) { @@ -205,7 +205,7 @@ public function get_curl_command(string $base_url, array $additional = []): stri $options = array_merge($options, $additional); return htmlspecialchars('curl ' . join(' ', $options) . ' ' . escapeshellarg($this->parent->build_url($base_url, - true))); + TRUE))); } /** @@ -226,17 +226,17 @@ public function is_equal_to($b): bool * @param string $base_url URL to the base server * @param array $additional Extra options to pass to the service * - * @return string * @throws Exception * + * @return string */ public function get_hurl_link(string $base_url, array $additional = []): string { $options = []; - $type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : null; + $type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : NULL; - $url = $this->parent->build_url($base_url, true); + $url = $this->parent->build_url($base_url, TRUE); $url = explode('?', $url); if (isset($url[1])) { $params = []; diff --git a/src/PHPDraft/Out/BaseTemplateGenerator.php b/src/PHPDraft/Out/BaseTemplateGenerator.php index cf43073b..a86519fc 100644 --- a/src/PHPDraft/Out/BaseTemplateGenerator.php +++ b/src/PHPDraft/Out/BaseTemplateGenerator.php @@ -9,7 +9,6 @@ namespace PHPDraft\Out; - use Lukasoppermann\Httpstatus\Httpstatus; use PHPDraft\Model\Elements\ObjectStructureElement; @@ -50,7 +49,7 @@ abstract class BaseTemplateGenerator * * @var string */ - protected $image = null; + protected $image = NULL; /** * The base URl of the API. * @@ -69,4 +68,4 @@ abstract class BaseTemplateGenerator * @var ObjectStructureElement[] */ protected $base_structures = []; -} \ No newline at end of file +} diff --git a/src/PHPDraft/Out/LegacyTemplateGenerator.php b/src/PHPDraft/Out/LegacyTemplateGenerator.php index f388208f..824f2f61 100644 --- a/src/PHPDraft/Out/LegacyTemplateGenerator.php +++ b/src/PHPDraft/Out/LegacyTemplateGenerator.php @@ -12,7 +12,6 @@ use Lukasoppermann\Httpstatus\Httpstatus; use Michelf\MarkdownExtra; use PHPDraft\Model\Category; -use PHPDraft\Model\Elements\ObjectStructureElement; use PHPDraft\Parse\ExecutionException; class LegacyTemplateGenerator extends BaseTemplateGenerator diff --git a/src/PHPDraft/Parse/BaseHtmlGenerator.php b/src/PHPDraft/Parse/BaseHtmlGenerator.php index fee38d9a..92dc619d 100644 --- a/src/PHPDraft/Parse/BaseHtmlGenerator.php +++ b/src/PHPDraft/Parse/BaseHtmlGenerator.php @@ -9,9 +9,7 @@ namespace PHPDraft\Parse; - use PHPDraft\Out\BaseTemplateGenerator; -use PHPDraft\Out\TemplateGenerator; use stdClass; abstract class BaseHtmlGenerator @@ -38,6 +36,7 @@ abstract class BaseHtmlGenerator public function init(stdClass $json): self { $this->object = $json; + return $this; } @@ -53,5 +52,5 @@ public function __toString() return $this->get_html(); } - public abstract function get_html(string $template = 'default', ?string $image = NULL, ?string $css = NULL, ?string $js = NULL): BaseTemplateGenerator; -} \ No newline at end of file + abstract public function get_html(string $template = 'default', ?string $image = NULL, ?string $css = NULL, ?string $js = NULL): BaseTemplateGenerator; +}