class ThrowPromise in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/phpspec/prophecy/src/Prophecy/Promise/ThrowPromise.php \Prophecy\Promise\ThrowPromise
Throw promise.
@author Konstantin Kudryashov <ever.zet@gmail.com>
Hierarchy
- class \Prophecy\Promise\ThrowPromise implements PromiseInterface
Expanded class hierarchy of ThrowPromise
File
- vendor/
phpspec/ prophecy/ src/ Prophecy/ Promise/ ThrowPromise.php, line 25
Namespace
Prophecy\PromiseView source
class ThrowPromise implements PromiseInterface {
private $exception;
/**
* @var \Doctrine\Instantiator\Instantiator
*/
private $instantiator;
/**
* Initializes promise.
*
* @param string|\Exception $exception Exception class name or instance
*
* @throws \Prophecy\Exception\InvalidArgumentException
*/
public function __construct($exception) {
if (is_string($exception)) {
if (!class_exists($exception) && 'Exception' !== $exception && !is_subclass_of($exception, 'Exception')) {
throw new InvalidArgumentException(sprintf('Exception class or instance expected as argument to ThrowPromise, but got %s.', gettype($exception)));
}
}
elseif (!$exception instanceof \Exception) {
throw new InvalidArgumentException(sprintf('Exception class or instance expected as argument to ThrowPromise, but got %s.', gettype($exception)));
}
$this->exception = $exception;
}
/**
* Throws predefined exception.
*
* @param array $args
* @param ObjectProphecy $object
* @param MethodProphecy $method
*
* @throws object
*/
public function execute(array $args, ObjectProphecy $object, MethodProphecy $method) {
if (is_string($this->exception)) {
$classname = $this->exception;
$reflection = new ReflectionClass($classname);
$constructor = $reflection
->getConstructor();
if ($constructor
->isPublic() && 0 == $constructor
->getNumberOfRequiredParameters()) {
throw $reflection
->newInstance();
}
if (!$this->instantiator) {
$this->instantiator = new Instantiator();
}
throw $this->instantiator
->instantiate($classname);
}
throw $this->exception;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThrowPromise:: |
private | property | ||
ThrowPromise:: |
private | property | ||
ThrowPromise:: |
public | function |
Throws predefined exception. Overrides PromiseInterface:: |
|
ThrowPromise:: |
public | function | Initializes promise. |