Example #1
0
 /**
  * Write the given image
  * @param string $filename
  * @param Stream $image
  */
 private function writeImage($filename, Stream $image)
 {
     $filename = $this->getDestinationPath($filename);
     $resource = $image->detach();
     $config = ['visibility' => 'public', 'mimetype' => Mimetypes::getInstance()->fromFilename($filename)];
     if ($this->fileExists($filename)) {
         return $this->filesystem->disk($this->getConfiguredFilesystem())->updateStream($filename, $resource, $config);
     }
     $this->filesystem->disk($this->getConfiguredFilesystem())->writeStream($filename, $resource, $config);
 }
Example #2
0
 public function testCanDetachStream()
 {
     $r = fopen('php://temp', 'w+');
     $stream = new Stream($r);
     $stream->write('foo');
     $this->assertTrue($stream->isReadable());
     $this->assertSame($r, $stream->detach());
     $stream->detach();
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isSeekable());
     $self = $this;
     $throws = function ($fn) use($stream, $self) {
         try {
             $fn($stream);
             $self->fail();
         } catch (\Exception $e) {
         }
     };
     $throws(function ($stream) {
         $stream->read(10);
     });
     $throws(function ($stream) {
         $stream->write('bar');
     });
     $throws(function ($stream) {
         $stream->seek(10);
     });
     $throws(function ($stream) {
         $stream->tell();
     });
     $throws(function ($stream) {
         $stream->eof();
     });
     $throws(function ($stream) {
         $stream->getSize();
     });
     $throws(function ($stream) {
         $stream->getContents();
     });
     $this->assertSame('', (string) $stream);
     $stream->close();
 }