Skip to content

Commit

Permalink
Allow body in other calls then PUT/POST
Browse files Browse the repository at this point in the history
Issue GH-77
  • Loading branch information
SMillerDev committed Nov 16, 2019
1 parent d40d31d commit a8c1f63
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea/
/.phpintel/

# IntelliJ
/build/coverage
Expand All @@ -16,4 +17,4 @@ composer.lock
# JIRA plugin
atlassian-ide-plugin.xml

*.pem
*.pem
8 changes: 5 additions & 3 deletions src/PHPDraft/Model/Elements/BasicStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions src/PHPDraft/Model/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand All @@ -117,20 +117,20 @@ 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;
}

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;
}
}
}
Expand All @@ -141,7 +141,7 @@ public function parse(stdClass $object): self
}
}

if ($this->body === null) {
if ($this->body === NULL) {
$this->body = &$this->struct;
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -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)));
}

/**
Expand All @@ -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 = [];
Expand Down
5 changes: 2 additions & 3 deletions src/PHPDraft/Out/BaseTemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace PHPDraft\Out;


use Lukasoppermann\Httpstatus\Httpstatus;
use PHPDraft\Model\Elements\ObjectStructureElement;

Expand Down Expand Up @@ -50,7 +49,7 @@ abstract class BaseTemplateGenerator
*
* @var string
*/
protected $image = null;
protected $image = NULL;
/**
* The base URl of the API.
*
Expand All @@ -69,4 +68,4 @@ abstract class BaseTemplateGenerator
* @var ObjectStructureElement[]
*/
protected $base_structures = [];
}
}
1 change: 0 additions & 1 deletion src/PHPDraft/Out/LegacyTemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/PHPDraft/Parse/BaseHtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

namespace PHPDraft\Parse;


use PHPDraft\Out\BaseTemplateGenerator;
use PHPDraft\Out\TemplateGenerator;
use stdClass;

abstract class BaseHtmlGenerator
Expand All @@ -38,6 +36,7 @@ abstract class BaseHtmlGenerator
public function init(stdClass $json): self
{
$this->object = $json;

return $this;
}

Expand All @@ -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;
}
abstract public function get_html(string $template = 'default', ?string $image = NULL, ?string $css = NULL, ?string $js = NULL): BaseTemplateGenerator;
}

0 comments on commit a8c1f63

Please sign in to comment.