Skip to content

Commit

Permalink
If 'format' option exists in Forrest request, it takes precedence. Do…
Browse files Browse the repository at this point in the history
…n't set formatter if correct one is already set. (#271)
  • Loading branch information
Zaphell authored Oct 6, 2020
1 parent 8c4ff5c commit 03bc2ac
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Omniphx/Forrest/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ public function setCredentials($credentials) {

private function handleRequest()
{
if ($this->options['format'] !== $this->settings['defaults']['format']) {
if (isset($this->options['format'])) {
$this->setFormatter($this->options['format']);
} else {
$this->setFormatter($this->settings['defaults']['format']);
}

if (isset($this->options['headers'])) {
Expand Down Expand Up @@ -763,11 +765,11 @@ protected function storeVersion()
*/
protected function setFormatter($formatter)
{
if ($formatter === 'json') {
if ($formatter === 'json' && strpos(get_class($this->formatter), 'JSONFormatter') === false) {
$this->formatter = new JSONFormatter($this->tokenRepo, $this->settings);
} else if ($formatter === 'xml') {
} else if ($formatter === 'xml' && strpos(get_class($this->formatter), 'XMLFormatter') === false) {
$this->formatter = new XMLFormatter($this->tokenRepo, $this->settings);
} else if ($formatter === 'none') {
} else if ($formatter === 'none' && strpos(get_class($this->formatter), 'BaseFormatter') === false) {
$this->formatter = new BaseFormatter($this->tokenRepo, $this->settings);
}
}
Expand Down

0 comments on commit 03bc2ac

Please # to comment.