You are here

class History in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/browser-kit/History.php \Symfony\Component\BrowserKit\History

History.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\BrowserKit\History

Expanded class hierarchy of History

3 files declare their use of History
Client.php in vendor/symfony/http-kernel/Client.php
ClientTest.php in vendor/symfony/browser-kit/Tests/ClientTest.php
HistoryTest.php in vendor/symfony/browser-kit/Tests/HistoryTest.php
1 string reference to 'History'
history.info.yml in core/modules/history/history.info.yml
core/modules/history/history.info.yml

File

vendor/symfony/browser-kit/History.php, line 19

Namespace

Symfony\Component\BrowserKit
View source
class History {
  protected $stack = array();
  protected $position = -1;

  /**
   * Clears the history.
   */
  public function clear() {
    $this->stack = array();
    $this->position = -1;
  }

  /**
   * Adds a Request to the history.
   *
   * @param Request $request A Request instance
   */
  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;
  }

  /**
   * Returns true if the history is empty.
   *
   * @return bool true if the history is empty, false otherwise
   */
  public function isEmpty() {
    return count($this->stack) == 0;
  }

  /**
   * Goes back in the history.
   *
   * @return Request A Request instance
   *
   * @throws \LogicException if the stack is already on the first page
   */
  public function back() {
    if ($this->position < 1) {
      throw new \LogicException('You are already on the first page.');
    }
    return clone $this->stack[--$this->position];
  }

  /**
   * Goes forward in the history.
   *
   * @return Request A Request instance
   *
   * @throws \LogicException if the stack is already on the last page
   */
  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];
  }

  /**
   * Returns the current element in the history.
   *
   * @return Request A Request instance
   *
   * @throws \LogicException if the stack is empty
   */
  public function current() {
    if (-1 == $this->position) {
      throw new \LogicException('The page history is empty.');
    }
    return clone $this->stack[$this->position];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
History::$position protected property
History::$stack protected property
History::add public function Adds a Request to the history.
History::back public function Goes back in the history.
History::clear public function Clears the history.
History::current public function Returns the current element in the history.
History::forward public function Goes forward in the history.
History::isEmpty public function Returns true if the history is empty.