| @@ 12-66 (lines=55) @@ | ||
| 9 | * type. Lists are often created within the context of defining the fields of an |
|
| 10 | * object type. |
|
| 11 | */ |
|
| 12 | class ListModifier extends Type implements TypeInterface, InputTypeInterface, OutputTypeInterface, NullableTypeInterface, ModifierInterface |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var callable|\Fubhy\GraphQL\Type\Definition\Types\TypeInterface |
|
| 16 | */ |
|
| 17 | protected $ofType; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param callable|\Fubhy\GraphQL\Type\Definition\Types\TypeInterface $ofType |
|
| 21 | */ |
|
| 22 | public function __construct($ofType) |
|
| 23 | { |
|
| 24 | if (!($ofType instanceof TypeInterface) && !is_callable($ofType)) { |
|
| 25 | throw new \LogicException('Expected callable or instance of \Fubhy\GraphQL\Type\Definition\Types\TypeInterface.'); |
|
| 26 | } |
|
| 27 | ||
| 28 | $this->ofType = $ofType; |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface |
|
| 33 | */ |
|
| 34 | public function getWrappedType() |
|
| 35 | { |
|
| 36 | if (is_callable($this->ofType)) { |
|
| 37 | $this->ofType = call_user_func($this->ofType); |
|
| 38 | } |
|
| 39 | ||
| 40 | return $this->ofType; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * {@inheritdoc} |
|
| 45 | */ |
|
| 46 | public function getName() |
|
| 47 | { |
|
| 48 | return '[' . (string) $this->getWrappedType() . ']'; |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * {@inheritdoc} |
|
| 53 | */ |
|
| 54 | public function getDescription() |
|
| 55 | { |
|
| 56 | return NULL; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function __toString() |
|
| 63 | { |
|
| 64 | return $this->getName(); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 16-72 (lines=57) @@ | ||
| 13 | * |
|
| 14 | * Note: The enforcement of non-nullability occurs within the executor. |
|
| 15 | */ |
|
| 16 | class NonNullModifier extends Type implements TypeInterface, InputTypeInterface, OutputTypeInterface, ModifierInterface |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @var callable|\Fubhy\GraphQL\Type\Definition\Types\TypeInterface |
|
| 20 | */ |
|
| 21 | protected $ofType; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Constructor. |
|
| 25 | * |
|
| 26 | * @param callable|\Fubhy\GraphQL\Type\Definition\Types\TypeInterface $ofType |
|
| 27 | */ |
|
| 28 | public function __construct($ofType) |
|
| 29 | { |
|
| 30 | if (!($ofType instanceof TypeInterface) && !is_callable($ofType)) { |
|
| 31 | throw new \LogicException('Expected callable or instance of \Fubhy\GraphQL\Type\Definition\Types\TypeInterface.'); |
|
| 32 | } |
|
| 33 | ||
| 34 | $this->ofType = $ofType; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface |
|
| 39 | */ |
|
| 40 | public function getWrappedType() |
|
| 41 | { |
|
| 42 | if (is_callable($this->ofType)) { |
|
| 43 | $this->ofType = call_user_func($this->ofType); |
|
| 44 | } |
|
| 45 | ||
| 46 | return $this->ofType; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function getName() |
|
| 53 | { |
|
| 54 | return (string) $this->getWrappedType() . '!'; |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * {@inheritdoc} |
|
| 59 | */ |
|
| 60 | public function getDescription() |
|
| 61 | { |
|
| 62 | return NULL; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * {@inheritdoc} |
|
| 67 | */ |
|
| 68 | public function __toString() |
|
| 69 | { |
|
| 70 | return $this->getName(); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||