Skip to content

Commit ac91adc

Browse files
committed
Change minimimum required PHP version to 5.3.23
- JSON_UNESCAPED_FLAGS is only available starting in 5.4.0; test for it before attempting to use it.
1 parent 2e4a964 commit ac91adc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
},
2828
"require": {
29-
"php": ">=5.4.8",
29+
"php": ">=5.3.23",
3030
"zendframework/zend-eventmanager": "~2.3-dev",
3131
"zendframework/zend-json": "~2.3-dev",
3232
"zendframework/zend-mvc": "~2.3-dev",

src/ZF/ApiProblem/ApiProblemResponse.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313
*/
1414
class ApiProblemResponse extends Response
1515
{
16+
/**
17+
* @var ApiProblem
18+
*/
1619
protected $apiProblem;
1720

21+
/**
22+
* Flags to use with json_encode
23+
*
24+
* @var int
25+
*/
26+
protected $jsonFlags = 0;
27+
1828
/**
1929
* @param ApiProblem $apiProblem
2030
*/
@@ -23,6 +33,10 @@ public function __construct(ApiProblem $apiProblem)
2333
$this->apiProblem = $apiProblem;
2434
$this->setStatusCode($apiProblem->status);
2535
$this->setReasonPhrase($apiProblem->title);
36+
37+
if (defined('JSON_UNESCAPED_SLASHES')) {
38+
$this->jsonFlags = constant('JSON_UNESCAPED_SLASHES');
39+
}
2640
}
2741

2842
/**
@@ -42,7 +56,7 @@ public function getApiProblem()
4256
*/
4357
public function getContent()
4458
{
45-
return json_encode($this->apiProblem->toArray(), JSON_UNESCAPED_SLASHES);
59+
return json_encode($this->apiProblem->toArray(), $this->jsonFlags);
4660
}
4761

4862
/**

0 commit comments

Comments
 (0)