Skip to content

Commit

Permalink
Accept io.Channel|io.streams.InputStream, remove io.Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 1, 2017
1 parent 7da96fd commit 5e31f10
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
11 changes: 9 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ Imaging APIs for the XP Framework ChangeLog

## ?.?.? / ????-??-??

## 8.0.0 / 2017-08-01

* **Heads up:** Removed support for deprecated `io.Stream` instances
(@thekid)
* Changed Stream(Reader|Writer) constructors to accept `io.Channel`
instances as well as `io.streams.InputStream`.
(@thekid)
* Added constants `Image::TRUECOLOR` and `Image::PALETTE`, deprecating
the global defines with the same name and an `IMG_` prefix
(@thekid)
* **Heads up:** Dropped PHP 5.5 support, minimum PHP version is now
PHP 5.6.
* **Heads up:** Added forward compatibility with XP 9; dropped PHP 5.5
support, minimum PHP version is now PHP 5.6.
(@thekid)

## 7.1.1 / 2017-05-20
Expand Down
19 changes: 5 additions & 14 deletions src/main/php/img/io/StreamReader.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace img\io;

use io\Stream;
use io\File;
use io\Channel;
use io\IOException;
use io\streams\InputStream;
use io\streams\Streams;
Expand All @@ -23,24 +22,16 @@ class StreamReader implements ImageReader {
/**
* Constructor
*
* @param var $arg either an io.streams.InputStream, an io.File or an io.Stream (BC)
* @throws lang.IllegalArgumentException when types are not met
* @param io.streams.InputStream|io.Channel $arg
* @throws lang.IllegalArgumentException when types are not met
*/
public function __construct($arg) {
if ($arg instanceof InputStream) {
$this->read($arg);
} else if ($arg instanceof File) {
} else if ($arg instanceof Channel) {
$this->read($arg->in());
} else if ($arg instanceof Stream) { // BC
$this->stream= $arg;
$this->reader= function($reader, $stream) {
$stream->open(STREAM_MODE_READ);
$bytes= $stream->read($stream->size());
$stream->close();
return $reader->readImageFromString($bytes);
};
} else {
throw new IllegalArgumentException('Expected either an io.streams.InputStream or an io.File, have '.typeof($this->stream)->getName());
throw new IllegalArgumentException('Expected either an io.streams.InputStream or an io.Channel, have '.typeof($this->stream)->getName());
}
}

Expand Down
23 changes: 5 additions & 18 deletions src/main/php/img/io/StreamWriter.class.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php namespace img\io;

use io\streams\OutputStream;
use io\Stream;
use io\File;
use io\Channel;
use lang\IllegalArgumentException;
use lang\Throwable;
use img\ImagingException;
Expand All @@ -22,28 +21,16 @@ abstract class StreamWriter implements ImageWriter {
/**
* Constructor
*
* @param var $arg either an io.streams.OutputStream, an io.File or an io.Stream (BC)
* @throws lang.IllegalArgumentException when types are not met
* @param io.streams.InputStream|io.Channel $arg
* @throws lang.IllegalArgumentException when types are not met
*/
public function __construct($arg) {
if ($arg instanceof OutputStream) {
$this->write($arg);
} else if ($arg instanceof File) {
} else if ($arg instanceof Channel) {
$this->write($arg->out());
} else if ($arg instanceof Stream) { // BC
$this->stream= $arg;
$this->writer= function($writer, $stream, $handle) {
ob_start();
if ($r= $writer->output($handle)) {
$stream->open(STREAM_MODE_WRITE);
$stream->write(ob_get_contents());
$stream->close();
}
ob_end_clean();
return $r;
};
} else {
throw new IllegalArgumentException('Expected either an io.streams.OutputStream or an io.File, have '.type($arg)->getName());
throw new IllegalArgumentException('Expected either an io.streams.OutputStream or an io.Channel, have '.type($arg)->getName());
}
}

Expand Down

0 comments on commit 5e31f10

Please sign in to comment.