-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpinator\ExtraTypes; | ||
|
||
final class RationalNumberInput extends \Graphpinator\Typesystem\InputType | ||
{ | ||
protected const NAME = 'RationalNumberInput'; | ||
protected const DESCRIPTION = 'RationalNumber input - input for the RationalNumber structure.'; | ||
|
||
public function __construct( | ||
private \Graphpinator\ConstraintDirectives\ConstraintDirectiveAccessor $constraintDirectiveAccessor, | ||
) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function getFieldDefinition() : \Graphpinator\Typesystem\Argument\ArgumentSet | ||
{ | ||
return new \Graphpinator\Typesystem\Argument\ArgumentSet([ | ||
\Graphpinator\Typesystem\Argument\Argument::create( | ||
'numerator', | ||
\Graphpinator\Typesystem\Container::Int()->notNull(), | ||
), | ||
\Graphpinator\Typesystem\Argument\Argument::create( | ||
'denominator', | ||
\Graphpinator\Typesystem\Container::Int()->notNull(), | ||
)->addDirective( | ||
$this->constraintDirectiveAccessor->getInt(), | ||
['min' => 1], | ||
), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpinator\ExtraTypes; | ||
|
||
final class RationalNumberType extends \Graphpinator\Typesystem\Type | ||
{ | ||
protected const NAME = 'RationalNumberType'; | ||
protected const DESCRIPTION = 'RationalNumber type - structure for numerator and denominator.'; | ||
|
||
public function __construct( | ||
private \Graphpinator\ConstraintDirectives\ConstraintDirectiveAccessor $constraintDirectiveAccessor, | ||
) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function validateNonNullValue(mixed $rawValue) : bool | ||
{ | ||
return $rawValue instanceof \stdClass | ||
&& \property_exists($rawValue, 'numerator') | ||
&& \property_exists($rawValue, 'denominator') | ||
&& \is_int($rawValue->numerator) | ||
&& \is_int($rawValue->denominator); | ||
} | ||
|
||
protected function getFieldDefinition() : \Graphpinator\Typesystem\Field\ResolvableFieldSet | ||
{ | ||
return new \Graphpinator\Typesystem\Field\ResolvableFieldSet([ | ||
\Graphpinator\Typesystem\Field\ResolvableField::create( | ||
'numerator', | ||
\Graphpinator\Typesystem\Container::Int()->notNull(), | ||
static function(\stdClass $number) : int { | ||
return $number->numerator; | ||
}, | ||
), | ||
\Graphpinator\Typesystem\Field\ResolvableField::create( | ||
'denominator', | ||
\Graphpinator\Typesystem\Container::Int()->notNull(), | ||
static function(\stdClass $number) : int { | ||
return $number->denominator; | ||
}, | ||
)->addDirective( | ||
$this->constraintDirectiveAccessor->getInt(), | ||
['min' => 1], | ||
), | ||
]); | ||
} | ||
} |