history = []; $this->historySize = $historySize; $this->eraseDups = $eraseDups; } /** * {@inheritdoc} */ public function addHistory($line) { if ($this->eraseDups) { if (($key = \array_search($line, $this->history)) !== false) { unset($this->history[$key]); } } $this->history[] = $line; if ($this->historySize > 0) { $histsize = \count($this->history); if ($histsize > $this->historySize) { $this->history = \array_slice($this->history, $histsize - $this->historySize); } } $this->history = \array_values($this->history); return true; } /** * {@inheritdoc} */ public function clearHistory() { $this->history = []; return true; } /** * {@inheritdoc} */ public function listHistory() { return $this->history; } /** * {@inheritdoc} */ public function readHistory() { return true; } /** * {@inheritdoc} * * @throws BreakException if user hits Ctrl+D * * @return string */ public function readline($prompt = null) { echo $prompt; return \rtrim(\fgets($this->getStdin()), "\n\r"); } /** * {@inheritdoc} */ public function redisplay() { // noop } /** * {@inheritdoc} */ public function writeHistory() { return true; } /** * Get a STDIN file handle. * * @throws BreakException if user hits Ctrl+D * * @return resource */ private function getStdin() { if (!isset($this->stdin)) { $this->stdin = \fopen('php://stdin', 'r'); } if (\feof($this->stdin)) { throw new BreakException('Ctrl+D'); } return $this->stdin; } }