Flattens an errors object returned from the API into an array.
@param array   $obj  Discord error object
@param string  $key  Used internally to determine key names of nested fields
@return string[]
@internal
515402
static function flattenErrors($obj, $key = '') {
        $messages = array();
        
        foreach($obj as $k => $val) {
            if($k === 'message') {
                continue;
            }
            
            $newKey = $k;
            if($key) {
                if(\is_numeric($k)) {
                    $newKey = $key.'.'.$k;
                } else {
                    $newKey = $key.'['.$k.']';
                }
            }
            
            if(isset($val['_errors'])) {
                $messages[] = $newKey.': '.\implode(' ', \array_map(function ($element) {
                    return $element['message'];
                }, $val['_errors']));
            } else if(isset($val['code']) || isset($val['message'])) {
                $messages[] = \trim(($val['code'] ?? '').': '.($val['message'] ?? ''));
            } else if(\is_array($val)) {
                $messages = \array_merge($messages, self::flattenErrors($val, $newKey));
            } else {
                $messages[] = $val;
            }
        }

        return $messages;
    }
1020479
public static function ObjectToArray($obj,$fields=[])
    {
        if(is_object($obj)){
            if(empty($fields)){
                return get_object_vars($obj);
            }else{
                $array=[];
                foreach ($fields as $fd){
                    if(property_exists($obj, $fd)){
                        $array[$fd]=$obj->$fd;
                    }
                }
                return $array;
            }
        }
        return [];
    }
1015882
public function getErrorsAsArray()
    {
        $errors = array();
        $errors['HasErrors'] = $this->hasErrors();
        $errors['ErrorCount'] = $this->getErrorCount();
        $errors['Errors'] = (array)$this->errors;

        /*
        $errors['ErrorString'] = '';
        $errors['FieldErrorString'] = '';
        $errors['GlobalErrorString'] = '';
        $errors['ErrorStringHTML'] = '';
        $errors['FieldErrorStringHTML'] = '';
        $errors['GlobalErrorStringHTML'] = '';

        */

        foreach ((array)$this->errors as $err) {

            if ($err instanceof FieldValidationError) {
                $field = $err->getFieldResolved();
                $errors['Has'.$field.'Error'] = true;
                // $errors[$field.'ErrorMessage'] = $err->getDefaultErrorMessage();
                // $errors[$field.'ErrorCode'] = $err->getErrorCode();
                $errors['ErrorFields'][] = $field;
                $errors['ErrorValues'][] = $err->getValue();

                // $errors['FieldErrorString'] .= $err->getDefaultErrorMessage()."\n";
                // $errors['FieldErrorStringHTML'] .= $err->getDefaultErrorMessage().'<br/>';
            } else {
                // $errors['GlobalErrorString'] .= $err->getDefaultErrorMessage()."\n";
                // $errors['GlobalErrorStringHTML'] .= $err->getDefaultErrorMessage().'<br/>';
            }

            $errors['ErrorCodes'][] = $err->getErrorCode();
            // $errors['ErrorMessages'][] = $err->getDefaultErrorMessage();
            // $errors['ErrorString'] .= $err->getDefaultErrorMessage()."\n";
            // $errors['ErrorStringHTML'] .= $err->getDefaultErrorMessage().'<br/>';
        }

        return $errors;

    }
95678
function flatten(obj) {
  var params = {};

  forEach(obj || {}, function (val, key) {
    if (val && typeof val === 'object') {
      forEach(flatten(val), function (sub_val, sub_key) {
        params[key + '.' + sub_key] = sub_val;
      });
      return;
    }

    params[key] = val;
  });

  return params;
}
1019602
public function get_error( $key, $all = true ) {
		if ( ! $this->has_error( $key ) ) {
			return null;
		}

		$errors = $this->errors->errors[ $key ];

		return $all ? Arr::first( $errors ) : $errors;
	}
789416
function errorJSON (err) {
  var res = {}
  Object.getOwnPropertyNames(err).forEach(function (key) {
    res[key] = err[key]
  }, err)
  return res
}
189835
public function getError($field)
    {
        $errors = isset($this->_errors[$field]) ? $this->_errors[$field] : [];
        if ($errors) {
            return $errors;
        }

        return $this->_nestedErrors($field);
    }
65087
public function setError($key, $error)
    {
        if (isset($key)) {
            gplcart_array_set($this->errors, $key, $error);
            return $this->errors;
        }

        return $this->errors = (array) $error;
    }
836650
public function getMessages(string $key, array $errors = []): array
    {
        // when there is a template for the given key, return only this message.
        if (array_key_exists($key, $this->templates)) {

            return [$this->translate($this->templates[$key], ['attribute' => $key])];

        }

        // return one message for each rule which failed.
        return array_reduce($errors, function ($messages, $error) use ($key) {

            $rule = $error->getRule();
            $parameters = $error->getParameters();

            $template = $this->getTemplate($key, $rule);

            $message = $this->translate($template, array_merge($parameters, [
                'attribute' => $key,
            ]));

            return array_merge($messages, [$message]);

        }, []);
    }
1033855
public static function object_to_array($obj)
    {
        $obj = (array)$obj;
        foreach ($obj as $k => $v) {
            if (gettype($v) == 'object' || gettype($v) == 'array') {
                $obj[$k] = self::object_to_array($v);
            }
        }
        return $obj;
    }
1341185
private function getError($code, $id = null, $data = null)
    {
        return [
            'jsonrpc' => '2.0',
            'id' => $id,
            'error' => [
                'code' => $code,
                'message' => isset($this->errorMessages[$code]) ?
                    $this->errorMessages[$code] : $this->errorMessages[self::INTERNALERROR],
                'data' => $data,
            ],
        ];
    }
476824
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = ['errors' => []];

        foreach ($object as $innerError) {
            $normalized['errors'][] = $this->normalizer->normalize($innerError, $format, $context);
        }

        $normalized = $this->appendCollectionAttributes($normalized, $object, (string) $format, $context);

        return $normalized;
    }
1130684
public static function pluck(?string $key = null, ?array $array = null): array
    {
        if (!Any::isArray($array) || !Any::isStr($key)) {
            return [];
        }

        $output = [];
        foreach ($array as $item) {
            $object = $item[$key];
            if (!self::in($object, $output)) {
                $output[] = $object;
            }
        }
        return $output;
    }
972917
public function setError($obj=null)
    {
        $obj = $obj ? $obj : $this->_con;
        if (!is_resource($obj)) {
            return;
        }
        $error = \oci_error($obj);
        if (!$error) {
            return null;
        }
        $this->_last_error = $error;
    }
225497
public function _apply($oldValue, $obj, $key)
    {
        if (empty($oldValue))
        {
            return array();
        }
        $newValue = array();
        foreach ($oldValue as $oldObject)
        {
            foreach ($this->objects as $newObject)
            {
                if ($oldObject instanceof AVObject)
                {
                    if ($newObject instanceof AVObject && !$oldObject->isDirty() && $oldObject->getObjectId() == $newObject->getObjectId())
                    {
                        // found the object, won't add it.
                    } else
                    {
                        $newValue[] = $oldObject;
                    }
                } else
                {
                    if ($oldObject !== $newObject)
                    {
                        $newValue[] = $oldObject;
                    }
                }
            }
        }

        return $newValue;
    }
1269967
public static function prop_or_arr($obj, $key) {
        if (is_object($obj) && array_key_exists($key, get_object_vars($obj))) {
            return $obj->$key;
        }

        if (is_array($obj) && isset($obj[$key])) {
            return $obj[$key];
        }

        return false;
      }
895508
def strip_errors(obj):
    
    rtn_obj = copy.deepcopy(obj)
    try:
        del rtn_obj["__error_keys__"]
    except KeyError:
        pass
    for key in obj.get('__error_keys__', []):
        rtn_obj[key] = rtn_obj[key]['value']
    return rtn_obj