ZF-11109: Find Zend_Json_Expr objects
Description
In it's current state, the Zend_Json_Server_Response class does not contain a way to find Zend_Json_Expr objects when returning data (with the toJson method, called automatically by default by Zend_Json_Server).
It would be very helpful to have a "findJsonExpr" flag within the Zend_Json_Server_Response class, that would be either true or false by default depending on the performance-wise implications such functionality brings.
The current public method toJson has the following implementation:
/**
* Cast to JSON
*
* @return string
*/
public function toJson()
{
if ($this->isError()) {
$response = array(
'result' => null,
'error' => $this->getError()->toArray(),
'id' => $this->getId(),
);
} else {
$response = array(
'result' => $this->getResult(),
'id' => $this->getId(),
'error' => null,
);
}
if (null !== ($version = $this->getVersion())) {
$response['jsonrpc'] = $version;
}
require_once 'Zend/Json.php';
return Zend_Json::encode($response);
}
Proposal:
/**
* Cast to JSON
*
* @return string
*/
public function toJson()
{
if ($this->isError()) {
$response = array(
'result' => null,
'error' => $this->getError()->toArray(),
'id' => $this->getId(),
);
} else {
$response = array(
'result' => $this->getResult(),
'id' => $this->getId(),
'error' => null,
);
}
if (null !== ($version = $this->getVersion())) {
$response['jsonrpc'] = $version;
}
require_once 'Zend/Json.php';
return Zend_Json::encode($response, false, array("findJsonExpr" => $this->_findJsonExpr)); //_findJsonExpr is a protected member (bool)
}
Right now, I have to disable auto-emit in Zend_Json_Server, retrieve the response object and do the whole routine above after sending the correct headers, with the exception of the last line.
Comments
No comments to display