/** * 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; }
/** * @return ErrorStack */ protected function getErrorStack() { return $this->hasErrors() ? $this->errors->getErrors() : []; }
/** * @param ErrorStack $messageStack */ public function merge(ErrorStack $messageStack) { $this->errors = array_merge($this->errors, $messageStack->getErrors()); }