Changeset 14146
- Timestamp:
- 12/17/08 22:53:16 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfConsolePlugin/trunk/lib/task/consoleRunTask.class.php
r14145 r14146 39 39 40 40 protected $errorNames = array( 41 E_USER_ERROR => 'User Error',42 E_USER_WARNING => 'User Warning',43 E_USER_NOTICE => 'User Notice',44 E_PARSE => 'Parse Error',45 E_NOTICE => 'Notice',46 E_WARNING => 'Warning',47 E_STRICT => 'Strict Standards',41 E_USER_ERROR => 'User Error', 42 E_USER_WARNING => 'User Warning', 43 E_USER_NOTICE => 'User Notice', 44 E_PARSE => 'Parse Error', 45 E_NOTICE => 'Notice', 46 E_WARNING => 'Warning', 47 E_STRICT => 'Strict Standards', 48 48 E_RECOVERABLE_ERROR => 'Catchable Fatal Error', 49 E_DEPRECATED => 'Deprecated',50 E_USER_DEPRECATED => 'User Deprecated',49 E_DEPRECATED => 'Deprecated', 50 E_USER_DEPRECATED => 'User Deprecated', 51 51 ); 52 52 53 /** 54 * The file to store the history in 55 * @param string $historyFile 56 */ 57 58 protected $historyFile; 59 53 60 54 61 /** … … 63 70 throw new sfException('You need the readline extension enabled to use the console'); 64 71 } 72 73 // since we are in a task, current dir is the project root 74 $this->historyFile = 'cache/console.history'; 65 75 66 76 $this->namespace = 'console'; … … 89 99 set_error_handler(array($this, 'errorHandler')); 90 100 101 $this->initHistory(); 102 91 103 while ($line = trim((readline($this->getPrompt())))) 92 104 { 93 readline_add_history($line);105 $this->addHistoryLine($line); 94 106 $this->nbLines++; 95 107 … … 120 132 } 121 133 } 134 } 135 136 /** 137 * Reads the history file (if any) and adds all lines 138 * to current history 139 */ 140 141 protected function initHistory() 142 { 143 if (!file_exists($this->historyFile)) 144 { 145 touch($this->historyFile); 146 } 147 148 $fp = fopen($this->historyFile, 'r'); 149 while ($line = trim(fgets($fp))) 150 { 151 if (!empty($line)) 152 { 153 readline_add_history($line); 154 } 155 } 156 fclose($fp); 157 } 158 159 /** 160 * Adds a line to the console history 161 * 162 * @param string $line 163 * @return boolean 164 */ 165 166 protected function addHistoryLine($line) 167 { 168 $fp = fopen($this->historyFile, 'a+'); 169 fputs($fp, $line.PHP_EOL); 170 fclose($fp); 171 return readline_add_history($line); 122 172 } 123 173 … … 193 243 protected function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) 194 244 { 195 $this->logSection('console', (isset($map[$errno]) ? $map[$errno] : 'Unknown Error').': '.$errstr);245 echo (isset($this->errorNames[$errno]) ? $this->errorNames[$errno] : 'Unknown Error').': '.$errstr; 196 246 197 247 return true;