Example #1
0
 private function initialize()
 {
     if ($this->reflectionParameter->isArray()) {
         $this->value = Json::toArray($this->value);
     }
     if (!isset($this->value)) {
         if ($this->reflectionParameter->isOptional()) {
             $defaultValue = $this->reflectionParameter->getDefaultValue();
             $this->value = $defaultValue;
         }
     }
     $class = $this->reflectionParameter->getClass();
     if (isset($class)) {
         $this->value = Json::toObject($this->value, $class);
     }
     if (!$this->reflectionParameter->allowsNull() && !isset($this->value)) {
         throw new ArgumentInvalidException($this->name, "Argument [{$this->name}] can't be null.");
     }
 }
Example #2
0
 public function test_json()
 {
     $message = Json::toObject('{"id":12,"content":"hello"}', Message::class);
     var_dump($message);
     $list = Json::toArray("[1,2,3,4,5,6]");
     var_dump($list);
 }