Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion for json method with passing bitmask option #390

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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/ 


9 changes: 7 additions & 2 deletions src/Klein/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down