function Inspector::assertAll

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertAll()
  2. 10 core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertAll()
  3. 11.x core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertAll()

Asserts callback returns TRUE for each member of a traversable.

This is less memory intensive than using array_filter() to build a second array and then comparing the arrays. Many of the other functions in this collection alias this function passing a specific callback to make the code more readable.

Parameters

callable $callable: Callback function.

mixed $traversable: Variable to be examined.

Return value

bool TRUE if $traversable can be traversed and $callable returns TRUE on all members.

See also

http://php.net/manual/language.types.callable.php

13 calls to Inspector::assertAll()
EntityResourceTestBase::assertPatchProtectedFieldNamesStructure in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Asserts structure of $patchProtectedFieldNames.
ErrorCollection::__construct in core/modules/jsonapi/src/JsonApiResource/ErrorCollection.php
Instantiates an ErrorCollection object.
HTMLRestrictions::applyOperation in core/modules/ckeditor5/src/HTMLRestrictions.php
Applies an operation (difference/intersection/union) with wildcard support.
HTMLRestrictions::validateAllowedRestrictionsPhase4 in core/modules/ckeditor5/src/HTMLRestrictions.php
Validates allowed elements — phase 4: HTML tag attr restriction values.
Inspector::assertAllArrays in core/lib/Drupal/Component/Assertion/Inspector.php
Asserts that all members are arrays.

... See full list

File

core/lib/Drupal/Component/Assertion/Inspector.php, line 53

Class

Inspector
Generic inspections for the <a href="http://php.net/assert" target="_blank" class="php-manual" title="void assert(string $assertion [, string $description = &#039;&#039;, string $file, int $line]) Checks an assertion">assert</a>() statement.

Namespace

Drupal\Component\Assertion

Code

public static function assertAll(callable $callable, $traversable) {
    if (static::assertTraversable($traversable)) {
        foreach ($traversable as $member) {
            if (!$callable($member)) {
                return FALSE;
            }
        }
        return TRUE;
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.