mirror of
https://github.com/danog/postgres.git
synced 2024-12-03 09:57:48 +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
|
* @throws \Amp\Postgres\ParseException
|
||||||
*/
|
*/
|
||||||
public function parse(string $data, callable $cast = null, string $delimiter = ','): array {
|
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);
|
$parser = $this->parser($data, $cast, $delimiter);
|
||||||
$data = \iterator_to_array($parser);
|
$data = \iterator_to_array($parser);
|
||||||
|
|
||||||
@ -26,12 +32,6 @@ class ArrayParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function parser(string $data, callable $cast = null, string $delimiter = ','): \Generator {
|
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));
|
$data = \ltrim(\substr($data, 1));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
Loading…
Reference in New Issue
Block a user