From 4f974ce3bed825bbae7e3c66ae4adc7e185119fd Mon Sep 17 00:00:00 2001 From: Henry Wong Date: Tue, 1 May 2018 13:01:25 +0000 Subject: [PATCH 1/3] Update Response.php --- src/Klein/Response.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Klein/Response.php b/src/Klein/Response.php index 5bae3aeb..4e23b373 100644 --- a/src/Klein/Response.php +++ b/src/Klein/Response.php @@ -165,4 +165,23 @@ public function json($object, $jsonp_prefix = null) return $this; } + + public function jsonPretty($object, $jsonp_prefix = null) + { + $this->body(''); + $this->noCache(); + + $json = json_encode($object, JSON_PRETTY_PRINT); + if (null !== $jsonp_prefix) { + $this->header('Content-Type', 'text/javascript'); + $this->body("$jsonp_prefox($json);"); + } else { + $this->header('Content-Type', 'application/json'); + $this->body($json); + } + + $this->send(); + + return $this; + } } From ad08541e8c1261f139af8b615f103108143cf867 Mon Sep 17 00:00:00 2001 From: Henry Wong Date: Thu, 10 May 2018 21:10:22 +0000 Subject: [PATCH 2/3] Update Response.php --- src/Klein/Response.php | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/Klein/Response.php b/src/Klein/Response.php index 4e23b373..2ee847fc 100644 --- a/src/Klein/Response.php +++ b/src/Klein/Response.php @@ -143,14 +143,19 @@ public function file($path, $filename = null, $mimetype = null) * * @param mixed $object The data to encode as JSON * @param string $jsonp_prefix The name of the JSON-P function prefix + * @param bitmask $json_encode_option The bitmask options for JSON_ENCODE * @return Response */ - public function json($object, $jsonp_prefix = null) + public function json($object, $jsonp_prefix = null, $json_encode_option = null) { $this->body(''); $this->noCache(); - $json = json_encode($object); + if ($json_encode_option != null) { + $json = json_encode($object, $json_encode_option); + } else { + $json = json_encode($object); + } if (null !== $jsonp_prefix) { // Should ideally be application/json-p once adopted @@ -165,23 +170,4 @@ public function json($object, $jsonp_prefix = null) return $this; } - - public function jsonPretty($object, $jsonp_prefix = null) - { - $this->body(''); - $this->noCache(); - - $json = json_encode($object, JSON_PRETTY_PRINT); - if (null !== $jsonp_prefix) { - $this->header('Content-Type', 'text/javascript'); - $this->body("$jsonp_prefox($json);"); - } else { - $this->header('Content-Type', 'application/json'); - $this->body($json); - } - - $this->send(); - - return $this; - } } From bc8cf7e40592028f7cf5dc930516b36b7b02da18 Mon Sep 17 00:00:00 2001 From: Henry Wong Date: Thu, 10 May 2018 21:20:51 +0000 Subject: [PATCH 3/3] Update .travis.yml --- .travis.yml | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8ad4419..f522634c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,26 @@ sudo: false language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - nightly +php:  + - 5.4  + - 5.5  + - 5.6  + - 7.0  + - nightly  - hhvm - -matrix: - allow_failures: - - php: nightly - - php: hhvm + +matrix:  + include:    + - php: 5.3      + dist: precise  + allow_failures:    + - php: nightly    + - php: hhvm  fast_finish: true - -before_script: + +before_script:  - composer install --prefer-dist - -script: - - composer validate - ./vendor/bin/phpunit - - ./vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 -p src/ tests/ +  - ./vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 -p src/ tests/  + +