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