/** * Adds an error to this document * @param JsonApiError $error Error to add * @return null */ public function addError(JsonApiError $error) { $this->errors[] = $error; if (!$this->statusCode && $error->getStatusCode()) { $this->statusCode = $error->getStatusCode(); } }
/** * Creates a new error * @param string $statusCode HTTP status code applicable to this problem * @param string $code Application-specific error code * @param string $title A short, human-readable summary of the problem that * SHOULD NOT change from occurrence to occurrence of the problem, except * for purposes of localization. * @param string $detail A human-readable explanation specific to this * occurrence of the problem. * @return JsonApiError */ public function createError($statusCode = null, $code = null, $title = null, $detail = null) { $error = new JsonApiError(); $error->setStatusCode($statusCode); $error->setCode($code); $error->setTitle($title); $error->setDetail($detail); return $error; }
public function providerGetJsonValue() { $document1 = new JsonApiDocument(); $document1->setMeta('meta1', 'value1'); $document1->setLink('self', 'http://url'); $expected1 = array('jsonapi' => array('version' => '1.0'), 'meta' => array('meta1' => 'value1'), 'links' => array('self' => $document1->getLink('self'))); $error = new JsonApiError(); $error->setCode('my-error'); $document2 = new JsonApiDocument(); $document2->addError($error); $expected2 = array('jsonapi' => array('version' => '1.0'), 'errors' => array($error)); $resource = new JsonApiResource('type', 'id'); $resource->setAttribute('attribute1', 'value1'); $resource->setAttribute('attribute2', 'value2'); $document3 = new JsonApiDocument(); $document3->setResourceData('type', $resource); $expected3 = array('jsonapi' => array('version' => '1.0'), 'data' => $resource->getJsonValue(true)); $document4 = new JsonApiDocument(); $document4->setResourceData('type', null); $expected4 = array('jsonapi' => array('version' => '1.0'), 'data' => null); return array(array($expected1, $document1), array($expected2, $document2), array($expected3, $document3), array($expected4, $document4)); }