Example #1
0
 /**
  * Closes down stream
  * @return boolean
  */
 function close()
 {
     if (is_resource($this->pointer)) {
         $result = fclose($this->pointer);
         parent::close();
         return $result;
     }
     return false;
 }
Example #2
0
 /**
  * Handles query invocation
  * @return mixed
  */
 public function __invoke()
 {
     $result = call_user_func_array([$this, 'invoke'], func_get_args());
     $e = new observr\Event($this, ['result' => &$result]);
     if (!isset($this->stream)) {
         throw new xral\Exception('No resource specified');
     }
     if ($this->stream->isWrite()) {
         $this->attach(self::COMPLETE, function () use($result, $e) {
             if ($this->hasObservers(self::SAVE)) {
                 $this->setState(self::SAVE, new observr\Event($this, ['result' => $e['result']]));
                 $this->clearState(self::SAVE);
             }
         });
     }
     $this->setState(self::COMPLETE, $e);
     if (!$e->canceled) {
         $result = $e['result'];
     }
     if ($this->stream->isOpen()) {
         $this->stream->close();
     }
     return $result;
 }
Example #3
0
 /**
  * Helper function using stream_copy_to_stream
  * @param \qio\Resource\Stream $stream
  * @param integer $maxlength
  * @param integer $offset
  */
 public function copyTo(Stream $stream, $maxlength = -1, $offset = 0)
 {
     if ($this->isOpen()) {
         $destination = $stream->getPointer();
         stream_copy_to_stream($this->pointer, $destination, $maxlength, $offset);
     }
 }