Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Response.php
Go to the documentation of this file.
1 <?php
31 {
36  protected $_error;
37 
42  protected $_id;
43 
48  protected $_result;
49 
54  protected $_serviceMap;
55 
60  protected $_version;
61 
68  public function setResult($value)
69  {
70  $this->_result = $value;
71  return $this;
72  }
73 
79  public function getResult()
80  {
81  return $this->_result;
82  }
83 
84  // RPC error, if response results in fault
91  public function setError(Zend_Json_Server_Error $error)
92  {
93  $this->_error = $error;
94  return $this;
95  }
96 
102  public function getError()
103  {
104  return $this->_error;
105  }
106 
112  public function isError()
113  {
114  return $this->getError() instanceof Zend_Json_Server_Error;
115  }
116 
123  public function setId($name)
124  {
125  $this->_id = $name;
126  return $this;
127  }
128 
134  public function getId()
135  {
136  return $this->_id;
137  }
138 
145  public function setVersion($version)
146  {
147  $version = is_array($version)
148  ? implode(' ', $version)
149  : $version;
150  if ((string)$version == '2.0') {
151  $this->_version = '2.0';
152  } else {
153  $this->_version = null;
154  }
155  return $this;
156  }
157 
163  public function getVersion()
164  {
165  return $this->_version;
166  }
167 
173  public function toJson()
174  {
175  if ($this->isError()) {
176  $response = array(
177  'error' => $this->getError()->toArray(),
178  'id' => $this->getId(),
179  );
180  } else {
181  $response = array(
182  'result' => $this->getResult(),
183  'id' => $this->getId(),
184  );
185  }
186 
187  if (null !== ($version = $this->getVersion())) {
188  $response['jsonrpc'] = $version;
189  }
190 
191  #require_once 'Zend/Json.php';
193  }
194 
200  public function getArgs()
201  {
202  return $this->_args;
203  }
204 
211  public function setArgs($args)
212  {
213  $this->_args = $args;
214  return $this;
215  }
216 
223  public function setServiceMap($serviceMap)
224  {
225  $this->_serviceMap = $serviceMap;
226  return $this;
227  }
228 
234  public function getServiceMap()
235  {
236  return $this->_serviceMap;
237  }
238 
244  public function __toString()
245  {
246  return $this->toJson();
247  }
248 }
249 
$response
Definition: 404.php:11
$value
Definition: gender.phtml:16
setError(Zend_Json_Server_Error $error)
Definition: Response.php:91
setServiceMap($serviceMap)
Definition: Response.php:223
static encode($valueToEncode, $cycleCheck=false, $options=array())
Definition: Json.php:130
if(!isset($_GET['name'])) $name
Definition: log.php:14