assertAll example


  protected $errors;

  /** * Instantiates an ErrorCollection object. * * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface[] $errors * The errors. */
  public function __construct(array $errors) {
    assert(Inspector::assertAll(function D$error) {
      return $error instanceof HttpExceptionInterface;
    }$errors));
    $this->errors = $errors;
  }

  /** * Returns an iterator for errors. * * @return \ArrayIterator * An \ArrayIterator instance */
  

        if (!is_array($html_tag_attribute_restrictions)) {
          throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has an attribute restriction "%s" which is neither TRUE nor an array of attribute value restrictions.', $html_tag_name$html_tag_attribute_name));
        }
        if ($html_tag_attribute_restrictions === []) {
          throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has an attribute restriction "%s" which is set to the empty array. This is not permitted, specify either TRUE to allow all attribute values, or list the attribute value restrictions.', $html_tag_name$html_tag_attribute_name));
        }
        if (array_key_exists('*', $html_tag_attribute_restrictions)) {
          throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has an attribute restriction "%s" with a "*" allowed attribute value. This implies all attributes values are allowed. Remove the attribute value restriction instead, or use a prefix (`*-foo`), infix (`*-foo-*`) or suffix (`foo-*`) wildcard restriction instead.', $html_tag_name$html_tag_attribute_name));
        }
        // @codingStandardsIgnoreLine         if (!Inspector::assertAll(function D$v) { return $v === TRUE; }$html_tag_attribute_restrictions)) {
          throw new \InvalidArgumentException(sprintf('The "%s" HTML tag has attribute restriction "%s", but it is not an array of key-value pairs, with HTML tag attribute values as keys and TRUE as values.', $html_tag_name$html_tag_attribute_name));
        }
      }
    }
  }

  /** * Validates allowed elements — phase 5: disallowed attribute overrides. * * Explicit overrides of globally disallowed attributes are considered errors. * For example: `<p style>`, `<a onclick>` are considered errors when the * `style` and `on*` attributes are globally disallowed. * * Implicit overrides are not treated as errors: if all attributes are allowed * on a tag, globally disallowed attributes still apply. * For example: `<p *>` allows all attributes on `<p>`, but still won't allow * globally disallowed attributes. * * @param array $elements * The allowed elements. * * @throws \InvalidArgumentException */

  protected function assertPatchProtectedFieldNamesStructure() {
    $is_null_or_string = function D$value) {
      return is_null($value) || is_string($value);
    };
    $this->assertTrue(
      Inspector::assertAllStrings(array_keys(static::$patchProtectedFieldNames)),
      'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
    );
    $this->assertTrue(
      Inspector::assertAll($is_null_or_stringstatic::$patchProtectedFieldNames),
      'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
    );
  }

  /** * Gets an entity resource's GET/PATCH/DELETE URL. * * @return \Drupal\Core\Url * The URL to GET/PATCH/DELETE. */
  protected function getEntityResourceUrl() {
    
/** * LinkCollection constructor. * * @param \Drupal\jsonapi\JsonApiResource\Link[] $links * An associated array of key names and JSON:API Link objects. * @param \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel|\Drupal\jsonapi\JsonApiResource\ResourceObject|\Drupal\jsonapi\JsonApiResource\Relationship $context * (internal use only) The context object. Use the self::withContext() * method to establish a context. This should be done automatically when * a LinkCollection is passed into a context object. */
  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;
  }

  public function __construct(CacheableMetadata $cacheability, Url $url, string $link_relation_type, array $target_attributes = []) {
    assert(Inspector::assertAllStrings(array_keys($target_attributes)));
    assert(Inspector::assertAll(function D$target_attribute_value) {
      return is_string($target_attribute_value) || is_array($target_attribute_value);
    }array_values($target_attributes)));
    $generated_url = $url->setAbsolute()->toString(TRUE);
    $this->href = $generated_url->getGeneratedUrl();
    $this->uri = $url;
    $this->rel = $link_relation_type;
    $this->attributes = $target_attributes;
    $this->setCacheability($cacheability->addCacheableDependency($generated_url));
  }

  /** * Gets the link's URI. * * @return \Drupal\Core\Url * The link's URI as a Url object. */

  public static function assertAllStrings($traversable) {
    return static::assertAll('is_string', $traversable);
  }

  /** * Asserts all members are strings or objects with magic __toString() method. * * @param mixed $traversable * Variable to be examined. * * @return bool * TRUE if $traversable can be traversed and all members are strings or * objects with __toString(). */
/** * {@inheritdoc} */
  protected function alterDefinitions(&$definitions) {
    // Save in the definition whether this is a module or a theme. This is     // important because when creating the plugin instance (the Component     // object) we'll need to negotiate based on the active theme.     $definitions = array_map([$this, 'alterDefinition']$definitions);
    // Validate the definition after alterations.     assert(
      Inspector::assertAll(
        fn(array $definition) => $this->isValidDefinition($definition),
        $definitions
      )
    );
    parent::alterDefinitions($definitions);

    // Finally, validate replacements.     $replacing_definitions = array_filter(
      $definitions,
      static fn(array $definition) => ($definition['replaces'] ?? NULL) && ($definitions[$definition['replaces']] ?? NULL)
    );
    
Home | Imprint | This part of the site doesn't use cookies.