/** * 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); }
/** * set any value to object at any point in object structure defined by second parameter which can be a path or * path/query array value. the fourth parameter defines if the object is extendable that when nothing was found at * path/query the value will be created/append there. the fifth parameter is an optional position value, see * Xapp_Util_Std_Query::set for more details. the last optional parameter defines whether the value will only be set * /overwritten if the to be replaced value is of the same type. will throw result exception if path/query does not * return any value and fourth parameter is to false * * @error 17021 * @see Xapp_Util_Std_Query::find * @see Xapp_Util_Std_Query::retrieve * @param object $object expects the object to set values to * @param null|string|array $mixed expects either null for connected query call, string for path or array for path/query * @param null|mixed $value expects the value to set at second parameter * @param bool $extend expects optional extend value as explained above * @param null|string|int $position expects optional set position as explained in Xapp_Util_Std_Query::set * @param bool $typesafe expects optional typesafe value as explained above * @throws Xapp_Result_Exception * @throws Xapp_Util_Std_Exception */ public static function _set(&$object, $mixed = null, $value = null, $extend = true, $position = null, $typesafe = false) { $last = null; $parent = null; $extend = (bool) $extend; $typesafe = (bool) $typesafe; if ($mixed === null) { $mixed = ''; } else { if (is_array($mixed)) { $mixed[0] = trim($mixed[0], './* '); } else { if (is_string($mixed)) { $mixed = trim($mixed, './* '); } } } try { if ($value === '__REMOVE__' && is_string($mixed)) { if (substr($mixed, 0, 1) !== '/' && strpos($mixed, '/') !== false) { $last = substr($mixed, strrpos($mixed, '/') + 1); $mixed = substr($mixed, 0, strrpos($mixed, '/')); } else { $last = $mixed; $mixed = ''; } } if (is_array($mixed) && sizeof($mixed) >= 2) { if (array_key_exists(2, $mixed)) { $mixed[2] = strtolower(trim((string) $mixed[2])); } else { $mixed[2] = 'first'; } $result =& Xapp_Util_Std_Query::find($object, $mixed[0], (array) $mixed[1], $mixed[2], $parent); } else { $result =& Xapp_Util_Std_Query::retrieve($object, $mixed, false, $parent); } } catch (Xapp_Result_Exception $e) { $result = false; } if ($result !== false) { if (is_array($result)) { if ($value === '__REMOVE__') { unset($result[(int) $last]); } else { if ($value === '__RESET__') { $result = null; } else { if ($value === '__SERIALIZE__') { $result = self::encode($result); } else { if ($position !== null) { if ($position === -1 || $position === 'last') { array_push($result, $value); } else { if ($position === 0 || $position === 'first') { array_unshift($result, $value); } else { if (is_int($position)) { if ($position < sizeof($result)) { array_splice($result, $position, 0, array($value)); } else { array_push($result, $value); } } } } } else { if ($typesafe) { if (xapp_type($result) === xapp_type($value)) { $result = $value; } else { throw new Xapp_Util_Std_Exception(_("value found at path can not be overwritten due to typesafe protection"), 1702101); } } else { $result = $value; } } } } } } else { if ($value === '__REMOVE__') { unset($result->{$last}); } else { if ($value === '__RESET__') { $result = null; } else { if ($value === '__SERIALIZE__') { $result = self::encode($result); } else { if ($position !== null) { if ($position === -1 || $position === 'last') { $result = (object) array_merge((array) $result, (array) $value); } else { if ($position === 0 || $position === 'first') { $result = (object) array_merge((array) $value, (array) $result); } else { if (is_int($position)) { if ($position < sizeof((array) $result)) { $result = (object) array_merge(array_slice((array) $result, 0, $position), (array) $value, array_slice((array) $result, $position)); } else { $result = (object) array_merge((array) $result, (array) $value); } } } } } else { if ($typesafe) { if (xapp_type($result) === xapp_type($value)) { $result = $value; } else { throw new Xapp_Util_Std_Exception(_("value found at path can not be overwritten due to typesafe protection"), 1702101); } } else { $result = $value; } } } } } } } else { if ($extend && is_object($parent)) { $parent->{trim(substr($mixed, strrpos($mixed, '/') + 1))} = $value; } else { throw new Xapp_Result_Exception(_("no result found for query"), 1702102); } } }