| @@ 10-35 (lines=26) @@ | ||
| 7 | /** |
|
| 8 | * Parser for PHP serialized boolean |
|
| 9 | */ |
|
| 10 | class BooleanParser implements ParserInterface |
|
| 11 | { |
|
| 12 | /** @var ParserInterface $parser internal parser for boolean parsing */ |
|
| 13 | private $parser; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * constructor |
|
| 17 | */ |
|
| 18 | public function __construct() |
|
| 19 | { |
|
| 20 | $this->parser = new RegexpSubstringParser('/\Gb:[01];/', 2, 1); |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * parse given `$source` as PHP serialized boolean |
|
| 25 | * |
|
| 26 | * @param Source $source parser input |
|
| 27 | * @return array |
|
| 28 | * @throws UnserializeFailedException |
|
| 29 | */ |
|
| 30 | public function parse(Source $source) |
|
| 31 | { |
|
| 32 | list($result, $source) = $this->parser->parse($source); |
|
| 33 | return array($result === '1', $source); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 10-35 (lines=26) @@ | ||
| 7 | /** |
|
| 8 | * Parser for PHP serialized integer |
|
| 9 | */ |
|
| 10 | class IntegerParser implements ParserInterface |
|
| 11 | { |
|
| 12 | /** @var ParserInterface $parser internal parser for integer parsing */ |
|
| 13 | private $parser; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * constructor |
|
| 17 | */ |
|
| 18 | public function __construct() |
|
| 19 | { |
|
| 20 | $this->parser = new RegexpSubstringParser('/\Gi:[+-]?[0-9]+;/', 2, -1); |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * parse given `$source` as PHP serialized integer |
|
| 25 | * |
|
| 26 | * @param Source $source parser input |
|
| 27 | * @return array |
|
| 28 | * @throws UnserializeFailedException |
|
| 29 | */ |
|
| 30 | public function parse(Source $source) |
|
| 31 | { |
|
| 32 | list($result, $source) = $this->parser->parse($source); |
|
| 33 | return array(intval($result, 10), $source); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||