设置多维数组的的值
@param string $key
@param $value
@param array $obj
@return array|string
@Author jiaWen.chen
171612
public static function array_set(string $key, $value, array $obj)
    {
        if (is_null($key)) {
            return json_encode($obj);
        }
        $keys = explode('.', $key);
        $tmp = &$obj;
        while (count($keys) > 0) {
            $key = array_shift($keys);

            // If the key doesn't exist at this depth, we will just create an empty array
            // to hold the next value, allowing us to create the arrays to hold final
            // values at the correct depth. Then we'll keep digging into the array.
            if (!isset($tmp[$key]) || !is_array($tmp[$key])) {
                $tmp[$key] = [];
            }

            $tmp = &$tmp[$key];
        }
        $tmp = $value;

        return $obj;
    }
531631
protected function operatorForWhere($key, $operator = null, $value = null)
    {
        if (func_num_args() === 1) {
            $value = true;

            $operator = '=';
        }

        if (func_num_args() === 2) {
            $value = $operator;

            $operator = '=';
        }

        return function ($item) use ($key, $operator, $value) {
            $retrieved = data_get($item, $key);

            $strings = array_filter([$retrieved, $value], function ($value) {
                return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
            });

            if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
                return in_array($operator, ['!=', '<>', '!==']);
            }

            switch ($operator) {
                default:
                case '=':
                case '==':  return $retrieved == $value;
                case '!=':
                case '<>':  return $retrieved != $value;
                case '<':   return $retrieved < $value;
                case '>':   return $retrieved > $value;
                case '<=':  return $retrieved <= $value;
                case '>=':  return $retrieved >= $value;
                case '===': return $retrieved === $value;
                case '!==': return $retrieved !== $value;
            }
        };
    }
1138553
function jsonConverter(value, key, obj) {
    if (value !== null && typeof value === 'object') {
      // Recurse into children
      _.each(value, jsonConverter);
    } else if (typeof value === 'string') {
      // handle special cases (regex/number/date)
      if (key === '$regex') {
        const m = value.match(/\/(.*)\//);
        if (m) {
          if (obj.$options) {
            m[2] = obj.$options;
            // eslint-disable-next-line no-param-reassign
            delete obj.$options;
          }
          // eslint-disable-next-line no-param-reassign
          obj[key] = new RegExp(m[1], m[2]);
        }
      } else if (/^oid:[a-fA-F0-9]{24}$/.test(value)) {
        // eslint-disable-next-line no-param-reassign, prefer-destructuring
        obj[key] = value.split(':')[1];
      } else {
        // check if date to convert it
        const date = parseDateCustom(value);
        if (!Number.isNaN(date)) {
          // eslint-disable-next-line no-param-reassign
          obj[key] = date;
        }
      }
    }
  }
887183
public static function writeJSON($obj, $buf = null)
    {
        $output = json_encode($obj);

        if ($output === false && json_last_error() === JSON_ERROR_UTF8)
        {
            $obj_fixed = Encoding::fixUTF8($obj);
            $output = json_encode($obj_fixed);
            if ($output === false && json_last_error() === JSON_ERROR_UTF8)
            {
                // @codeCoverageIgnoreStart
                // The input has to be extremely weird to trigger this, so
                // in practice it shouldn't happen.  
                $rep = WF::str($obj); 
                throw new IOException("Invalid encoding: " . $rep); 
                // @codeCoverageIgnoreEnd
            }
        }

        if (is_resource($buf))
        {
            fwrite($buf, $output);
            return "";
        }

        return $output;
    }
618365
public function setArray($key, $objs_array) {
		$this->a [$key] = array ();
		foreach ( $objs_array as $obj ) {
			$this->a [$key] [] = $obj->toArray ();
		}
	}
1014948
public static function toArray(object $obj)
    {
        $array = (array)get_object_vars($obj);
        foreach ($array as $key => &$value) {
            if (is_object($value) && method_exists($value, 'toArray')) {
                $array[$key] = $value->toArray();
            } else if (is_array($value)) {
                foreach ($value as $deeper => $deepValue) {
                    if (is_object($deepValue) && method_exists($deepValue, 'toArray')) {
                        $value[$deeper] = $deepValue->toArray();
                    }
                }
            }
        }

        return $array;
    }
307233
private function inject(object $object, string $key, $value): object
    {
        return $this->injectionStrategy->inject($object, $key, $value);
    }
801385
public function mapObjToChoice($obj)
    {
        $map = $this->choiceObjMap();

        $choice = [];

        foreach ($map as $key => $props) {
            $choice[$key] = null;

            $props = explode(':', $props);
            foreach ($props as $prop) {
                $choice[$key] = $this->renderChoiceObjMap($obj, $prop);
                break;
            }
        }

        return $choice;
    }
903666
public Object getMapValue(Object obj, String key){
        Map m = (Map) obj;
        if(!m.containsKey(key)){
            return JsonProvider.UNDEFINED;
        } else {
            return m.get(key);
        }
    }
1022602
public function whereJson($key, $operator, $value = null)
    {
        return $this->filter($this->jsonOperator(...func_get_args()));
    }
637322
public function resolve($obj, array &$context)
    {
        if (empty($obj)) {
            return $obj;
        } elseif (is_array($obj)) {
            $res = [];
            foreach ($obj as $key => $value) {
                $res[$key] = $this->resolve($value, $context);
            }

            return $res;
        } elseif (is_string($obj)) {
            $availableVars = array_merge($context, $context[self::CONTEXT_VARS]);

            return $this->evaluateStringOrExpression($obj, $availableVars);
        }

        return $obj;
    }
827002
protected function objectToArray($obj)
    {
        if (!is_array($obj) && !is_object($obj)) {
            return $obj;
        }

        if (is_array($obj)) {
            return $obj;
        }

        if (is_object($obj)) {
            $obj = get_object_vars($obj);
        }

        return array_map([$this, 'objectToArray'], $obj);
    }
1159557
public static function jsonEncode( $obj )
    {
        if ( self::$nativeJsonEncode === null )
            self::$nativeJsonEncode = function_exists( 'json_encode' );

        if ( self::$nativeJsonEncode === true )
            return json_encode( $obj );

        $inst = self::getInstance();
        return $inst->phpJsonEncode( $obj );    
    }
1296344
public function setData($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $key => $value) {
                if (!is_array($value) && !is_object($value)) {
                    $value = $this->stripInvalidUnicodeSequences(
                        $this->stringToUtf8(
                            $value,
                            ShopgateObject::$sourceEncodings
                        )
                    );
                }
                $this->$key = $value;
            }
        } else {
            if (!is_array($value) && !is_object($value)) {
                if (!is_null($value)) {
                    $value = $this->stripInvalidUnicodeSequences(
                        $this->stringToUtf8(
                            $value,
                            ShopgateObject::$sourceEncodings
                        )
                    );
                }
            }
            $this->$key = $value;
        }

        return $this;
    }
1010796
private function objectToArray($obj){
        if(!is_object($obj) && !is_array($obj)) {
            return $obj;
        }
        $arr = array();
        foreach($obj as $k => $v){
            $arr[$k] = $this->objectToArray($v);
        }
        return $arr;
    }
929864
private function toArray($obj) {
        $arr = array();

        if (is_array($obj)) {
            foreach ($obj as $value) {
                $arr[] = $this->toArray($value);
            }
        } else if (is_object($obj)) {
            $arObj = (array) $obj;
            foreach ($arObj as $key => $value) {
                $attribute = str_replace(get_class($obj), "", $key);
                if (is_object($value) || is_array($value)) {
                    $value = $this->toArray($value);
                } else {
                    $arr[$attribute] = $this->utf8_encode_all($value);
                }
            }
        } else {
            $arr = $this->utf8_encode_all($obj);
        }
        return $arr;
    }
553953
private function parseValue(string $key, $value): string
    {

        if (is_array($value)) {
            return $this->parseArray($key, $value);
        }

        return $this->parseScalar($key, $value);
    }