closedquestion-8.x-3.x-dev/src/Utility/EvalMathStack.php

src/Utility/EvalMathStack.php
<?php

namespace Drupal\closedquestion\Utility;

/**
 * A stack implementation for internal use.
 */
class EvalMathStack {

  /**
   * The actual stack.
   *
   * @var array
   */
  private $stack = array();

  /**
   * The number of items on the stack.
   *
   * @var int
   */
  private $count = 0;

  /**
   * Puts an item on the stack.
   *
   * @param mixed $val
   *   The item to put on the stack.
   */
  public function push($val) {
    $this->stack[$this->count] = $val;
    $this->count++;
  }

  /**
   * Pops an item from the stack.
   *
   * @return mixed
   *   The last item that was put on the stack, or NULL if no items are on the
   *   stack.
   */
  public function pop() {
    if ($this->count > 0) {
      $this->count--;

      return $this->stack[$this->count];
    }

    return NULL;
  }

  /**
   * Returns the item that is n places from the end of the stack.
   *
   * @param int $n
   *   The distance from the end to look. $n=1 is the last item on the stack.
   *
   * @return mixed
   *   The item at distance $n from the end of the stack.
   */
  public function last($n = 1) {
    if (($this->count - $n) >= 0) {
      return $this->stack[$this->count - $n];
    }
    else {
      return NULL;
    }
  }

  /**
   * Returns the number of items on the stack.
   *
   * @return int
   *   The number of items on the stack.
   */
  public function getCount() {
    return $this->count;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc