Exemplo n.º 1
0
 /**
  * class constructor for json store implementation. see Xapp_Util_Std_Store::__constructor for more details
  *
  * @error 16901
  * @see Xapp_Util_Std_Store::__constructor
  * @param null|mixed $mixed expects one of the above value options
  * @param null|mixed $options expects optional class instance options
  * @throws Xapp_Util_Json_Exception
  */
 public function __construct($mixed = null, $options = null)
 {
     xapp_init_options($options, $this);
     if ($mixed !== null) {
         if (is_object($mixed)) {
             $this->_object =& $mixed;
         } else {
             if (is_array($mixed)) {
                 $this->_object = Xapp_Util_Json::convert($mixed);
             } else {
                 if (is_file($mixed)) {
                     $this->_file = $mixed;
                     if (($mixed = file_get_contents($mixed)) !== false) {
                         $this->_object = Xapp_Util_Json::decode($mixed);
                     } else {
                         throw new Xapp_Util_Json_Exception("unable to read from file: {$mixed}", 1690101);
                     }
                 } else {
                     if (is_string($mixed) && Xapp_Util_Json::isJson($mixed)) {
                         $this->_object = Xapp_Util_Json::decode($mixed);
                     } else {
                         if (is_string($mixed) && strpos($mixed, '.') !== false && is_writeable(dirname($mixed))) {
                             $this->_file = $mixed;
                         } else {
                             throw new Xapp_Util_Json_Exception("passed first argument in constructor is not a valid object or file path", 1690102);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * class constructor checks if passed object is a json string and decodes then first, than
  * calls parent constructor
  *
  * @error 16801
  * @param array|object|string $object expects the json object or json string
  * @param null|mixed $options expects optional options
  */
 public function __construct(&$object, $options = null)
 {
     if (Xapp_Util_Json::isJson($object)) {
         $object = Xapp_Util_Json::decode($object);
     }
     parent::__construct($object, $options);
 }