success

@param  mixed $errmsg
@param  array $data
@return ResponseInterface
356075
protected function success($errmsg=null, $data=null)
    {
        $this->errorInfo = ErrorInfo::success($errmsg, $data);
        
        if (!isset($this->errorInfo['errmsg'])) {
            $this->errorInfo['errmsg'] = '操作成功';
        }
        
        return $this->jump($this->errorInfo);
    }
699183
public function validate(array $data = [], array $rules = [], array $messages = [])
    {
        $this->prepareRecord($data, $rules, $messages);

        return $this->validateRecord();
    }
1026316
public function success(array $data = [], $status = 200, $code = 'success', array $headers = [], $options = 0)
    {
        return $this->respond($data, $status, $code, $headers, $options);
    }
630464
public static UnitResponse createError(String errCode, Object data, String errMsg) {
        if (Group.CODE_SUCCESS.equalsIgnoreCase(errCode)) {
            throw new IllegalArgumentException("Only non-success code is allowed here.");
        }
        return new UnitResponse().setCode(errCode).setData(data).setMessage(errMsg);
    }
1184154
public function execute($data = null)
    {
        $result = $this->next->execute($data);

        $response = $data->response;

        $this->controller->setResponse(new RedirectResponse(
            $result,
            $response->getStatusCode(),
            $response->getHeaders()
        ));

        return $this->next->execute($data);
    }
439799
private function errorResponse($error, $notices = [], $errorCode = 400)
    {
        if (is_array($error)) {
            json_encode($error);
        }
        $payload = ['error' => $error];
        if (!empty($notices)) {
            $payload['notices'] = $notices;
        }

        return \Response::json($payload, $errorCode);
    }
876304
public function convertFailedToDelete(array $data = null)
    {
        $result = new FailedToDeleteData();

        if (empty($data)) {
            return $result;
        }

        $result->setIds(array_map('strval', $data[JSONConstants::JSON_FAILEDTODELETE_ID] ?? []));
        $result->setExtensions($this->convertExtension($data, JSONConstants::getFailedToDeleteKeys()));

        return $result;
    }
215991
public function aError($message,$url='',$data=[])
    {
        $url=is_null($url) || $url=='' ? 'javascript:history.back(-1)' : $url;
        if(Request::isAjax() ){
            return $this->json(1,$message,array_merge($data,['url'=>$url]));
        }else{
            return $this->error($message,$url);
        }
    }
482302
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
346816
public function respond(array $data = [], array $headers = []): JsonResponse
    {
        $meta = [
            'meta' => [
                'server_time' => time(),
                'server_timezone' => date_default_timezone_get(),
                'api_version' => 'v1',
            ],
        ];

        return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
    }
342460
public function post($resource, $data = [])
    {
        $exec = $this->execute(Method::$HTTP_POST, $resource, ['json' => $data]);

        return $exec;
    }
297231
protected function error($errcode=-1, $errmsg=null, $data=null)
    {
        !isset($this->errorInfo['errcode']) && $this->errorInfo = ErrorInfo::error($errcode, $errmsg, $data);
        
        if (!isset($this->errorInfo['errmsg'])) {
            $this->errorInfo['errmsg'] = '操作失败';
        }
        
        return $this->jump($this->errorInfo);
    }
536255
static public function instance($errcode=0, $errmsg=null, $data=null)
    {
        if ($errcode instanceof ErrorInfo) {
            return $errcode->setErrorInfo(null, $errmsg, $data);
        } else {
            return new static($errcode, $errmsg, $data);
        }
    }
644779
private static function prepareErrorMessage($validatorErrors, $data)
    {
        $errors = json_decode(json_encode($validatorErrors, true));
        array_walk($errors, function (&$value, $key) use ($data) {
            array_push($value, "Value: $data[$key]");
        });

        return json_encode($errors, true);
    }
878531
public static UnitResponse createSuccess(Object data, String errMsg) {
        return createSuccess(data).setMessage(errMsg);
    }
709493
public function successData($data, $msg = null, $extraData = [])
    {
        $return = $this->output(1, $msg, $data, $extraData);

        return $this->responseJson($return);
    }
1281929
public function redirect(string $url, $data = null)
    {
        return $this->response([
            'success' => true,
            'redirect' => $url,
            'data' => $data,
        ]);
    }