-
-
Save arnold-almeida/2f656202153b3e161bcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class JsonpResponseFormat extends \Dingo\Api\Http\ResponseFormat\JsonResponseFormat | |
{ | |
/** | |
* Get the response content type. | |
* | |
* @return string | |
*/ | |
public function getContentType() | |
{ | |
if (isset($_GET['callback']) && !empty($_GET['callback'])) { | |
return 'application/javascript'; | |
} | |
return 'application/json'; | |
} | |
/** | |
* Encode the content to its JSON representation. | |
* | |
* @param string $content | |
* @return string | |
*/ | |
protected function encode($content) | |
{ | |
if (isset($_GET['callback']) && !empty($_GET['callback'])) { | |
$callback = $_GET['callback']; | |
return sprintf('%s(%s);', $callback, json_encode($content)); | |
} | |
return json_encode($content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment