1<?php
2
3/*
4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 *     Marcello Duarte <marcello.duarte@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Prophecy\Promise;
13
14use Prophecy\Prophecy\ObjectProphecy;
15use Prophecy\Prophecy\MethodProphecy;
16
17/**
18 * Return promise.
19 *
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 */
22class ReturnPromise implements PromiseInterface
23{
24    private $returnValues = array();
25
26    /**
27     * Initializes promise.
28     *
29     * @param array $returnValues Array of values
30     */
31    public function __construct(array $returnValues)
32    {
33        $this->returnValues = $returnValues;
34    }
35
36    /**
37     * Returns saved values one by one until last one, then continuously returns last value.
38     *
39     * @param array          $args
40     * @param ObjectProphecy $object
41     * @param MethodProphecy $method
42     *
43     * @return mixed
44     */
45    public function execute(array $args, ObjectProphecy $object, MethodProphecy $method)
46    {
47        $value = array_shift($this->returnValues);
48
49        if (!count($this->returnValues)) {
50            $this->returnValues[] = $value;
51        }
52
53        return $value;
54    }
55}
56