1 | <?php |
||
13 | class JsonReader extends ModelA { |
||
14 | private $sJsonString; |
||
15 | private $oPayload; |
||
16 | |||
17 | 1 | public function __construct() { |
|
18 | 1 | if (!extension_loaded('json')) { |
|
19 | throw new ExceptionUnimplemented('The JSON extension is not loaded'); |
||
20 | } |
||
21 | 1 | parent::__construct(); |
|
22 | 1 | } |
|
23 | |||
24 | 1 | public function setString($sString) { |
|
27 | |||
28 | 1 | public function getString() { |
|
31 | |||
32 | 1 | public function __get($sIncName = null) { |
|
33 | try { |
||
34 | 1 | $oProperty = new \ReflectionProperty($this, $sIncName); |
|
35 | if ($oProperty->isPublic()) { |
||
36 | return $oProperty->getValue($this); |
||
37 | } |
||
38 | 1 | } catch (\ReflectionException $e) { |
|
39 | // |
||
40 | } |
||
41 | 1 | return parent::__get($sIncName); |
|
42 | } |
||
43 | |||
44 | 1 | public function __set($sIncName, $mValue) { |
|
45 | 1 | if (is_null($sIncName)) { |
|
46 | throw new \ReflectionException('Can\'t set a value to a null property on the current object [' . get_class($this) . ']'); |
||
47 | } |
||
48 | try { |
||
49 | 1 | $oProperty = new \ReflectionProperty($this->oPayload, $sIncName); |
|
50 | if ($oProperty->isPublic()) { |
||
51 | $oProperty->setValue($this->oPayload, $mValue); |
||
52 | } |
||
53 | return; |
||
54 | 1 | } catch (\ReflectionException $e) { |
|
55 | 1 | $this->$sIncName = $mValue; |
|
56 | } |
||
57 | 1 | } |
|
58 | |||
59 | /** |
||
60 | * @param integer $iError |
||
61 | * @return string |
||
62 | */ |
||
63 | 5 | public static function getError($iError) { |
|
81 | |||
82 | 1 | public function buildObj() { |
|
83 | 1 | $oPayload = json_decode($this->sJsonString); |
|
84 | 1 | $iLastError = json_last_error(); |
|
93 | } |
||
94 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.