class ErrorCollection in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/JsonApiResource/ErrorCollection.php \Drupal\jsonapi\JsonApiResource\ErrorCollection
- 9 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 - JsonapiMaintenanceModeSubscriber.php in core/
modules/ jsonapi/ src/ EventSubscriber/ JsonapiMaintenanceModeSubscriber.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
*/
#[\ReturnTypeWillChange]
public function getIterator() {
return new \ArrayIterator($this->errors);
}
}