Skip to content

Commit

Permalink
Rework deprecated IBMDB2 exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jun 24, 2020
1 parent 2eab085 commit 569ca39
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Doctrine\DBAL\Driver\IBMDB2;

use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCopyStreamToStream;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCreateTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotWriteToTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
Expand Down Expand Up @@ -522,7 +525,7 @@ private function createTemporaryFile()
$handle = @tmpfile();

if ($handle === false) {
throw new DB2Exception('Could not create temporary file: ' . error_get_last()['message']);
throw CannotCreateTemporaryFile::new(error_get_last()['message']);
}

return $handle;
Expand All @@ -537,7 +540,7 @@ private function createTemporaryFile()
private function copyStreamToStream($source, $target): void
{
if (@stream_copy_to_stream($source, $target) === false) {
throw new DB2Exception('Could not copy source stream to temporary file: ' . error_get_last()['message']);
throw CannotCopyStreamToStream::new(error_get_last()['message']);
}
}

Expand All @@ -549,7 +552,7 @@ private function copyStreamToStream($source, $target): void
private function writeStringToStream(string $string, $target): void
{
if (@fwrite($target, $string) === false) {
throw new DB2Exception('Could not write string to temporary file: ' . error_get_last()['message']);
throw CannotWriteToTemporaryFile::new(error_get_last()['message']);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\IBMDB2\Exception;

use Doctrine\DBAL\Driver\IBMDB2\DB2Exception;

/**
* @internal
*
* @psalm-immutable
*/
final class CannotCopyStreamToStream extends DB2Exception
{
public static function new(string $message): self
{
return new self('Could not copy source stream to temporary file: ' . $message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\IBMDB2\Exception;

use Doctrine\DBAL\Driver\IBMDB2\DB2Exception;

/**
* @internal
*
* @psalm-immutable
*/
final class CannotCreateTemporaryFile extends DB2Exception
{
public static function new(string $message): self
{
return new self('Could not create temporary file: ' . $message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\IBMDB2\Exception;

use Doctrine\DBAL\Driver\IBMDB2\DB2Exception;

/**
* @internal
*
* @psalm-immutable
*/
final class CannotWriteToTemporaryFile extends DB2Exception
{
public static function new(string $message): self
{
return new self('Could not write string to temporary file: ' . $message);
}
}

0 comments on commit 569ca39

Please sign in to comment.