Beispiel #1
0
 /**
  * Converts json string to array and sets local access property
  * @param string $input
  * @return array
  */
 public function fromJSON($input)
 {
     if ($this instanceof Interfaces\Collection) {
         $this->fromArray((array) JSONUtil::decode($input));
         return $input;
     }
     $property = defined('static::$DOMAIN_PROPERTY') ? static::$DOMAIN_PROPERTY : 'data';
     $this->{$property} = (array) JSONUtil::decode($input);
     return $input;
 }
Beispiel #2
0
 public function readPacket($json)
 {
     $json_data = \qtil\JSONUtil::decode($json);
     //TODO: VALIDATE JSON SCHEMA
     if (is_object($json_data) && isset($json_data->id)) {
         $data = [];
         if (isset($json_data->data)) {
             $data = $json_data->data;
         }
         $packet = false;
         try {
             $packet = $this->builder->link($json_data->id, [$json_data->id, $data]);
             $packet->id = $json_data->id;
             $packet->data = $data;
         } catch (\BadMethodCallException $e) {
             $packet = new qtcp\Network\Packet($json_data->id, (array) $data);
         }
         return $packet;
     }
     return false;
 }