class ErrorCollection in JSON:API 8.2
To be used when the primary data is `errors`.
@internal JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it.
(The spec says the top-level `data` and `errors` members MUST NOT coexist.)
Hierarchy
- class \Drupal\jsonapi\JsonApiResource\ErrorCollection implements \Drupal\jsonapi\JsonApiResource\IteratorAggregate
Expanded class hierarchy of ErrorCollection
See also
https://www.drupal.org/project/jsonapi/issues/3032787
http://jsonapi.org/format/#document-top-level
http://jsonapi.org/format/#error-objects
3 files declare their use of ErrorCollection
- DefaultExceptionSubscriber.php in src/
EventSubscriber/ DefaultExceptionSubscriber.php - JsonApiDocumentTopLevelNormalizer.php in src/
Normalizer/ JsonApiDocumentTopLevelNormalizer.php - JsonApiDocumentTopLevelNormalizerTest.php in tests/
src/ Kernel/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.php
File
- src/
JsonApiResource/ ErrorCollection.php, line 22
Namespace
Drupal\jsonapi\JsonApiResourceView source
class ErrorCollection implements \IteratorAggregate {
/**
* The HTTP exceptions.
*
* @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface[]
*/
protected $errors;
/**
* Instantiates an ErrorCollection object.
*
* @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface[] $errors
* The errors.
*/
public function __construct(array $errors) {
assert(Inspector::assertAll(function ($error) {
return $error instanceof HttpExceptionInterface;
}, $errors));
$this->errors = $errors;
}
/**
* Returns an iterator for errors.
*
* @return \ArrayIterator
* An \ArrayIterator instance
*/
public function getIterator() {
return new \ArrayIterator($this->errors);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ErrorCollection:: |
protected | property | The HTTP exceptions. | |
ErrorCollection:: |
public | function | Returns an iterator for errors. | |
ErrorCollection:: |
public | function | Instantiates an ErrorCollection object. |