1
0
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:
Aaron Piotrowski 2017-12-18 00:17:55 -06:00
parent 82e439c111
commit 67b821343f
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -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 {