graphql-php/tests/Executor/TestClasses/Root.php

46 lines
1013 B
PHP
Raw Normal View History

2018-09-01 18:07:06 +03:00
<?php
declare(strict_types=1);
namespace GraphQL\Tests\Executor\TestClasses;
2018-09-26 12:07:23 +03:00
use Exception;
2018-09-01 18:07:06 +03:00
use GraphQL\Deferred;
class Root
{
/** @var NumberHolder */
public $numberHolder;
public function __construct(float $originalNumber)
{
$this->numberHolder = new NumberHolder($originalNumber);
}
public function promiseToChangeTheNumber($newNumber) : Deferred
{
return new Deferred(function () use ($newNumber) {
return $this->immediatelyChangeTheNumber($newNumber);
});
}
public function immediatelyChangeTheNumber($newNumber) : NumberHolder
{
$this->numberHolder->theNumber = $newNumber;
return $this->numberHolder;
}
public function failToChangeTheNumber() : void
{
2018-09-26 12:07:23 +03:00
throw new Exception('Cannot change the number');
2018-09-01 18:07:06 +03:00
}
public function promiseAndFailToChangeTheNumber() : Deferred
{
return new Deferred(function () {
$this->failToChangeTheNumber();
});
}
}