Pressroom template verwijderd, website naar root van repo
This commit is contained in:
66
vendor/phpspec/prophecy/src/Prophecy/Promise/CallbackPromise.php
vendored
Normal file
66
vendor/phpspec/prophecy/src/Prophecy/Promise/CallbackPromise.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Prophecy.
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
* Marcello Duarte <marcello.duarte@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Prophecy\Promise;
|
||||
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
use Prophecy\Exception\InvalidArgumentException;
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Callback promise.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class CallbackPromise implements PromiseInterface
|
||||
{
|
||||
private $callback;
|
||||
|
||||
/**
|
||||
* Initializes callback promise.
|
||||
*
|
||||
* @param callable $callback Custom callback
|
||||
*
|
||||
* @throws \Prophecy\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function __construct($callback)
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Callable expected as an argument to CallbackPromise, but got %s.',
|
||||
gettype($callback)
|
||||
));
|
||||
}
|
||||
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates promise callback.
|
||||
*
|
||||
* @param array $args
|
||||
* @param ObjectProphecy $object
|
||||
* @param MethodProphecy $method
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(array $args, ObjectProphecy $object, MethodProphecy $method)
|
||||
{
|
||||
$callback = $this->callback;
|
||||
|
||||
if ($callback instanceof Closure && method_exists('Closure', 'bind')) {
|
||||
$callback = Closure::bind($callback, $object);
|
||||
}
|
||||
|
||||
return call_user_func($callback, $args, $object, $method);
|
||||
}
|
||||
}
|
||||
35
vendor/phpspec/prophecy/src/Prophecy/Promise/PromiseInterface.php
vendored
Normal file
35
vendor/phpspec/prophecy/src/Prophecy/Promise/PromiseInterface.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Prophecy.
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
* Marcello Duarte <marcello.duarte@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Prophecy\Promise;
|
||||
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
|
||||
/**
|
||||
* Promise interface.
|
||||
* Promises are logical blocks, tied to `will...` keyword.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
interface PromiseInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates promise.
|
||||
*
|
||||
* @param array $args
|
||||
* @param ObjectProphecy $object
|
||||
* @param MethodProphecy $method
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(array $args, ObjectProphecy $object, MethodProphecy $method);
|
||||
}
|
||||
61
vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnArgumentPromise.php
vendored
Normal file
61
vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnArgumentPromise.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Prophecy.
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
* Marcello Duarte <marcello.duarte@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Prophecy\Promise;
|
||||
|
||||
use Prophecy\Exception\InvalidArgumentException;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
|
||||
/**
|
||||
* Return argument promise.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class ReturnArgumentPromise implements PromiseInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $index;
|
||||
|
||||
/**
|
||||
* Initializes callback promise.
|
||||
*
|
||||
* @param int $index The zero-indexed number of the argument to return
|
||||
*
|
||||
* @throws \Prophecy\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function __construct($index = 0)
|
||||
{
|
||||
if (!is_int($index) || $index < 0) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Zero-based index expected as argument to ReturnArgumentPromise, but got %s.',
|
||||
$index
|
||||
));
|
||||
}
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns nth argument if has one, null otherwise.
|
||||
*
|
||||
* @param array $args
|
||||
* @param ObjectProphecy $object
|
||||
* @param MethodProphecy $method
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
public function execute(array $args, ObjectProphecy $object, MethodProphecy $method)
|
||||
{
|
||||
return count($args) > $this->index ? $args[$this->index] : null;
|
||||
}
|
||||
}
|
||||
55
vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnPromise.php
vendored
Normal file
55
vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnPromise.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Prophecy.
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
* Marcello Duarte <marcello.duarte@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Prophecy\Promise;
|
||||
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
|
||||
/**
|
||||
* Return promise.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class ReturnPromise implements PromiseInterface
|
||||
{
|
||||
private $returnValues = array();
|
||||
|
||||
/**
|
||||
* Initializes promise.
|
||||
*
|
||||
* @param array $returnValues Array of values
|
||||
*/
|
||||
public function __construct(array $returnValues)
|
||||
{
|
||||
$this->returnValues = $returnValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns saved values one by one until last one, then continuously returns last value.
|
||||
*
|
||||
* @param array $args
|
||||
* @param ObjectProphecy $object
|
||||
* @param MethodProphecy $method
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(array $args, ObjectProphecy $object, MethodProphecy $method)
|
||||
{
|
||||
$value = array_shift($this->returnValues);
|
||||
|
||||
if (!count($this->returnValues)) {
|
||||
$this->returnValues[] = $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
99
vendor/phpspec/prophecy/src/Prophecy/Promise/ThrowPromise.php
vendored
Normal file
99
vendor/phpspec/prophecy/src/Prophecy/Promise/ThrowPromise.php
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Prophecy.
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
* Marcello Duarte <marcello.duarte@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Prophecy\Promise;
|
||||
|
||||
use Doctrine\Instantiator\Instantiator;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
use Prophecy\Exception\InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Throw promise.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class ThrowPromise implements PromiseInterface
|
||||
{
|
||||
private $exception;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Instantiator\Instantiator
|
||||
*/
|
||||
private $instantiator;
|
||||
|
||||
/**
|
||||
* Initializes promise.
|
||||
*
|
||||
* @param string|\Exception|\Throwable $exception Exception class name or instance
|
||||
*
|
||||
* @throws \Prophecy\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function __construct($exception)
|
||||
{
|
||||
if (is_string($exception)) {
|
||||
if (!class_exists($exception) || !$this->isAValidThrowable($exception)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.',
|
||||
$exception
|
||||
));
|
||||
}
|
||||
} elseif (!$exception instanceof \Exception && !$exception instanceof \Throwable) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.',
|
||||
is_object($exception) ? get_class($exception) : 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exception
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isAValidThrowable($exception)
|
||||
{
|
||||
return is_a($exception, 'Exception', true) || is_subclass_of($exception, 'Throwable', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user