| @@ 12-43 (lines=32) @@ | ||
| 9 | ||
| 10 | namespace Rafrsr\LibArray2Object\Parser; |
|
| 11 | ||
| 12 | class IntegerParser implements ValueParserInterface |
|
| 13 | { |
|
| 14 | const NAME = 'integer'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @inheritDoc |
|
| 18 | */ |
|
| 19 | public function getName() |
|
| 20 | { |
|
| 21 | return self::NAME; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @inheritDoc |
|
| 26 | */ |
|
| 27 | public function toObjectValue($value, $type, \ReflectionProperty $property, $object) |
|
| 28 | { |
|
| 29 | if ($type === 'integer' || $type === 'int') { |
|
| 30 | return (integer)$value; |
|
| 31 | } |
|
| 32 | ||
| 33 | return $value; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @inheritDoc |
|
| 38 | */ |
|
| 39 | public function toArrayValue($value, $type, \ReflectionProperty $property, $object) |
|
| 40 | { |
|
| 41 | return $value; |
|
| 42 | } |
|
| 43 | } |
|
| @@ 12-43 (lines=32) @@ | ||
| 9 | ||
| 10 | namespace Rafrsr\LibArray2Object\Parser; |
|
| 11 | ||
| 12 | class StringParser implements ValueParserInterface |
|
| 13 | { |
|
| 14 | const NAME = 'string'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @inheritDoc |
|
| 18 | */ |
|
| 19 | public function getName() |
|
| 20 | { |
|
| 21 | return self::NAME; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @inheritDoc |
|
| 26 | */ |
|
| 27 | public function toObjectValue($value, $type, \ReflectionProperty $property, $object) |
|
| 28 | { |
|
| 29 | if ($type === 'string') { |
|
| 30 | return (string)$value; |
|
| 31 | } |
|
| 32 | ||
| 33 | return $value; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @inheritDoc |
|
| 38 | */ |
|
| 39 | public function toArrayValue($value, $type, \ReflectionProperty $property, $object) |
|
| 40 | { |
|
| 41 | return $value; |
|
| 42 | } |
|
| 43 | } |
|