*/ /** * Class representing the Recurison Handlers */ class RecursionHandler { /** * An instance of Recursion Handler * @var RecursionHandler */ protected static $instance; /** * Array of all pages currently forbiden for recursion. * @var array */ protected $pages; /** * Handler is singleton, it is only accessible using this function. * @return RecursionHandler */ public static function getInstance() { if(!isset(RecursionHandler::$instance)) { RecursionHandler::$instance = new RecursionHandler(); } return RecursionHandler::$instance; } /** * Private constructor. */ protected function __construct() { $this->pages = array(); } /** * If the page is already in array, it can't be recursively inserted. * @param string $page * @return boolean */ public function disallow($page) { return in_array($page, $this->pages); } /** * Inserts the page to array. * @param string $page */ public function insert($page) { $this->pages[] = $page; } /** * Removes the page from array and revalues the array. * @param string $page */ public function remove($page) { $search = array_search($page, $this->pages); if ($search !== FALSE) { unset($this->pages[$search]); $this->pages = array_values($this->pages); } } }