-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve consistency of exception message formatting.
- Loading branch information
Showing
77 changed files
with
376 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Exception; | ||
|
||
use function array_map; | ||
use function bin2hex; | ||
use function implode; | ||
use function is_resource; | ||
use function is_string; | ||
use function json_encode; | ||
use function preg_replace; | ||
use function sprintf; | ||
|
||
final class FormatArray | ||
{ | ||
/** | ||
* Returns a human-readable representation of an array of parameters. | ||
* This properly handles binary data by returning a hex representation. | ||
* | ||
* @param array<mixed, mixed> $array | ||
*/ | ||
public function __invoke(array $array) : string | ||
{ | ||
return '[' . implode(', ', array_map(static function ($param) { | ||
if (is_resource($param)) { | ||
return (string) $param; | ||
} | ||
|
||
$json = @json_encode($param); | ||
|
||
if (! is_string($json) || $json === 'null' && is_string($param)) { | ||
// JSON encoding failed, this is not a UTF-8 string. | ||
return sprintf('"%s"', preg_replace('/.{2}/', '\\x$0', bin2hex($param))); | ||
} | ||
|
||
return $json; | ||
}, $array)) . ']'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Exception; | ||
|
||
use InvalidArgumentException; | ||
use function get_class; | ||
use function get_resource_type; | ||
use function gettype; | ||
use function is_array; | ||
use function is_bool; | ||
use function is_object; | ||
use function is_resource; | ||
use function is_string; | ||
use function sprintf; | ||
|
||
final class FormatVariable | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __invoke($value) : string | ||
{ | ||
if ($value === null) { | ||
return 'NULL'; | ||
} | ||
|
||
if (is_object($value)) { | ||
return get_class($value); | ||
} | ||
|
||
if (is_resource($value)) { | ||
return get_resource_type($value); | ||
} | ||
|
||
if (is_bool($value)) { | ||
return $value === true ? 'true' : 'false'; | ||
} | ||
|
||
if (is_array($value)) { | ||
return 'array'; | ||
} | ||
|
||
if (is_string($value)) { | ||
return $value; | ||
} | ||
|
||
throw new InvalidArgumentException(sprintf('Could not format value of type "%s".', gettype($value))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.