Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Json_Server_Error Class Reference

Public Member Functions

 __construct ($message=null, $code=-32000, $data=null)
 
 setCode ($code)
 
 getCode ()
 
 setMessage ($message)
 
 getMessage ()
 
 setData ($data)
 
 getData ()
 
 toArray ()
 
 toJson ()
 
 __toString ()
 

Data Fields

const ERROR_PARSE = -32768
 
const ERROR_INVALID_REQUEST = -32600
 
const ERROR_INVALID_METHOD = -32601
 
const ERROR_INVALID_PARAMS = -32602
 
const ERROR_INTERNAL = -32603
 
const ERROR_OTHER = -32000
 

Protected Attributes

 $_allowedCodes
 
 $_code = -32000
 
 $_data
 
 $_message
 

Detailed Description

Definition at line 28 of file Error.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $message = null,
  $code = -32000,
  $data = null 
)

Constructor

Parameters
string$message
int$code
mixed$data
Returns
void

Definition at line 76 of file Error.php.

77  {
78  $this->setMessage($message)
79  ->setCode($code)
80  ->setData($data);
81  }
$message
setMessage($message)
Definition: Error.php:121
$code
Definition: info.phtml:12

Member Function Documentation

◆ __toString()

__toString ( )

Cast to string (JSON)

Returns
string

Definition at line 193 of file Error.php.

194  {
195  return $this->toJson();
196  }

◆ getCode()

getCode ( )

Get error code

Returns
int|null

Definition at line 110 of file Error.php.

111  {
112  return $this->_code;
113  }

◆ getData()

getData ( )

Get error data

Returns
mixed

Definition at line 158 of file Error.php.

159  {
160  return $this->_data;
161  }

◆ getMessage()

getMessage ( )

Get error message

Returns
string

Definition at line 136 of file Error.php.

137  {
138  return $this->_message;
139  }

◆ setCode()

setCode (   $code)

Set error code

Parameters
int$code
Returns
Zend_Json_Server_Error

Definition at line 89 of file Error.php.

90  {
91  if (!is_scalar($code)) {
92  return $this;
93  }
94 
95  $code = (int) $code;
96  if (in_array($code, $this->_allowedCodes)) {
97  $this->_code = $code;
98  } elseif (in_array($code, range(-32099, -32000))) {
99  $this->_code = $code;
100  }
101 
102  return $this;
103  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$code
Definition: info.phtml:12

◆ setData()

setData (   $data)

Set error data

Parameters
mixed$data
Returns
Zend_Json_Server_Error

Definition at line 147 of file Error.php.

148  {
149  $this->_data = $data;
150  return $this;
151  }

◆ setMessage()

setMessage (   $message)

Set error message

Parameters
string$message
Returns
Zend_Json_Server_Error

Definition at line 121 of file Error.php.

122  {
123  if (!is_scalar($message)) {
124  return $this;
125  }
126 
127  $this->_message = (string) $message;
128  return $this;
129  }
$message

◆ toArray()

toArray ( )

Cast error to array

Returns
array

Definition at line 168 of file Error.php.

169  {
170  return array(
171  'code' => $this->getCode(),
172  'message' => $this->getMessage(),
173  'data' => $this->getData(),
174  );
175  }

◆ toJson()

toJson ( )

Cast error to JSON

Returns
string

Definition at line 182 of file Error.php.

183  {
184  #require_once 'Zend/Json.php';
185  return Zend_Json::encode($this->toArray());
186  }
static encode($valueToEncode, $cycleCheck=false, $options=array())
Definition: Json.php:130

Field Documentation

◆ $_allowedCodes

$_allowedCodes
protected
Initial value:
= array(
self::ERROR_PARSE,
self::ERROR_INVALID_REQUEST,
self::ERROR_INVALID_METHOD,
self::ERROR_INVALID_PARAMS,
self::ERROR_INTERNAL,
self::ERROR_OTHER,
)

Definition at line 41 of file Error.php.

◆ $_code

$_code = -32000
protected

Definition at line 54 of file Error.php.

◆ $_data

$_data
protected

Definition at line 60 of file Error.php.

◆ $_message

$_message
protected

Definition at line 66 of file Error.php.

◆ ERROR_INTERNAL

const ERROR_INTERNAL = -32603

Definition at line 34 of file Error.php.

◆ ERROR_INVALID_METHOD

const ERROR_INVALID_METHOD = -32601

Definition at line 32 of file Error.php.

◆ ERROR_INVALID_PARAMS

const ERROR_INVALID_PARAMS = -32602

Definition at line 33 of file Error.php.

◆ ERROR_INVALID_REQUEST

const ERROR_INVALID_REQUEST = -32600

Definition at line 31 of file Error.php.

◆ ERROR_OTHER

const ERROR_OTHER = -32000

Definition at line 35 of file Error.php.

◆ ERROR_PARSE

const ERROR_PARSE = -32768

Definition at line 30 of file Error.php.


The documentation for this class was generated from the following file: