GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
CommandReader Class Reference

Public Member Functions

 __construct ()
 
 shutdown ()
 
 quit ()
 
 getLine ()
 
 run ()
 
 getThreadName ()
 
- Public Member Functions inherited from Thread
 getClassLoader ()
 
 setClassLoader (\ClassLoader $loader=null)
 
 registerClassLoader ()
 
 start (int $options=PTHREADS_INHERIT_ALL)
 
 quit ()
 
 getThreadName ()
 
- Public Member Functions inherited from Thread
 getCreatorId ()
 
 getThreadId ()
 
 isJoined ()
 
 isStarted ()
 
 join ()
 
 start (int $options=PTHREADS_INHERIT_ALL)
 
- Public Member Functions inherited from Threaded
 chunk ($size, bool $preserve=false)
 
 count ()
 
 isRunning ()
 
 isTerminated ()
 
 merge ($from, $overwrite=true)
 
 notify ()
 
 notifyOne ()
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 pop ()
 
 run ()
 
 shift ()
 
 synchronized (\Closure $function, $args=null)
 
 wait ($timeout)
 
 getRefCount ()
 
 addRef ()
 
 delRef ()
 
 isGarbage ()
 

Data Fields

const TYPE_READLINE = 0
 
const TYPE_STREAM = 1
 
const TYPE_PIPED = 2
 

Protected Attributes

 $buffer
 
- Protected Attributes inherited from Thread
 $classLoader
 
 $isKilled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Thread
static getCurrentThread ()
 
static getCurrentThreadId ()
 
- Static Public Member Functions inherited from Threaded
static extend ($obj)
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

CommandReader constructor.

44  {
45  $this->buffer = new \Threaded;
46 
47  $opts = getopt("", ["disable-readline"]);
48  if((extension_loaded("readline") and !isset($opts["disable-readline"]) and !$this->isPipe(STDIN))){
49  $this->type = self::TYPE_READLINE;
50  }
51 
52  $this->start();
53  }

Member Function Documentation

◆ getLine()

getLine ( )

Reads a line from console, if available. Returns null if not available

Returns
string|null
167  {
168  if($this->buffer->count() !== 0){
169  return $this->buffer->shift();
170  }
171 
172  return null;
173  }

◆ getThreadName()

getThreadName ( )
Returns
string
192  {
193  return "Console";
194  }

◆ quit()

quit ( )
59  {
60  $wait = microtime(true) + 0.5;
61  while(microtime(true) < $wait){
62  if($this->isRunning()){
63  usleep(100000);
64  }else{
65  parent::quit();
66  return;
67  }
68  }
69 
70  $message = "Thread blocked for unknown reason";
71  if($this->type === self::TYPE_PIPED){
72  $message = "STDIN is being piped from another location and the pipe is blocked, cannot stop safely";
73  }
74 
75  throw new \ThreadException($message);
76  }

◆ run()

run ( )
175  {
176  if($this->type !== self::TYPE_READLINE){
177  $this->initStdin();
178  }
179 
180  while(!$this->shutdown and $this->readLine()) ;
181 
182  if($this->type !== self::TYPE_READLINE){
183  global $stdin;
184  fclose($stdin);
185  }
186 
187  }

◆ shutdown()

shutdown ( )
55  {
56  $this->shutdown = true;
57  }

Field Documentation

◆ $buffer

$buffer
protected

◆ TYPE_PIPED

const TYPE_PIPED = 2

◆ TYPE_READLINE

const TYPE_READLINE = 0

◆ TYPE_STREAM

const TYPE_STREAM = 1

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