for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* AjaxResponse
*
* @package erdiko/core
* @copyright 2012-2017 Arroyo Labs, Inc. http://www.arroyolabs.com
* @author John Arroyo <[email protected]>
* @author Andy Armstrong <[email protected]>
*/
namespace erdiko\core;
class AjaxResponse extends Response
{
* _statusCode
* Unless explicitly set, default to a 200 status
* assuming everything went ok.
protected $_statusCode = 200;
* _errors
protected $_errors = false;
* Theme
protected $_theme;
* Content
protected $_content = null;
* setStatusCode
* Set, and send, the HTTP status code.
public function setStatusCode($code = null)
if (!empty($code)) {
$this->_statusCode = $code;
http_response_code($this->_statusCode); // this sends the http status code
}
public function setErrors($errors = null)
if (!empty($errors)) {
if (!is_array($errors)) {
$errors = array($errors);
$this->_errors = $errors;
$errors
array
boolean
$_errors
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
* Ajax render function
* @return string
public function render()
$responseData = array(
"status" => $this->_statusCode,
"body" => $this->_content,
"errors" => $this->_errors
);
return json_encode($responseData);
* Render and send data to browser then end request
* @note This should only be called at the very end of processing the response
public function send()
// set the mime type to JSON
header('Content-Type: application/json');
echo $this->render();
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..