From 38f3aa9857c422f9af9017cfadd58c93a3c2a6eb Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 21 Jun 2026 18:24:19 +0200 Subject: [PATCH] Refactor I/O exceptions --- composer.json | 2 +- src/main/php/img/io/StreamReader.class.php | 4 ++-- src/test/php/img/unittest/GifImageWriterTest.class.php | 4 ++-- src/test/php/img/unittest/ImageReaderTest.class.php | 4 ++-- src/test/php/img/unittest/JpegImageWriterTest.class.php | 4 ++-- src/test/php/img/unittest/PngImageWriterTest.class.php | 4 ++-- src/test/php/img/unittest/WebpImageWriterTest.class.php | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index d4990256..890457c8 100755 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "description" : "Imaging APIs for the XP Framework", "keywords": ["module", "xp"], "require" : { - "xp-framework/core": "^12.0 | ^11.0 | ^10.0", + "xp-framework/core": "^12.11 | ^11.11", "php" : ">=7.4.0", "ext-gd" : "*" }, diff --git a/src/main/php/img/io/StreamReader.class.php b/src/main/php/img/io/StreamReader.class.php index f6501a63..c0ccbaba 100755 --- a/src/main/php/img/io/StreamReader.class.php +++ b/src/main/php/img/io/StreamReader.class.php @@ -1,8 +1,8 @@ reader; try { return $f($this, $this->stream); - } catch (IOException $e) { + } catch (OperationFailed $e) { throw new ImagingException($e->getMessage()); } } diff --git a/src/test/php/img/unittest/GifImageWriterTest.class.php b/src/test/php/img/unittest/GifImageWriterTest.class.php index 8ac7bba4..b307fb6a 100755 --- a/src/test/php/img/unittest/GifImageWriterTest.class.php +++ b/src/test/php/img/unittest/GifImageWriterTest.class.php @@ -2,7 +2,7 @@ use img\ImagingException; use img\io\GifStreamWriter; -use io\IOException; +use io\OperationFailed; use io\streams\{MemoryOutputStream, OutputStream}; use test\{Assert, Expect, Test}; @@ -12,7 +12,7 @@ class GifImageWriterTest extends AbstractImageWriterTest { #[Test, Expect(ImagingException::class)] public function write_error() { $this->image->saveTo(new GifStreamWriter(new class() implements OutputStream { - public function write($arg) { throw new IOException('Could not write: Intentional exception'); } + public function write($arg) { throw new OperationFailed('Could not write: Intentional exception'); } public function flush() { } public function close() { } })); diff --git a/src/test/php/img/unittest/ImageReaderTest.class.php b/src/test/php/img/unittest/ImageReaderTest.class.php index 473943e0..d5c2428e 100755 --- a/src/test/php/img/unittest/ImageReaderTest.class.php +++ b/src/test/php/img/unittest/ImageReaderTest.class.php @@ -2,7 +2,7 @@ use img\io\PngStreamReader; use img\{Image, ImagingException}; -use io\IOException; +use io\OperationFailed; use io\streams\{InputStream, MemoryInputStream}; use test\{Expect, Test}; @@ -12,7 +12,7 @@ class ImageReaderTest { #[Test, Expect(ImagingException::class)] public function readError() { Image::loadFrom(new PngStreamReader(new class() implements InputStream { - public function read($limit= 8192) { throw new IOException('Could not read: Intentional exception'); } + public function read($limit= 8192) { throw new OperationFailed('Could not read: Intentional exception'); } public function available() { return 1; } public function close() { } })); diff --git a/src/test/php/img/unittest/JpegImageWriterTest.class.php b/src/test/php/img/unittest/JpegImageWriterTest.class.php index c6730162..422a6d70 100755 --- a/src/test/php/img/unittest/JpegImageWriterTest.class.php +++ b/src/test/php/img/unittest/JpegImageWriterTest.class.php @@ -2,7 +2,7 @@ use img\ImagingException; use img\io\JpegStreamWriter; -use io\IOException; +use io\OperationFailed; use io\streams\{MemoryOutputStream, OutputStream}; use test\{Assert, Expect, Test}; @@ -12,7 +12,7 @@ class JpegImageWriterTest extends AbstractImageWriterTest { #[Test, Expect(ImagingException::class)] public function write_error() { $this->image->saveTo(new JpegStreamWriter(new class() implements OutputStream { - public function write($arg) { throw new IOException('Could not write: Intentional exception'); } + public function write($arg) { throw new OperationFailed('Could not write: Intentional exception'); } public function flush() { } public function close() { } })); diff --git a/src/test/php/img/unittest/PngImageWriterTest.class.php b/src/test/php/img/unittest/PngImageWriterTest.class.php index 8e2b430b..44fafb7e 100755 --- a/src/test/php/img/unittest/PngImageWriterTest.class.php +++ b/src/test/php/img/unittest/PngImageWriterTest.class.php @@ -2,7 +2,7 @@ use img\ImagingException; use img\io\PngStreamWriter; -use io\IOException; +use io\OperationFailed; use io\streams\{MemoryOutputStream, OutputStream}; use test\{Assert, Expect, Test}; @@ -15,7 +15,7 @@ protected function imageType() { return 'PNG'; } #[Test, Expect(ImagingException::class)] public function write_error() { $this->image->saveTo(new PngStreamWriter(new class() implements OutputStream { - public function write($arg) { throw new IOException('Could not write: Intentional exception'); } + public function write($arg) { throw new OperationFailed('Could not write: Intentional exception'); } public function flush() { } public function close() { } })); diff --git a/src/test/php/img/unittest/WebpImageWriterTest.class.php b/src/test/php/img/unittest/WebpImageWriterTest.class.php index 95c9a5a6..a9ed39fa 100755 --- a/src/test/php/img/unittest/WebpImageWriterTest.class.php +++ b/src/test/php/img/unittest/WebpImageWriterTest.class.php @@ -2,7 +2,7 @@ use img\ImagingException; use img\io\WebpStreamWriter; -use io\IOException; +use io\OperationFailed; use io\streams\{MemoryOutputStream, OutputStream}; use test\{Assert, Expect, Test}; @@ -12,7 +12,7 @@ class WebpImageWriterTest extends AbstractImageWriterTest { #[Test, Expect(ImagingException::class)] public function write_error() { $this->image->saveTo(new WebpStreamWriter(new class() implements OutputStream { - public function write($arg) { throw new IOException('Could not write: Intentional exception'); } + public function write($arg) { throw new OperationFailed('Could not write: Intentional exception'); } public function flush() { } public function close() { } }));