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

Public Member Functions

 setOptions (array $options)
 
 setTransport ($transport)
 
 getTransport ()
 
 setEnvelope ($envelopeType)
 
 getEnvelope ()
 
 setContentType ($type)
 
 getContentType ()
 
 setTarget ($target)
 
 getTarget ()
 
 setId ($id)
 
 getId ()
 
 setDescription ($description)
 
 getDescription ()
 
 setDojoCompatible ($flag)
 
 isDojoCompatible ()
 
 addService ($service)
 
 addServices (array $services)
 
 setServices (array $services)
 
 getService ($name)
 
 getServices ()
 
 removeService ($name)
 
 toArray ()
 
 toDojoArray ()
 
 toJson ()
 
 __toString ()
 

Data Fields

const ENV_JSONRPC_1 = 'JSON-RPC-1.0'
 
const ENV_JSONRPC_2 = 'JSON-RPC-2.0'
 
const SMD_VERSION = '2.0'
 

Protected Attributes

 $_contentType = 'application/json'
 
 $_contentTypeRegex = '#[a-z]+/[a-z][a-z-]+#i'
 
 $_description
 
 $_dojoCompatible = false
 
 $_envelope = self::ENV_JSONRPC_1
 
 $_envelopeTypes
 
 $_id
 
 $_services = array()
 
 $_target
 
 $_transport = 'POST'
 
 $_transportTypes = array('POST')
 

Detailed Description

Definition at line 30 of file Smd.php.

Member Function Documentation

◆ __toString()

__toString ( )

Cast to string (JSON)

Returns
string

Definition at line 475 of file Smd.php.

476  {
477  return $this->toJson();
478  }

◆ addService()

addService (   $service)

Add Service

Parameters
Zend_Json_Server_Smd_Service | array$service
Returns
void

Definition at line 296 of file Smd.php.

297  {
298  #require_once 'Zend/Json/Server/Smd/Service.php';
299 
300  if ($service instanceof Zend_Json_Server_Smd_Service) {
301  $name = $service->getName();
302  } elseif (is_array($service)) {
304  $name = $service->getName();
305  } else {
306  #require_once 'Zend/Json/Server/Exception.php';
307  throw new Zend_Json_Server_Exception('Invalid service passed to addService()');
308  }
309 
310  if (array_key_exists($name, $this->_services)) {
311  #require_once 'Zend/Json/Server/Exception.php';
312  throw new Zend_Json_Server_Exception('Attempt to register a service already registered detected');
313  }
314  $this->_services[$name] = $service;
315  return $this;
316  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addServices()

addServices ( array  $services)

Add many services

Parameters
array$services
Returns
Zend_Json_Server_Smd

Definition at line 324 of file Smd.php.

325  {
326  foreach ($services as $service) {
327  $this->addService($service);
328  }
329  return $this;
330  }
addService($service)
Definition: Smd.php:296

◆ getContentType()

getContentType ( )

Retrieve content type

Returns
string

Definition at line 197 of file Smd.php.

198  {
199  return $this->_contentType;
200  }

◆ getDescription()

getDescription ( )

Get service description

Returns
string

Definition at line 263 of file Smd.php.

264  {
265  return $this->_description;
266  }

◆ getEnvelope()

getEnvelope ( )

Retrieve envelope

Returns
string

Definition at line 170 of file Smd.php.

171  {
172  return $this->_envelope;
173  }

◆ getId()

getId ( )

Get service id

Returns
string

Definition at line 241 of file Smd.php.

242  {
243  return $this->_id;
244  }

◆ getService()

getService (   $name)

Get service object

Parameters
string$name
Returns
false|Zend_Json_Server_Smd_Service

Definition at line 350 of file Smd.php.

351  {
352  if (array_key_exists($name, $this->_services)) {
353  return $this->_services[$name];
354  }
355  return false;
356  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getServices()

getServices ( )

Return services

Returns
array

Definition at line 363 of file Smd.php.

364  {
365  return $this->_services;
366  }

◆ getTarget()

getTarget ( )

Retrieve service target

Returns
string

Definition at line 219 of file Smd.php.

220  {
221  return $this->_target;
222  }

◆ getTransport()

getTransport ( )

Get transport

Returns
string

Definition at line 144 of file Smd.php.

145  {
146  return $this->_transport;
147  }

◆ isDojoCompatible()

isDojoCompatible ( )

Is this a Dojo compatible SMD?

Returns
bool

Definition at line 285 of file Smd.php.

286  {
287  return $this->_dojoCompatible;
288  }

◆ removeService()

removeService (   $name)

Remove service

Parameters
string$name
Returns
boolean

Definition at line 374 of file Smd.php.

375  {
376  if (array_key_exists($name, $this->_services)) {
377  unset($this->_services[$name]);
378  return true;
379  }
380  return false;
381  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setContentType()

setContentType (   $type)

Set content type

Parameters
string$type
Returns
Zend_Json_Server_Smd

Definition at line 182 of file Smd.php.

183  {
184  if (!preg_match($this->_contentTypeRegex, $type)) {
185  #require_once 'Zend/Json/Server/Exception.php';
186  throw new Zend_Json_Server_Exception(sprintf('Invalid content type "%s" specified', $type));
187  }
188  $this->_contentType = $type;
189  return $this;
190  }
$type
Definition: item.phtml:13

◆ setDescription()

setDescription (   $description)

Set service description

Parameters
string$description
Returns
Zend_Json_Server_Smd

Definition at line 252 of file Smd.php.

253  {
254  $this->_description = (string) $description;
255  return $this->_description;
256  }

◆ setDojoCompatible()

setDojoCompatible (   $flag)

Indicate whether or not to generate Dojo-compatible SMD

Parameters
bool$flag
Returns
Zend_Json_Server_Smd

Definition at line 274 of file Smd.php.

275  {
276  $this->_dojoCompatible = (bool) $flag;
277  return $this;
278  }

◆ setEnvelope()

setEnvelope (   $envelopeType)

Set envelope

Parameters
string$envelopeType
Returns
Zend_Json_Server_Smd

Definition at line 155 of file Smd.php.

156  {
157  if (!in_array($envelopeType, $this->_envelopeTypes)) {
158  #require_once 'Zend/Json/Server/Exception.php';
159  throw new Zend_Json_Server_Exception(sprintf('Invalid envelope type "%s"', $envelopeType));
160  }
161  $this->_envelope = $envelopeType;
162  return $this;
163  }

◆ setId()

setId (   $id)

Set service ID

Parameters
string$Id
Returns
Zend_Json_Server_Smd

Definition at line 230 of file Smd.php.

231  {
232  $this->_id = (string) $id;
233  return $this->_id;
234  }
$id
Definition: fieldset.phtml:14

◆ setOptions()

setOptions ( array  $options)

Set object state via options

Parameters
array$options
Returns
Zend_Json_Server_Smd

Definition at line 111 of file Smd.php.

112  {
113  $methods = get_class_methods($this);
114  foreach ($options as $key => $value) {
115  $method = 'set' . ucfirst($key);
116  if (in_array($method, $methods)) {
117  $this->$method($value);
118  }
119  }
120  return $this;
121  }
$methods
Definition: billing.phtml:71
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13

◆ setServices()

setServices ( array  $services)

Overwrite existing services with new ones

Parameters
array$services
Returns
Zend_Json_Server_Smd

Definition at line 338 of file Smd.php.

339  {
340  $this->_services = array();
341  return $this->addServices($services);
342  }
addServices(array $services)
Definition: Smd.php:324

◆ setTarget()

setTarget (   $target)

Set service target

Parameters
string$target
Returns
Zend_Json_Server_Smd

Definition at line 208 of file Smd.php.

209  {
210  $this->_target = (string) $target;
211  return $this;
212  }
$target
Definition: skip.phtml:8

◆ setTransport()

setTransport (   $transport)

Set transport

Parameters
string$transport
Returns
Zend_Json_Server_Smd

Definition at line 129 of file Smd.php.

130  {
131  if (!in_array($transport, $this->_transportTypes)) {
132  #require_once 'Zend/Json/Server/Exception.php';
133  throw new Zend_Json_Server_Exception(sprintf('Invalid transport "%s" specified', $transport));
134  }
135  $this->_transport = $transport;
136  return $this;
137  }

◆ toArray()

toArray ( )

Cast to array

Returns
array

Definition at line 388 of file Smd.php.

389  {
390  if ($this->isDojoCompatible()) {
391  return $this->toDojoArray();
392  }
393 
394  $transport = $this->getTransport();
395  $envelope = $this->getEnvelope();
396  $contentType = $this->getContentType();
397  $SMDVersion = self::SMD_VERSION;
398  $service = compact('transport', 'envelope', 'contentType', 'SMDVersion');
399 
400  if (null !== ($target = $this->getTarget())) {
401  $service['target'] = $target;
402  }
403  if (null !== ($id = $this->getId())) {
404  $service['id'] = $id;
405  }
406 
407  $services = $this->getServices();
408  if (!empty($services)) {
409  $service['services'] = array();
410  foreach ($services as $name => $svc) {
411  $svc->setEnvelope($envelope);
412  $service['services'][$name] = $svc->toArray();
413  }
414  $service['methods'] = $service['services'];
415  }
416 
417  return $service;
418  }
$id
Definition: fieldset.phtml:14
$target
Definition: skip.phtml:8
const SMD_VERSION
Definition: Smd.php:34
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ toDojoArray()

toDojoArray ( )

Export to DOJO-compatible SMD array

Returns
array

Definition at line 425 of file Smd.php.

426  {
427  $SMDVersion = '.1';
428  $serviceType = 'JSON-RPC';
429  $service = compact('SMDVersion', 'serviceType');
430 
431  $target = $this->getTarget();
432 
433  $services = $this->getServices();
434  if (!empty($services)) {
435  $service['methods'] = array();
436  foreach ($services as $name => $svc) {
437  $method = array(
438  'name' => $name,
439  'serviceURL' => $target,
440  );
441  $params = array();
442  foreach ($svc->getParams() as $param) {
443  $paramName = array_key_exists('name', $param) ? $param['name'] : $param['type'];
444  $params[] = array(
445  'name' => $paramName,
446  'type' => $param['type'],
447  );
448  }
449  if (!empty($params)) {
450  $method['parameters'] = $params;
451  }
452  $service['methods'][] = $method;
453  }
454  }
455 
456  return $service;
457  }
$target
Definition: skip.phtml:8
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ toJson()

toJson ( )

Cast to JSON

Returns
string

Definition at line 464 of file Smd.php.

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

Field Documentation

◆ $_contentType

$_contentType = 'application/json'
protected

Definition at line 40 of file Smd.php.

◆ $_contentTypeRegex

$_contentTypeRegex = '#[a-z]+/[a-z][a-z-]+#i'
protected

Definition at line 46 of file Smd.php.

◆ $_description

$_description
protected

Definition at line 52 of file Smd.php.

◆ $_dojoCompatible

$_dojoCompatible = false
protected

Definition at line 58 of file Smd.php.

◆ $_envelope

$_envelope = self::ENV_JSONRPC_1
protected

Definition at line 64 of file Smd.php.

◆ $_envelopeTypes

$_envelopeTypes
protected
Initial value:
= array(
self::ENV_JSONRPC_1,
self::ENV_JSONRPC_2,
)

Definition at line 70 of file Smd.php.

◆ $_id

$_id
protected

Definition at line 79 of file Smd.php.

◆ $_services

$_services = array()
protected

Definition at line 85 of file Smd.php.

◆ $_target

$_target
protected

Definition at line 91 of file Smd.php.

◆ $_transport

$_transport = 'POST'
protected

Definition at line 97 of file Smd.php.

◆ $_transportTypes

$_transportTypes = array('POST')
protected

Definition at line 103 of file Smd.php.

◆ ENV_JSONRPC_1

const ENV_JSONRPC_1 = 'JSON-RPC-1.0'

Definition at line 32 of file Smd.php.

◆ ENV_JSONRPC_2

const ENV_JSONRPC_2 = 'JSON-RPC-2.0'

Definition at line 33 of file Smd.php.

◆ SMD_VERSION

const SMD_VERSION = '2.0'

Definition at line 34 of file Smd.php.


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