123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace Symfony\Component\BrowserKit;
- class History
- {
- protected $stack = [];
- protected $position = -1;
-
- public function clear()
- {
- $this->stack = [];
- $this->position = -1;
- }
-
- public function add(Request $request)
- {
- $this->stack = \array_slice($this->stack, 0, $this->position + 1);
- $this->stack[] = clone $request;
- $this->position = \count($this->stack) - 1;
- }
-
- public function isEmpty()
- {
- return 0 == \count($this->stack);
- }
-
- public function back()
- {
- if ($this->position < 1) {
- throw new \LogicException('You are already on the first page.');
- }
- return clone $this->stack[--$this->position];
- }
-
- public function forward()
- {
- if ($this->position > \count($this->stack) - 2) {
- throw new \LogicException('You are already on the last page.');
- }
- return clone $this->stack[++$this->position];
- }
-
- public function current()
- {
- if (-1 == $this->position) {
- throw new \LogicException('The page history is empty.');
- }
- return clone $this->stack[$this->position];
- }
- }
|