public function setUp()
 {
     if (!Libedit::isSupported()) {
         $this->markTestSkipped('Libedit not enabled');
     }
     $this->historyFile = tempnam(sys_get_temp_dir(), 'psysh_test_history');
     if (false === file_put_contents($this->historyFile, "_HiStOrY_V2_\n")) {
         $this->fail('Unable to write history file: ' . $this->historyFile);
     }
     // Calling readline_read_history before readline_clear_history
     // avoids segfault with PHP 5.5.7 & libedit v3.1
     readline_read_history($this->historyFile);
     readline_clear_history();
 }
 /**
  * Get the appropriate Readline implementation class name.
  *
  * @see self::getReadline
  *
  * @return string
  */
 private function getReadlineClass()
 {
     if ($this->useReadline()) {
         if (GNUReadline::isSupported()) {
             return 'Psy\\Readline\\GNUReadline';
         } elseif (Libedit::isSupported()) {
             return 'Psy\\Readline\\Libedit';
         }
     }
     return 'Psy\\Readline\\Transient';
 }
Example #3
0
 /**
  * Get the Psy Shell readline service.
  *
  * By default, this service uses (in order of preference):
  *
  *  * GNU Readline
  *  * Libedit
  *  * A transient array-based readline emulation.
  *
  * @return Readline
  */
 public function getReadline()
 {
     if (!isset($this->readline)) {
         if ($this->useReadline()) {
             $historyFile = $this->getHistoryFile();
             if (GNUReadline::isSupported()) {
                 $this->readline = new GNUReadline($historyFile);
             } elseif (Libedit::isSupported()) {
                 $this->readline = new Libedit($historyFile);
             } elseif (LibeditTransient::isSupported()) {
                 $this->readline = new LibeditTransient($historyFile);
             }
         }
         if (!isset($this->readline)) {
             $this->readline = new Transient();
         }
     }
     return $this->readline;
 }