class ErrorCollection in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/JsonApiResource/ErrorCollection.php \Drupal\jsonapi\JsonApiResource\ErrorCollection
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/drupal/issues/3032787
http://jsonapi.org/format/#document-top-level
http://jsonapi.org/format/#error-objects
2 files declare their use of ErrorCollection
- DefaultExceptionSubscriber.php in core/
modules/ jsonapi/ src/ EventSubscriber/ DefaultExceptionSubscriber.php - JsonApiDocumentTopLevelNormalizer.php in core/
modules/ jsonapi/ src/ Normalizer/ JsonApiDocumentTopLevelNormalizer.php
File
- core/
modules/ jsonapi/ 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. |