assertAllObjects example


  protected function __construct($resource_type_name, array $fields) {
    assert(Inspector::assertAllObjects($fields, ResourceTypeField::class));
    $this->resourceTypeName = $resource_type_name;
    $this->fields = $fields;
  }

  /** * Creates a new ResourceTypeBuildEvent. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * An entity type for the resource type to be built. * @param string $bundle * A bundle name for the resource type to be built. If the entity type does * not have bundles, the entity type ID. * @param \Drupal\jsonapi\ResourceType\ResourceTypeField[] $fields * The fields of the resource type to be built. * * @return \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent * A new event. */
$this->assertFalse(Inspector::assertAllRegularExpressionMatch('/F/', ['fee', 'fi', 'fo']));
    $this->assertFalse(Inspector::assertAllRegularExpressionMatch('/e/', ['fee', 'fi', 'fo']));
    $this->assertFalse(Inspector::assertAllRegularExpressionMatch('/1/', [12]));
  }

  /** * Tests asserting all members are objects. * * @covers ::assertAllObjects */
  public function testAssertAllObjects() {
    $this->assertTrue(Inspector::assertAllObjects([new \ArrayObject()new \ArrayObject()]));
    $this->assertFalse(Inspector::assertAllObjects([new \ArrayObject()new \ArrayObject(), 'foo']));
    $this->assertTrue(Inspector::assertAllObjects([new \ArrayObject()new \ArrayObject()], '\\Traversable'));
    $this->assertFalse(Inspector::assertAllObjects([new \ArrayObject()new \ArrayObject(), 'foo'], '\\Traversable'));
    $this->assertFalse(Inspector::assertAllObjects([new \ArrayObject()new StringObject()], '\\Traversable'));
    $this->assertTrue(Inspector::assertAllObjects([new \ArrayObject()new StringObject()], '\\Traversable', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
    $this->assertFalse(Inspector::assertAllObjects([new \ArrayObject()new StringObject()new \stdClass()], '\\ArrayObject', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
  }

  /** * Defines a test method referenced by ::testAllCallable(). */
  
/** * RelationshipData constructor. * * @param \Drupal\jsonapi\JsonApiResource\ResourceIdentifier[] $data * Resource objects that are the primary data for the response. * @param int $cardinality * The number of ResourceIdentifiers that this collection may contain. * * @see \Drupal\jsonapi\JsonApiResource\Data::__construct */
  public function __construct(array $data$cardinality = -1) {
    assert(Inspector::assertAllObjects($data, ResourceIdentifier::class));
    parent::__construct($data$cardinality);
  }

}
/** * ResourceObjectData constructor. * * @param \Drupal\jsonapi\JsonApiResource\ResourceObject[]|\Drupal\jsonapi\Exception\EntityAccessDeniedHttpException[] $data * Resource objects that are the primary data for the response. * @param int $cardinality * The number of resources that this collection may contain. * * @see \Drupal\jsonapi\JsonApiResource\Data::__construct */
  public function __construct($data$cardinality = -1) {
    assert(Inspector::assertAllObjects($data, ResourceObject::class, EntityAccessDeniedHttpException::class));
    parent::__construct($data$cardinality);
  }

  /** * {@inheritdoc} */
  public function getData() {
    return $this->getAccessible();
  }

  /** * Gets only data to be exposed. * * @return static */

  protected function respondWithCollection(ResourceObjectData $primary_data, Data $includes, Request $request, ResourceType $resource_type, OffsetPage $page_param) {
    assert(Inspector::assertAllObjects([$includes], IncludedData::class, NullIncludedData::class));
    $link_context = [
      'has_next_page' => $primary_data->hasNextPage(),
    ];
    $meta = [];
    if ($resource_type->includeCount()) {
      $link_context['total_count'] = $meta['count'] = $primary_data->getTotalCount();
    }
    $collection_links = self::getPagerLinks($request$page_param$link_context);
    $response = $this->buildWrappedResponse($primary_data$request$includes, 200, []$collection_links$meta);

    // When a new change to any entity in the resource happens, we cannot ensure

  public static function aggregate(array $cacheable_normalizations) {
    assert(Inspector::assertAllObjects($cacheable_normalizations, CacheableNormalization::class));
    return new static(
      array_reduce($cacheable_normalizationsfunction DCacheableMetadata $merged, CacheableNormalization $item) {
        return $merged->addCacheableDependency($item);
      }new CacheableMetadata()),
      array_reduce(array_keys($cacheable_normalizations)function D$merged$key) use ($cacheable_normalizations) {
        if (!$cacheable_normalizations[$key] instanceof CacheableOmission) {
          $merged[$key] = $cacheable_normalizations[$key]->getNormalization();
        }
        return $merged;
      }[])
    );
  }
class IncludedData extends ResourceObjectData {

  /** * IncludedData constructor. * * @param \Drupal\jsonapi\JsonApiResource\ResourceObject[]|\Drupal\jsonapi\Exception\EntityAccessDeniedHttpException[] $data * Resource objects that are the primary data for the response. * * @see \Drupal\jsonapi\JsonApiResource\Data::__construct */
  public function __construct($data) {
    assert(Inspector::assertAllObjects($data, ResourceObject::class, EntityAccessDeniedHttpException::class));
    parent::__construct($data, -1);
  }

}

  public function __construct(array $links$context = NULL) {
    assert(Inspector::assertAll(function D$key) {
      return static::validKey($key);
    }array_keys($links)));
    assert(Inspector::assertAll(function D$link) {
      return $link instanceof Link || is_array($link) && Inspector::assertAllObjects($link, Link::class);
    }$links));
    assert(is_null($context) || Inspector::assertAllObjects([$context], JsonApiDocumentTopLevel::class, ResourceObject::class, Relationship::class));
    ksort($links);
    $this->links = array_map(function D$link) {
      return is_array($link) ? $link : [$link];
    }$links);
    $this->context = $context;
  }

  /** * {@inheritdoc} */
class OmittedData extends ResourceObjectData {

  /** * OmittedData constructor. * * @param \Drupal\jsonapi\Exception\EntityAccessDeniedHttpException[] $data * Resource objects that are the primary data for the response. * * @see \Drupal\jsonapi\JsonApiResource\Data::__construct */
  public function __construct(array $data) {
    assert(Inspector::assertAllObjects($data, EntityAccessDeniedHttpException::class));
    parent::__construct($data, -1);
  }

}

  public function __construct(array $data$cardinality = -1) {
    assert(Inspector::assertAllObjects($data, ResourceIdentifierInterface::class));
    assert($cardinality >= -1 && $cardinality !== 0, 'Cardinality must be -1 for unlimited cardinality or a positive integer.');
    assert($cardinality === -1 || count($data) <= $cardinality, 'If cardinality is not unlimited, the number of given resources must not exceed the cardinality of the collection.');
    $this->data = array_values($data);
    $this->cardinality = $cardinality;
  }

  /** * Returns an iterator for entities. * * @return \ArrayIterator * An \ArrayIterator instance */
Home | Imprint | This part of the site doesn't use cookies.