class ErrorCollection
Same name in other branches
- 9 core/modules/jsonapi/src/JsonApiResource/ErrorCollection.php \Drupal\jsonapi\JsonApiResource\ErrorCollection
- 10 core/modules/jsonapi/src/JsonApiResource/ErrorCollection.php \Drupal\jsonapi\JsonApiResource\ErrorCollection
- 11.x 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.
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
(The spec says the top-level `data` and `errors` members MUST NOT coexist.)
http://jsonapi.org/format/#document-top-level
http://jsonapi.org/format/#error-objects
3 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 - JsonApiDocumentTopLevelNormalizerTest.php in core/
modules/ jsonapi/ tests/ src/ Kernel/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.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
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ErrorCollection::$errors | protected | property | The HTTP exceptions. |
ErrorCollection::getIterator | public | function | Returns an iterator for errors. |
ErrorCollection::__construct | public | function | Instantiates an ErrorCollection object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.