當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。