/** * Renders the values as a json object. * * @return string */ public function render() { $options = 0; $options |= $this->prettyPrint ? JSON_PRETTY_PRINT : 0; if ($this->hasErrors()) { $json = json_encode(['errors' => $this->getErrorStack()], $options); } else { $json = json_encode($this->values, $options); } if (json_last_error() !== JSON_ERROR_NONE) { $errorStack = new ErrorStack(); $errorStack->addError('Invalid JSON'); $json = json_encode(['errors' => $errorStack->getErrors()], $options); } return $json; }
/** * @param string $message * @param int $code * * @return Result */ public function addError($message, $code = null) { $this->errorStack->addError($message, $code); return $this; }
/** * @param string $message * @param int $code * * @return Controller */ protected function addError($message, $code = null) { $this->errorStack->addError($message, $code); }