Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / browser-kit / History.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.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
12 namespace Symfony\Component\BrowserKit;
13
14 /**
15  * History.
16  *
17  * @author Fabien Potencier <fabien@symfony.com>
18  */
19 class History
20 {
21     protected $stack = array();
22     protected $position = -1;
23
24     /**
25      * Clears the history.
26      */
27     public function clear()
28     {
29         $this->stack = array();
30         $this->position = -1;
31     }
32
33     /**
34      * Adds a Request to the history.
35      *
36      * @param Request $request A Request instance
37      */
38     public function add(Request $request)
39     {
40         $this->stack = array_slice($this->stack, 0, $this->position + 1);
41         $this->stack[] = clone $request;
42         $this->position = count($this->stack) - 1;
43     }
44
45     /**
46      * Returns true if the history is empty.
47      *
48      * @return bool true if the history is empty, false otherwise
49      */
50     public function isEmpty()
51     {
52         return count($this->stack) == 0;
53     }
54
55     /**
56      * Goes back in the history.
57      *
58      * @return Request A Request instance
59      *
60      * @throws \LogicException if the stack is already on the first page
61      */
62     public function back()
63     {
64         if ($this->position < 1) {
65             throw new \LogicException('You are already on the first page.');
66         }
67
68         return clone $this->stack[--$this->position];
69     }
70
71     /**
72      * Goes forward in the history.
73      *
74      * @return Request A Request instance
75      *
76      * @throws \LogicException if the stack is already on the last page
77      */
78     public function forward()
79     {
80         if ($this->position > count($this->stack) - 2) {
81             throw new \LogicException('You are already on the last page.');
82         }
83
84         return clone $this->stack[++$this->position];
85     }
86
87     /**
88      * Returns the current element in the history.
89      *
90      * @return Request A Request instance
91      *
92      * @throws \LogicException if the stack is empty
93      */
94     public function current()
95     {
96         if (-1 == $this->position) {
97             throw new \LogicException('The page history is empty.');
98         }
99
100         return clone $this->stack[$this->position];
101     }
102 }