2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-08-16 06:46:26 +02:00
|
|
|
|
2016-05-24 17:39:19 +02:00
|
|
|
namespace Amp;
|
2016-05-22 07:11:03 +02:00
|
|
|
|
2016-08-11 21:35:58 +02:00
|
|
|
class InvalidYieldError extends \Error {
|
2016-05-22 16:25:40 +02:00
|
|
|
/**
|
2017-03-16 01:10:23 +01:00
|
|
|
* @param \Generator $generator
|
|
|
|
* @param string $prefix
|
|
|
|
* @param \Throwable|null $previous
|
2016-05-22 16:25:40 +02:00
|
|
|
*/
|
2017-03-16 01:10:23 +01:00
|
|
|
public function __construct(\Generator $generator, string $prefix, \Throwable $previous = null) {
|
2016-06-17 05:44:32 +02:00
|
|
|
$yielded = $generator->current();
|
|
|
|
$prefix .= \sprintf(
|
|
|
|
"; %s yielded at key %s",
|
2016-05-22 07:11:03 +02:00
|
|
|
\is_object($yielded) ? \get_class($yielded) : \gettype($yielded),
|
2016-12-11 17:08:17 +01:00
|
|
|
\var_export($generator->key(), true)
|
2016-05-22 07:11:03 +02:00
|
|
|
);
|
|
|
|
|
2016-08-11 21:35:58 +02:00
|
|
|
if (!$generator->valid()) {
|
2017-03-16 01:10:23 +01:00
|
|
|
parent::__construct($prefix, 0, $previous);
|
2016-05-22 07:11:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reflGen = new \ReflectionGenerator($generator);
|
|
|
|
$exeGen = $reflGen->getExecutingGenerator();
|
|
|
|
if ($isSubgenerator = ($exeGen !== $generator)) {
|
|
|
|
$reflGen = new \ReflectionGenerator($exeGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct(\sprintf(
|
|
|
|
"%s on line %s in %s",
|
|
|
|
$prefix,
|
|
|
|
$reflGen->getExecutingLine(),
|
|
|
|
$reflGen->getExecutingFile()
|
2017-03-16 01:10:23 +01:00
|
|
|
), 0, $previous);
|
2016-05-22 07:11:03 +02:00
|
|
|
}
|
|
|
|
}
|