Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. History.php

class History

History.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\BrowserKit\History

Expanded class hierarchy of History

1 file declares its use of History
HttpKernelBrowser.php in vendor/symfony/http-kernel/HttpKernelBrowser.php
10 string references to 'History'
CommentHooks::nodeViewAlter in core/modules/comment/src/Hook/CommentHooks.php
Implements hook_ENTITY_TYPE_view_alter() for node entities.
CommentLinkBuilder::buildCommentedEntityLinks in core/modules/comment/src/CommentLinkBuilder.php
CommentManager::getCountNewComments in core/modules/comment/src/CommentManager.php
CommentViewBuilder::buildComponents in core/modules/comment/src/CommentViewBuilder.php
In addition to modifying the content key on entities, this implementation will also set the comment entity key which all comments carry.
demo_umami.info.yml in core/profiles/demo_umami/demo_umami.info.yml
core/profiles/demo_umami/demo_umami.info.yml

... See full list

File

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

Namespace

Symfony\Component\BrowserKit
View source
class History {
    protected array $stack = [];
    protected int $position = -1;
    
    /**
     * Clears the history.
     */
    public function clear() : void {
        $this->stack = [];
        $this->position = -1;
    }
    
    /**
     * Adds a Request to the history.
     */
    public function add(Request $request) : void {
        $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.
     */
    public function isEmpty() : bool {
        return 0 === \count($this->stack);
    }
    
    /**
     * Goes back in the history.
     *
     * @throws LogicException if the stack is already on the first page
     */
    public function back() : Request {
        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.
     *
     * @throws LogicException if the stack is already on the last page
     */
    public function forward() : Request {
        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.
     *
     * @throws LogicException if the stack is empty
     */
    public function current() : Request {
        if (-1 === $this->position) {
            throw new LogicException('The page history is empty.');
        }
        return clone $this->stack[$this->position];
    }

}

Members

Title Sort descending Modifiers Object type Summary
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.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal