GraphQL\Utils::every PHP Метод

every() публичный статический Метод

public static every ( $traversable, callable $predicate ) : boolean
$traversable
$predicate callable
Результат boolean
    public static function every($traversable, callable $predicate)
    {
        foreach ($traversable as $key => $value) {
            if (!$predicate($value, $key)) {
                return false;
            }
        }
        return true;
    }

Usage Example

Пример #1
0
 /**
  * @param array $config
  */
 protected function init(array $config)
 {
     $config += ['query' => null, 'mutation' => null, 'subscription' => null, 'types' => [], 'directives' => [], 'validate' => true];
     if ($config['query'] instanceof DefinitionContainer) {
         $config['query'] = $config['query']->getDefinition();
     }
     if ($config['mutation'] instanceof DefinitionContainer) {
         $config['mutation'] = $config['mutation']->getDefinition();
     }
     if ($config['subscription'] instanceof DefinitionContainer) {
         $config['subscription'] = $config['subscription']->getDefinition();
     }
     Utils::invariant($config['query'] instanceof ObjectType, "Schema query must be Object Type but got: " . Utils::getVariableType($config['query']));
     $this->queryType = $config['query'];
     Utils::invariant(!$config['mutation'] || $config['mutation'] instanceof ObjectType, "Schema mutation must be Object Type if provided but got: " . Utils::getVariableType($config['mutation']));
     $this->mutationType = $config['mutation'];
     Utils::invariant(!$config['subscription'] || $config['subscription'] instanceof ObjectType, "Schema subscription must be Object Type if provided but got: " . Utils::getVariableType($config['subscription']));
     $this->subscriptionType = $config['subscription'];
     Utils::invariant(!$config['types'] || is_array($config['types']), "Schema types must be Array if provided but got: " . Utils::getVariableType($config['types']));
     Utils::invariant(!$config['directives'] || is_array($config['directives']) && Utils::every($config['directives'], function ($d) {
         return $d instanceof Directive;
     }), "Schema directives must be Directive[] if provided but got " . Utils::getVariableType($config['directives']));
     $this->directives = $config['directives'] ?: GraphQL::getInternalDirectives();
     // Build type map now to detect any errors within this schema.
     $initialTypes = [$config['query'], $config['mutation'], $config['subscription'], Introspection::_schema()];
     if (!empty($config['types'])) {
         $initialTypes = array_merge($initialTypes, $config['types']);
     }
     foreach ($initialTypes as $type) {
         $this->extractTypes($type);
     }
     $this->typeMap += Type::getInternalTypes();
     // Keep track of all implementations by interface name.
     $this->implementations = [];
     foreach ($this->typeMap as $typeName => $type) {
         if ($type instanceof ObjectType) {
             foreach ($type->getInterfaces() as $iface) {
                 $this->implementations[$iface->name][] = $type;
             }
         }
     }
 }