Skip to content

Commit

Permalink
Move type handling to reader
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed May 30, 2021
1 parent f48dcec commit 50d4482
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main/php/webservices/rest/Result.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function match(array $cases) {
*/
public function value($type= null) {
$s= $this->response->status();
if ($s >= 200 && $s < 300) return $this->response->reader()->read($type ?? 'var');
if ($s >= 200 && $s < 300) return $this->response->reader()->read($type);

throw new UnexpectedStatus($this->response);
}
Expand All @@ -113,7 +113,7 @@ public function value($type= null) {
*/
public function optional($type= null, $absent= [404]) {
$s= $this->response->status();
if ($s >= 200 && $s < 300) return $this->response->reader()->read($type ?? 'var');
if ($s >= 200 && $s < 300) return $this->response->reader()->read($type);
if (in_array($s, $absent)) return null;

throw new UnexpectedStatus($this->response);
Expand All @@ -131,6 +131,6 @@ public function error($type= null) {
if ($this->response->status() < 400) return null;

$r= $this->response->reader();
return $r->format() instanceof Unsupported ? $r->content() : $r->read($type ?? 'var');
return $r->format() instanceof Unsupported ? $r->content() : $r->read($type);
}
}
2 changes: 1 addition & 1 deletion src/main/php/webservices/rest/UnexpectedStatus.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public function status() { return $this->response->status(); }
*/
public function reason($type= null) {
$r= $this->response->reader();
return $r->format() instanceof Unsupported ? $r->content() : $r->read($type ?? 'var');
return $r->format() instanceof Unsupported ? $r->content() : $r->read($type);
}
}
6 changes: 3 additions & 3 deletions src/main/php/webservices/rest/io/Reader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function content() {
/**
* Reads the payload and unmarshals it to data
*
* @param string $type
* @param ?string $type
* @return var
*/
public function read($type= 'var') {
return $this->marshalling->unmarshal($this->format->deserialize($this->stream), $type);
public function read($type= null) {
return $this->marshalling->unmarshal($this->format->deserialize($this->stream), $type ?? 'var');
}
}

0 comments on commit 50d4482

Please sign in to comment.