Last active
July 17, 2019 12:48
-
-
Save omnidan/7706595 to your computer and use it in GitHub Desktop.
Pretty-printed Symfony JsonResponse class. 100% compatible with the original class, requires PHP 5.4.0 or higher.
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 | |
/** | |
* @license WTFPL (Do What the Fuck You Want to Public License) | |
* @author Daniel Bugl <[email protected]> | |
*/ | |
namespace TouchLay\HelperBundle\Component; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
/** | |
* Class PrettyJsonResponse: Pretty prints the Symfony JsonResponse, 100% compatible with JsonResponse | |
* @package TouchLay\HelperBundle\Component | |
*/ | |
class PrettyJsonResponse extends JsonResponse { | |
/** | |
* Sets the data to be sent as json. | |
* | |
* @param mixed $data | |
* | |
* @return JsonResponse | |
*/ | |
public function setData($data = array()) | |
{ | |
// Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML. | |
$this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | |
| JSON_PRETTY_PRINT); // JSON_PRETTY_PRINT requires PHP >5.4.0 | |
return $this->update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just extend JsonResponse end override property,