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


PHP Type::float方法代码示例

本文整理汇总了PHP中GraphQL\Type\Definition\Type::float方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::float方法的具体用法?PHP Type::float怎么用?PHP Type::float使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphQL\Type\Definition\Type的用法示例。


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

示例1: resolveType

 /**
  * @param string $name
  * @return Type
  */
 public function resolveType($name)
 {
     if (preg_match('#^(.+)\\!$#', $name, $regs)) {
         return Type::nonNull($this->resolveType($regs[1]));
     }
     if (preg_match('#^\\[(.+)\\]$#', $name, $regs)) {
         return Type::listOf($this->resolveType($regs[1]));
     }
     switch ($name) {
         case Type::INT:
             return Type::int();
         case Type::STRING:
             return Type::string();
         case Type::BOOLEAN:
             return Type::boolean();
         case Type::FLOAT:
             return Type::float();
         case Type::ID:
             return Type::id();
         default:
             if (!isset($this->types[$name])) {
                 throw new \InvalidArgumentException(sprintf('Type "%s" is not defined', $name));
             }
             return $this->types[$name];
     }
 }
开发者ID:jmcclell,项目名称:graphql-mapper,代码行数:30,代码来源:TypeResolver.php

示例2: testSerializesOutputFloat

 /**
  * @it serializes output float
  */
 public function testSerializesOutputFloat()
 {
     $floatType = Type::float();
     $this->assertSame(1.0, $floatType->serialize(1));
     $this->assertSame(0.0, $floatType->serialize(0));
     $this->assertSame(123.5, $floatType->serialize('123.5'));
     $this->assertSame(-1.0, $floatType->serialize(-1));
     $this->assertSame(0.1, $floatType->serialize(0.1));
     $this->assertSame(1.1, $floatType->serialize(1.1));
     $this->assertSame(-1.1, $floatType->serialize(-1.1));
     $this->assertSame(-1.1, $floatType->serialize('-1.1'));
     try {
         $floatType->serialize('one');
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Float cannot represent non numeric value: one', $e->getMessage());
     }
     try {
         $floatType->serialize('');
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Float cannot represent non numeric value: (empty string)', $e->getMessage());
     }
     $this->assertSame(0.0, $floatType->serialize(false));
     $this->assertSame(1.0, $floatType->serialize(true));
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:29,代码来源:ScalarSerializationTest.php

示例3: getDefaultSchema

 /**
  * @return Schema
  */
 protected function getDefaultSchema()
 {
     $Being = new InterfaceType(['name' => 'Being', 'fields' => ['name' => ['type' => Type::string()]]]);
     $Pet = new InterfaceType(['name' => 'Pet', 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogCommand = new EnumType(['name' => 'DogCommand', 'values' => ['SIT' => ['value' => 0], 'HEEL' => ['value' => 1], 'DOWN' => ['value' => 3]]]);
     $Dog = new ObjectType(['name' => 'Dog', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'barkVolume' => ['type' => Type::int()], 'barks' => ['type' => Type::boolean()], 'doesKnowCommand' => ['type' => Type::boolean(), 'args' => ['dogCommand' => ['type' => $DogCommand]]], 'isHousetrained' => ['type' => Type::boolean(), 'args' => ['atOtherHomes' => ['type' => Type::boolean(), 'defaultValue' => true]]], 'isAtLocation' => ['type' => Type::boolean(), 'args' => ['x' => ['type' => Type::int()], 'y' => ['type' => Type::int()]]]], 'interfaces' => [$Being, $Pet]]);
     $FurColor = new EnumType(['name' => 'FurColor', 'values' => ['BROWN' => ['value' => 0], 'BLACK' => ['value' => 1], 'TAN' => ['value' => 2], 'SPOTTED' => ['value' => 3]]]);
     $Cat = new ObjectType(['name' => 'Cat', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()], 'meowVolume' => ['type' => Type::int()], 'furColor' => ['type' => $FurColor]], 'interfaces' => [$Being, $Pet]]);
     $CatOrDog = new UnionType(['name' => 'CatOrDog', 'types' => [$Dog, $Cat], 'resolveType' => function ($value) {
         // not used for validation
         return null;
     }]);
     $Intelligent = new InterfaceType(['name' => 'Intelligent', 'fields' => ['iq' => ['type' => Type::int()]]]);
     $Human = $this->humanType = new ObjectType(['name' => 'Human', 'interfaces' => [$Being, $Intelligent], 'fields' => ['name' => ['args' => ['surname' => ['type' => Type::boolean()]], 'type' => Type::string()], 'pets' => ['type' => Type::listOf($Pet)], 'relatives' => ['type' => function () {
         return Type::listOf($this->humanType);
     }]]]);
     $Alien = new ObjectType(['name' => 'Alien', 'interfaces' => [$Being, $Intelligent], 'fields' => ['iq' => ['type' => Type::int()], 'numEyes' => ['type' => Type::int()]]]);
     $DogOrHuman = new UnionType(['name' => 'DogOrHuman', 'types' => [$Dog, $Human], 'resolveType' => function () {
         // not used for validation
         return null;
     }]);
     $HumanOrAlien = new UnionType(['name' => 'HumanOrAlien', 'types' => [$Human, $Alien], 'resolveType' => function () {
         // not used for validation
         return null;
     }]);
     $ComplexInput = new InputObjectType(['name' => 'ComplexInput', 'fields' => ['requiredField' => ['type' => Type::nonNull(Type::boolean())], 'intField' => ['type' => Type::int()], 'stringField' => ['type' => Type::string()], 'booleanField' => ['type' => Type::boolean()], 'stringListField' => ['type' => Type::listOf(Type::string())]]]);
     $ComplicatedArgs = new ObjectType(['name' => 'ComplicatedArgs', 'fields' => ['intArgField' => ['type' => Type::string(), 'args' => ['intArg' => ['type' => Type::int()]]], 'nonNullIntArgField' => ['type' => Type::string(), 'args' => ['nonNullIntArg' => ['type' => Type::nonNull(Type::int())]]], 'stringArgField' => ['type' => Type::string(), 'args' => ['stringArg' => ['type' => Type::string()]]], 'booleanArgField' => ['type' => Type::string(), 'args' => ['booleanArg' => ['type' => Type::boolean()]]], 'enumArgField' => ['type' => Type::string(), 'args' => ['enumArg' => ['type' => $FurColor]]], 'floatArgField' => ['type' => Type::string(), 'args' => ['floatArg' => ['type' => Type::float()]]], 'idArgField' => ['type' => Type::string(), 'args' => ['idArg' => ['type' => Type::id()]]], 'stringListArgField' => ['type' => Type::string(), 'args' => ['stringListArg' => ['type' => Type::listOf(Type::string())]]], 'complexArgField' => ['type' => Type::string(), 'args' => ['complexArg' => ['type' => $ComplexInput]]], 'multipleReqs' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())]]], 'multipleOpts' => ['type' => Type::string(), 'args' => ['opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]], 'multipleOptAndReq' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())], 'opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]]]]);
     $queryRoot = new ObjectType(['name' => 'QueryRoot', 'fields' => ['human' => ['args' => ['id' => ['type' => Type::id()]], 'type' => $Human], 'alien' => ['type' => $Alien], 'dog' => ['type' => $Dog], 'cat' => ['type' => $Cat], 'pet' => ['type' => $Pet], 'catOrDog' => ['type' => $CatOrDog], 'dogOrHuman' => ['type' => $DogOrHuman], 'humanOrAlien' => ['type' => $HumanOrAlien], 'complicatedArgs' => ['type' => $ComplicatedArgs]]]);
     $defaultSchema = new Schema($queryRoot);
     return $defaultSchema;
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:34,代码来源:TestCase.php

示例4: testCoercesOutputFloat

 public function testCoercesOutputFloat()
 {
     $floatType = Type::float();
     $this->assertSame(1.0, $floatType->coerce(1));
     $this->assertSame(-1.0, $floatType->coerce(-1));
     $this->assertSame(0.1, $floatType->coerce(0.1));
     $this->assertSame(1.1, $floatType->coerce(1.1));
     $this->assertSame(-1.1, $floatType->coerce(-1.1));
     $this->assertSame(null, $floatType->coerce('one'));
     $this->assertSame(0.0, $floatType->coerce(false));
     $this->assertSame(1.0, $floatType->coerce(true));
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:12,代码来源:ScalarCoercionTest.php

示例5: testDoesNotConvertWhenInputCoercionRulesRejectAValue

 /**
  * @it does not convert when input coercion rules reject a value
  */
 public function testDoesNotConvertWhenInputCoercionRulesRejectAValue()
 {
     $undefined = Utils::undefined();
     $this->runTestCase(Type::boolean(), '123', $undefined);
     $this->runTestCase(Type::int(), '123.456', $undefined);
     $this->runTestCase(Type::int(), 'true', $undefined);
     $this->runTestCase(Type::int(), '"123"', $undefined);
     $this->runTestCase(Type::float(), '"123"', $undefined);
     $this->runTestCase(Type::string(), '123', $undefined);
     $this->runTestCase(Type::string(), 'true', $undefined);
     $this->runTestCase(Type::id(), '123.456', $undefined);
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:15,代码来源:ValueFromAstTest.php

示例6: testConvertsInputObjects

 /**
  * @it converts input objects
  */
 public function testConvertsInputObjects()
 {
     $inputObj = new InputObjectType(['name' => 'MyInputObj', 'fields' => ['foo' => Type::float(), 'bar' => $this->myEnum()]]);
     $expected = new ObjectValue(['fields' => [$this->objectField('foo', new IntValue(['value' => '3'])), $this->objectField('bar', new EnumValue(['value' => 'HELLO']))]]);
     $data = ['foo' => 3, 'bar' => 'HELLO'];
     $this->assertEquals($expected, AST::astFromValue($data, $inputObj));
     $this->assertEquals($expected, AST::astFromValue((object) $data, $inputObj));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:11,代码来源:AstFromValueTest.php

示例7: initAlambicBaseTypes

 /**
  * Initialize Alambic types using GraphQL scalar types.
  */
 protected function initAlambicBaseTypes()
 {
     $this->alambicTypes = ['String' => Type::string(), 'Int' => Type::int(), 'Float' => Type::float(), 'Boolean' => Type::boolean(), 'ID' => Type::id()];
     $this->inputAlambicTypes = ['String' => Type::string(), 'Int' => Type::int(), 'Float' => Type::float(), 'Boolean' => Type::boolean(), 'ID' => Type::id()];
 }
开发者ID:webtales,项目名称:alambic,代码行数:8,代码来源:Alambic.php

示例8: float

 /**
  * @return \GraphQL\Type\Definition\FloatType
  */
 public static function float()
 {
     return Type::float();
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:7,代码来源:Types.php

示例9: schemaWithFieldArgOfType

 private function schemaWithFieldArgOfType($argType)
 {
     $someIncorrectInputType = new InputObjectType(['name' => 'SomeIncorrectInputType', 'fields' => ['val' => ['type' => function () use($argType) {
         return $argType;
     }]]]);
     $queryType = new ObjectType(['name' => 'QueryType', 'fields' => ['f2' => ['type' => Type::float(), 'args' => ['arg' => ['type' => $someIncorrectInputType]]]]]);
     return new Schema($queryType);
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:8,代码来源:SchemaValidatorTest.php

示例10: testConvertsInputObjectsWithExplicitNulls

 /**
  * @it converts input objects with explicit nulls
  */
 public function testConvertsInputObjectsWithExplicitNulls()
 {
     $inputObj = new InputObjectType(['name' => 'MyInputObj', 'fields' => ['foo' => Type::float(), 'bar' => $this->myEnum()]]);
     $this->assertEquals(new ObjectValueNode(['fields' => [$this->objectField('foo', new NullValueNode([]))]]), AST::astFromValue(['foo' => null], $inputObj));
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:8,代码来源:AstFromValueTest.php

示例11: resolveTypeByColumn

 /**
  * Resolve field type by column info.
  *
  * @param  string $name
  * @param  string $colType
  * @return \GraphQL\Type\Definition\Type
  */
 protected function resolveTypeByColumn($name, $colType)
 {
     $type = Type::string();
     $type->name = $this->getName() . '_String';
     if ($name === $this->model->getKeyName()) {
         $type = Type::id();
         $type->name = $this->getName() . '_ID';
     } elseif ($colType === 'integer') {
         $type = Type::int();
         $type->name = $this->getName() . '_Int';
     } elseif ($colType === 'float' || $colType === 'decimal') {
         $type = Type::float();
         $type->name = $this->getName() . '_Float';
     } elseif ($colType === 'boolean') {
         $type = Type::boolean();
         $type->name = $this->getName() . '_Boolean';
     }
     return $type;
 }
开发者ID:nuwave,项目名称:laravel-graphql-relay,代码行数:26,代码来源:EloquentType.php

示例12: float

 /**
  * Float field.
  *
  * @param  array|string $config
  * @return array
  */
 public function float($config = [])
 {
     $description = is_string($config) ? $config : '';
     $config = is_array($config) ? $config : [];
     return array_merge(['type' => Type::float(), 'description' => $description], $config);
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:12,代码来源:ScalarTypes.php

示例13: getFloatType

 /**
  * Get FloatType instance.
  *
  * @return \GraphQL\Type\Definition\FloatType
  */
 public function getFloatType()
 {
     return Type::float();
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:9,代码来源:TypeGenerator.php


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