Example #1
0
 public function getMetadata($key = null)
 {
     $this->assertOpen();
     $meta = ['timed_out' => false, 'blocked' => false, 'eof' => $this->isEof(), 'unread_bytes' => 0, 'stream_type' => 'MEMORY', 'wrapper_type' => '', 'wrapper_data' => null, 'mode' => $this->mode->getMode(), 'seekable' => false, 'uri' => 'binsoul://null'];
     if ($key === null) {
         return $meta;
     }
     if (!array_key_exists($key, $meta)) {
         return;
     }
     return $meta[$key];
 }
Example #2
0
 public function open(AccessMode $mode)
 {
     if ($this->handle) {
         throw new \LogicException(sprintf('The stream "%s" is already open.', $this->uri));
     }
     $handle = @fopen($this->uri, $mode->getMode());
     if ($handle === false) {
         throw new \RuntimeException(sprintf('The stream "%s" cannot be opened.', $this->uri));
     }
     if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
         throw new \InvalidArgumentException(sprintf('The stream "%s" is not of type "stream".', $this->uri));
     }
     $this->mode = $mode;
     $this->handle = $handle;
     return true;
 }