Ejemplo n.º 1
0
 /**
  * Initialize streams
  *
  * @param  bool console
  */
 public static function initialize($console)
 {
     if ($console) {
         self::$in = new StringReader(new ConsoleInputStream(STDIN));
         self::$out = new StringWriter(new ConsoleOutputStream(STDOUT));
         self::$err = new StringWriter(new ConsoleOutputStream(STDERR));
     } else {
         self::$in = newinstance('io.streams.InputStreamReader', [null], '{
     public function __construct($in) { }
     public function getStream() { return null; }
     public function raise() { throw new \\lang\\IllegalStateException("There is no console present"); }
     public function read($count= 8192) { $this->raise(); }
     public function readLine() { $this->raise(); }
   }');
         self::$out = self::$err = newinstance('io.streams.OutputStreamWriter', [null], '{
     public function __construct($out) { }
     public function getStream() { return null; }
     public function flush() { $this->raise(); }
     public function raise() { throw new \\lang\\IllegalStateException("There is no console present"); }
     public function write() { $this->raise(); }
     public function writeLine() { $this->raise(); }
     public function writef() { $this->raise(); }
     public function writeLinef() { $this->raise(); }
   }');
     }
 }
Ejemplo n.º 2
0
 /**
  * Initialize streams
  *
  * @param  bool $console
  */
 public static function initialize($console)
 {
     if ($console) {
         self::$in = new StringReader(new ConsoleInputStream(STDIN));
         self::$out = new StringWriter(new ConsoleOutputStream(STDOUT));
         self::$err = new StringWriter(new ConsoleOutputStream(STDERR));
     } else {
         self::$in = new class(null) implements InputStreamReader
         {
             public function __construct($in)
             {
             }
             public function getStream()
             {
                 return null;
             }
             public function raise()
             {
                 throw new IllegalStateException('There is no console present');
             }
             public function read($count = 8192)
             {
                 $this->raise();
             }
             public function readLine()
             {
                 $this->raise();
             }
         };
         self::$out = self::$err = new class(null) implements OutputStreamWriter
         {
             public function __construct($out)
             {
             }
             public function getStream()
             {
                 return null;
             }
             public function flush()
             {
                 $this->raise();
             }
             public function raise()
             {
                 throw new IllegalStateException('There is no console present');
             }
             public function write(...$args)
             {
                 $this->raise();
             }
             public function writeLine(...$args)
             {
                 $this->raise();
             }
             public function writef($format, ...$args)
             {
                 $this->raise();
             }
             public function writeLinef($format, ...$args)
             {
                 $this->raise();
             }
         };
     }
 }