Hoa central
Static Public Member Functions | Public Attributes | Static Protected Attributes | Static Private Attributes | List of all members
Hoa\Console\Console Class Reference

Static Public Member Functions

static advancedInteraction ()
 
static restoreInteraction ()
 
static getMode ($pipe=STDIN)
 
static isDirect ($pipe)
 
static isPipe ($pipe)
 
static isRedirection ($pipe)
 
static getTput ()
 

Public Attributes

const IS_FIFO = 0
 
const IS_CHARACTER = 1
 
const IS_DIRECTORY = 2
 
const IS_BLOCK = 3
 
const IS_REGULAR = 4
 
const IS_LINK = 5
 
const IS_SOCKET = 6
 
const IS_WHITEOUT = 7
 

Static Protected Attributes

static $_mode = []
 
static $_tput = null
 

Static Private Attributes

static $_advanced = null
 
static $_old = null
 

Detailed Description

Class .

Util.

Definition at line 49 of file Console.php.

Member Function Documentation

static Hoa\Console\Console::advancedInteraction ( )
static

Prepare the environment for advanced interactions.

Returns
bool

Definition at line 142 of file Console.php.

143  {
144  if (null !== self::$_advanced) {
145  return self::$_advanced;
146  }
147 
148  if (OS_WIN) {
149  return self::$_advanced = false;
150  }
151 
152  if (false === self::isDirect(STDIN)) {
153  return self::$_advanced = false;
154  }
155 
156  self::$_old = Processus::execute('stty -g');
157  Processus::execute('stty -echo -icanon min 1 time 0');
158 
159  return self::$_advanced = true;
160  }
static execute($commandLine, $escape=true)
Definition: Processus.php:1165

Here is the call graph for this function:

static Hoa\Console\Console::getMode (   $pipe = STDIN)
static

Get mode of a certain pipe. Inspired by sys/stat.h.

Parameters
resource$pipePipe.
Returns
int

Definition at line 185 of file Console.php.

186  {
187  $_pipe = (int) $pipe;
188 
189  if (isset(self::$_mode[$_pipe])) {
190  return self::$_mode[$_pipe];
191  }
192 
193  $stat = fstat($pipe);
194 
195  switch ($stat['mode'] & 0170000) {
196  // named pipe (fifo).
197  case 0010000:
198  $mode = self::IS_FIFO;
199 
200  break;
201 
202  // character special.
203  case 0020000:
204  $mode = self::IS_CHARACTER;
205 
206  break;
207 
208  // directory.
209  case 0040000:
210  $mode = self::IS_DIRECTORY;
211 
212  break;
213 
214  // block special.
215  case 0060000:
216  $mode = self::IS_BLOCK;
217 
218  break;
219 
220  // regular.
221  case 0100000:
222  $mode = self::IS_REGULAR;
223 
224  break;
225 
226  // symbolic link.
227  case 0120000:
228  $mode = self::IS_LINK;
229 
230  break;
231 
232  // socket.
233  case 0140000:
234  $mode = self::IS_SOCKET;
235 
236  break;
237 
238  // whiteout.
239  case 0160000:
240  $mode = self::IS_WHITEOUT;
241 
242  break;
243 
244  default:
245  $mode = -1;
246  }
247 
248  return self::$_mode[$_pipe] = $mode;
249  }
static Hoa\Console\Console::getTput ( )
static

Get the current tput instance of the current process.

Returns

Definition at line 306 of file Console.php.

307  {
308  if (null === static::$_tput) {
309  static::$_tput = new Tput();
310  }
311 
312  return static::$_tput;
313  }

Here is the caller graph for this function:

static Hoa\Console\Console::isDirect (   $pipe)
static

Check whether a certain pipe is a character device (keyboard, screen etc.). For example: $ php Mode.php In this case, self::isDirect(STDOUT) will return true.

Parameters
resource$pipePipe.
Returns
bool

Definition at line 261 of file Console.php.

262  {
263  return self::IS_CHARACTER === self::getMode($pipe);
264  }

Here is the caller graph for this function:

static Hoa\Console\Console::isPipe (   $pipe)
static

Check whether a certain pipe is a pipe. For example: $ php Mode.php | foobar In this case, self::isPipe(STDOUT) will return true.

Parameters
resource$pipePipe.
Returns
bool

Definition at line 275 of file Console.php.

276  {
277  return self::IS_FIFO === self::getMode($pipe);
278  }
static Hoa\Console\Console::isRedirection (   $pipe)
static

Check whether a certain pipe is a redirection. For example: $ php Mode.php < foobar In this case, self::isRedirection(STDIN) will return true.

Parameters
resource$pipePipe.
Returns
bool

Definition at line 289 of file Console.php.

290  {
291  $mode = self::getMode($pipe);
292 
293  return
294  self::IS_REGULAR === $mode ||
295  self::IS_DIRECTORY === $mode ||
296  self::IS_LINK === $mode ||
297  self::IS_SOCKET === $mode ||
298  self::IS_BLOCK === $mode;
299  }
static Hoa\Console\Console::restoreInteraction ( )
static

Restore previous interaction options.

Returns
void

Definition at line 167 of file Console.php.

168  {
169  if (null === self::$_old) {
170  return;
171  }
172 
173  Processus::execute('stty ' . self::$_old);
174 
175  return;
176  }
static execute($commandLine, $escape=true)
Definition: Processus.php:1165

Here is the call graph for this function:

Member Data Documentation

Hoa\Console\Console::$_advanced = null
staticprivate

Definition at line 112 of file Console.php.

Hoa\Console\Console::$_mode = []
staticprotected

Definition at line 126 of file Console.php.

Hoa\Console\Console::$_old = null
staticprivate

Definition at line 119 of file Console.php.

Hoa\Console\Console::$_tput = null
staticprotected

Definition at line 133 of file Console.php.

const Hoa\Console\Console::IS_BLOCK = 3

Definition at line 77 of file Console.php.

const Hoa\Console\Console::IS_CHARACTER = 1

Definition at line 63 of file Console.php.

const Hoa\Console\Console::IS_DIRECTORY = 2

Definition at line 70 of file Console.php.

const Hoa\Console\Console::IS_FIFO = 0

Definition at line 56 of file Console.php.

const Hoa\Console\Console::IS_LINK = 5

Definition at line 91 of file Console.php.

const Hoa\Console\Console::IS_REGULAR = 4

Definition at line 84 of file Console.php.

const Hoa\Console\Console::IS_SOCKET = 6

Definition at line 98 of file Console.php.

const Hoa\Console\Console::IS_WHITEOUT = 7

Definition at line 105 of file Console.php.


The documentation for this class was generated from the following file: