diff --git a/.gitignore b/.gitignore index d1502b0..f054ad8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor/ composer.lock + +.idea/ diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 53a257d..2d136d3 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -81,6 +81,7 @@ class Curl private $jsonPattern = '/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i'; private $xmlDecoder = null; private $xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; + private $defaultDecoder = null; /** * Construct @@ -754,6 +755,25 @@ class Curl }; } + /** + * Set Default Decoder + * + * @access public + * @param $decoder string|callable + */ + public function setDefaultDecoder($decoder = 'json') + { + if (is_callable($decoder)) { + $this->defaultDecoder = $decoder; + } else { + if ($decoder === 'json') { + $this->defaultDecoder = $this->jsonDecoder; + } elseif ($decoder === 'xml') { + $this->defaultDecoder = $this->xmlDecoder; + } + } + } + /** * Set Default Timeout * @@ -1041,6 +1061,11 @@ class Curl if (is_callable($xml_decoder)) { $response = $xml_decoder($response); } + } else { + $decoder = $this->defaultDecoder; + if (is_callable($decoder)) { + $response = $decoder($response); + } } }