Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 5326190fc690eb59f6575c01243b0085 > files > 112

php-apc-3.1.15-4.14.mga4.x86_64.rpm

<?php

namespace Symfony\Component\BrowserKit;

class History
{
    protected $stack = array();
    protected $position = -1;

    public function __construct()
    {
        $this->clear();
    }

    public function clear()
    {
        $this->stack = array();
        $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 count($this->stack) == 0;
    }

    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];
    }
}