mirror of
https://github.com/danog/postgres.git
synced 2024-12-02 09:27:54 +01:00
Move initial data validation out of generator parser
This commit is contained in:
parent
82e439c111
commit
67b821343f
@ -15,6 +15,12 @@ class ArrayParser {
|
||||
* @throws \Amp\Postgres\ParseException
|
||||
*/
|
||||
public function parse(string $data, callable $cast = null, string $delimiter = ','): array {
|
||||
$data = \trim($data);
|
||||
|
||||
if ($data[0] !== '{' || \substr($data, -1) !== '}') {
|
||||
throw new ParseException("Missing opening or closing brackets");
|
||||
}
|
||||
|
||||
$parser = $this->parser($data, $cast, $delimiter);
|
||||
$data = \iterator_to_array($parser);
|
||||
|
||||
@ -26,12 +32,6 @@ class ArrayParser {
|
||||
}
|
||||
|
||||
private function parser(string $data, callable $cast = null, string $delimiter = ','): \Generator {
|
||||
$data = \trim($data);
|
||||
|
||||
if ($data[0] !== '{' || \substr($data, -1) !== '}') {
|
||||
throw new ParseException("Missing opening or closing brackets");
|
||||
}
|
||||
|
||||
$data = \ltrim(\substr($data, 1));
|
||||
|
||||
do {
|
||||
|
Loading…
Reference in New Issue
Block a user