当前位置: 首页>>代码示例>>PHP>>正文


PHP GraphQL\Utils类代码示例

本文整理汇总了PHP中GraphQL\Utils的典型用法代码示例。如果您正苦于以下问题:PHP Utils类的具体用法?PHP Utils怎么用?PHP Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke(ValidationContext $context)
 {
     return [Node::FIELD => function (Field $fieldAST) use($context) {
         $fieldDef = $context->getFieldDef();
         if (!$fieldDef) {
             return Visitor::skipNode();
         }
         $errors = [];
         $argASTs = $fieldAST->arguments ?: [];
         $argASTMap = Utils::keyMap($argASTs, function (Argument $arg) {
             return $arg->name->value;
         });
         foreach ($fieldDef->args as $argDef) {
             $argAST = isset($argASTMap[$argDef->name]) ? $argASTMap[$argDef->name] : null;
             if (!$argAST && $argDef->getType() instanceof NonNull) {
                 $errors[] = new Error(Messages::missingArgMessage($fieldAST->name->value, $argDef->name, $argDef->getType()), [$fieldAST]);
             }
         }
         $argDefMap = Utils::keyMap($fieldDef->args, function ($def) {
             return $def->name;
         });
         foreach ($argASTs as $argAST) {
             $argDef = $argDefMap[$argAST->name->value];
             if ($argDef && !DocumentValidator::isValidLiteralValue($argAST->value, $argDef->getType())) {
                 $errors[] = new Error(Messages::badValueMessage($argAST->name->value, $argDef->getType(), Printer::doPrint($argAST->value)), [$argAST->value]);
             }
         }
         return !empty($errors) ? $errors : null;
     }];
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:30,代码来源:ArgumentsOfCorrectType.php

示例2: parseValue

 public function parseValue($value)
 {
     if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
         throw new \Exception('Cannot represent value as email: ' . Utils::printSafe($value));
     }
     return $value;
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:7,代码来源:EmailType.php

示例3: doTypesOverlap

 private function doTypesOverlap($t1, $t2)
 {
     if ($t1 === $t2) {
         return true;
     }
     if ($t1 instanceof ObjectType) {
         if ($t2 instanceof ObjectType) {
             return false;
         }
         return in_array($t1, $t2->getPossibleTypes());
     }
     if ($t1 instanceof InterfaceType || $t1 instanceof UnionType) {
         if ($t2 instanceof ObjectType) {
             return in_array($t2, $t1->getPossibleTypes());
         }
         $t1TypeNames = Utils::keyMap($t1->getPossibleTypes(), function ($type) {
             return $type->name;
         });
         foreach ($t2->getPossibleTypes() as $type) {
             if (!empty($t1TypeNames[$type->name])) {
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:26,代码来源:PossibleFragmentSpreads.php

示例4: parseValue

 public function parseValue($value)
 {
     if (!is_string($value) || !filter_var($value, FILTER_VALIDATE_URL)) {
         throw new \Exception('Cannot represent value as URL:' . Utils::printSafe($value));
     }
     return $value;
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:7,代码来源:UrlType.php

示例5: __construct

 /**
  * ScalarType constructor.
  */
 public function __construct()
 {
     if (!isset($this->name)) {
         $this->name = $this->tryInferName();
     }
     Utils::invariant($this->name, 'Type must be named.');
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:10,代码来源:ScalarType.php

示例6: getField

 /**
  * @param $name
  * @return FieldDefinition
  * @throws \Exception
  */
 public function getField($name)
 {
     if (null === $this->fields) {
         $this->getFields();
     }
     Utils::invariant(isset($this->fields[$name]), 'Field "%s" is not defined for type "%s"', $name, $this->name);
     return $this->fields[$name];
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:13,代码来源:InterfaceType.php

示例7: parseValue

 /**
  * Parses an externally provided value (query variable) to use as an input
  *
  * @param mixed $value
  * @return mixed
  */
 public function parseValue($value)
 {
     if (!is_string($value) || !filter_var($value, FILTER_VALIDATE_URL)) {
         // quite naive, but after all this is example
         throw new \UnexpectedValueException("Cannot represent value as URL: " . Utils::printSafe($value));
     }
     return $value;
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:14,代码来源:UrlType.php

示例8: getTypeASTName

 private function getTypeASTName(Type $typeAST)
 {
     if ($typeAST->kind === Node::NAME) {
         return $typeAST->value;
     }
     Utils::invariant($typeAST->type, 'Must be wrapping type');
     return $this->getTypeASTName($typeAST->type);
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:8,代码来源:VariablesAreInputTypes.php

示例9: coerceFloat

 /**
  * @param $value
  * @return float|null
  */
 private function coerceFloat($value)
 {
     if ($value === '') {
         throw new InvariantViolation('Float cannot represent non numeric value: (empty string)');
     }
     if (is_numeric($value) || $value === true || $value === false) {
         return (double) $value;
     }
     throw new InvariantViolation('Float cannot represent non numeric value: ' . Utils::printSafe($value));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:14,代码来源:FloatType.php

示例10: withModifiers

 private function withModifiers($types)
 {
     return array_merge(Utils::map($types, function ($type) {
         return Type::listOf($type);
     }), Utils::map($types, function ($type) {
         return Type::nonNull($type);
     }), Utils::map($types, function ($type) {
         return Type::nonNull(Type::listOf($type));
     }));
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:10,代码来源:SchemaValidatorTest.php

示例11: __construct

 public function __construct($config)
 {
     Config::validate($config, ['name' => Config::STRING | Config::REQUIRED, 'values' => Config::arrayOf(['name' => Config::STRING | Config::REQUIRED, 'value' => Config::ANY, 'deprecationReason' => Config::STRING, 'description' => Config::STRING], Config::KEY_AS_NAME), 'description' => Config::STRING]);
     $this->name = $config['name'];
     $this->description = isset($config['description']) ? $config['description'] : null;
     $this->_values = [];
     if (!empty($config['values'])) {
         foreach ($config['values'] as $name => $value) {
             $this->_values[] = Utils::assign(new EnumValueDefinition(), $value + ['name' => $name]);
         }
     }
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:12,代码来源:EnumType.php

示例12: getImplementationsIncludingField

 /**
  * Return implementations of `type` that include `fieldName` as a valid field.
  *
  * @param Schema $schema
  * @param AbstractType $type
  * @param $fieldName
  * @return array
  */
 static function getImplementationsIncludingField(Schema $schema, AbstractType $type, $fieldName)
 {
     $types = $schema->getPossibleTypes($type);
     $types = Utils::filter($types, function ($t) use($fieldName) {
         return isset($t->getFields()[$fieldName]);
     });
     $types = Utils::map($types, function ($t) {
         return $t->name;
     });
     sort($types);
     return $types;
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:20,代码来源:FieldsOnCorrectType.php

示例13: coerceInt

 /**
  * @param $value
  * @return int|null
  */
 private function coerceInt($value)
 {
     if ($value === '') {
         throw new InvariantViolation('Int cannot represent non 32-bit signed integer value: (empty string)');
     }
     if (false === $value || true === $value) {
         return (int) $value;
     }
     if (is_numeric($value) && $value <= self::MAX_INT && $value >= self::MIN_INT) {
         return (int) $value;
     }
     throw new InvariantViolation('Int cannot represent non 32-bit signed integer value: ' . Utils::printSafe($value));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:17,代码来源:IntType.php

示例14: __invoke

 public function __invoke(ValidationContext $context)
 {
     $operationCount = 0;
     return [NodeKind::DOCUMENT => function (DocumentNode $node) use(&$operationCount) {
         $tmp = Utils::filter($node->definitions, function ($definition) {
             return $definition->kind === NodeKind::OPERATION_DEFINITION;
         });
         $operationCount = count($tmp);
     }, NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $node) use(&$operationCount, $context) {
         if (!$node->name && $operationCount > 1) {
             $context->reportError(new Error(self::anonOperationNotAloneMessage(), [$node]));
         }
     }];
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:14,代码来源:LoneAnonymousOperation.php

示例15: __construct

 public function __construct($config)
 {
     Config::validate($config, ['name' => Config::STRING | Config::REQUIRED, 'types' => Config::arrayOf(Config::OBJECT_TYPE | Config::REQUIRED), 'resolveType' => Config::CALLBACK, 'description' => Config::STRING]);
     Utils::invariant(!empty($config['types']), "");
     /**
      * Optionally provide a custom type resolver function. If one is not provided,
      * the default implemenation will call `isTypeOf` on each implementing
      * Object type.
      */
     $this->name = $config['name'];
     $this->description = isset($config['description']) ? $config['description'] : null;
     $this->_types = $config['types'];
     $this->_resolveType = isset($config['resolveType']) ? $config['resolveType'] : null;
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:14,代码来源:UnionType.php


注:本文中的GraphQL\Utils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。