Hoa central
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Hoa\XmlRpc\Message\Message Class Reference
Inheritance diagram for Hoa\XmlRpc\Message\Message:

Public Member Functions

 __construct ($is=self::IS_SCALAR, $parent=null)
 
 withArray ()
 
 endArray ()
 
 withBase64 ($data)
 
 withBoolean ($data)
 
 withDateTime ($timestamp)
 
 withFloat ($float)
 
 withInteger ($integer)
 
 withString ($string)
 
 withStructure ()
 
 withName ($name)
 
 endStructure ()
 
 withNull ()
 
 getParent ()
 
 getValues ()
 
 getValueAsString ($value, $type)
 
 getFormattedValues ()
 

Public Attributes

const VALUE = 0
 
const TYPE = 1
 
const TYPE_ARRAY = 2
 
const TYPE_BASE64 = 3
 
const TYPE_BOOLEAN = 4
 
const TYPE_DATETIME = 5
 
const TYPE_FLOAT = 6
 
const TYPE_INTEGER = 7
 
const TYPE_STRING = 8
 
const TYPE_STRUCTURE = 9
 
const TYPE_NULL = 10
 
const IS_SCALAR = 11
 
const IS_ARRAY = 12
 
const IS_STRUCTURE = 13
 

Protected Member Functions

 _with ($value, $type)
 
 setParent ($parent)
 
 _getFormattedValues ($values)
 
 computeValues ($values, $self=null)
 

Protected Attributes

 $_values = []
 
 $_parent = null
 
 $_name = 'undefined'
 
 $_is = self::IS_SCALAR
 

Detailed Description

Class .

Write XML-RPC values intuitively on a message. XML-RPC specification can be found at: http://xmlrpc.com/spec.

Definition at line 50 of file Message.php.

Constructor & Destructor Documentation

Hoa\XmlRpc\Message\Message::__construct (   $is = self::IS_SCALAR,
  $parent = null 
)

Build a new value object.

Parameters
int$isType of object. Please, see the self::IS_* constants.
\Hoa\XmlRpc\Message$parentParent.
Returns
void

Definition at line 189 of file Message.php.

190  {
191  $this->_is = $is;
192  $this->setParent($parent);
193 
194  return;
195  }

Here is the call graph for this function:

Member Function Documentation

Hoa\XmlRpc\Message\Message::_getFormattedValues (   $values)
protected

Built formatted values.

Returns
array

Definition at line 471 of file Message.php.

472  {
473  if (!is_array($values)) {
474  return $values;
475  }
476 
477  $formatted = [];
478 
479  foreach ($values as $key => $value) {
480  $formatted[$key] = $this->_getFormattedValues($value[self::VALUE]);
481  }
482 
483  return $formatted;
484  }

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::_with (   $value,
  $type 
)
protected

Generic method to “with” (:-p).

Parameters
mixed$valueValue.
int$typeType. Please, see the self::TYPE_* constants.
Returns

Definition at line 204 of file Message.php.

205  {
206  if (self::IS_STRUCTURE == $this->_is) {
207  $this->_values[$this->_name] = [$value, $type];
208  } else {
209  $this->_values[] = [$value, $type];
210  }
211 
212  return $this;
213  }

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::computeValues (   $values,
  $self = null 
)
protected

Compute XML values into values bucket.

Parameters
array$valuesValues XML collection.
\Hoa\XmlRpc\Message$selfCurrent valued object.
Returns
void

Definition at line 493 of file Message.php.

494  {
495  if (null === $self) {
496  $self = $this;
497  }
498 
499  if (!is_array($values)) {
500  $values = [$values];
501  }
502 
503  foreach ($values as $value) {
504  switch (strtolower($value->getName())) {
505  case 'array':
506  $self = $self->withArray();
507 
508  foreach ($value->data as $data) {
509  $this->computeValues($data->xpath('./value/*'), $self);
510  }
511 
512  $self = $self->endArray();
513 
514  break;
515 
516  case 'base64':
517  $self->withBase64(base64_decode($value->readAll()));
518 
519  break;
520 
521  case 'boolean':
522  $self->withBoolean((boolean) (int) $value->readAll());
523 
524  break;
525 
526  case 'datetime.iso8601':
527  $self->withDateTime(strtotime($value->readAll()));
528 
529  break;
530 
531  case 'double':
532  $self->withFloat((float) $value->readAll());
533 
534  break;
535 
536  case 'i4':
537  case 'int':
538  $self->withInteger((int) $value->readAll());
539 
540  break;
541 
542  case 'string':
543  $self->withString(htmlspecialchars_decode($value->readAll()));
544 
545  break;
546 
547  case 'struct':
548  $self = $self->withStructure();
549 
550  foreach ($value->member as $member) {
551  $self->withName($member->name->readAll());
552  $this->computeValues($member->xpath('./value/*'), $self);
553  }
554 
555  $self = $self->endStructure();
556 
557  break;
558 
559  case 'nil':
560  $self->withNull();
561 
562  break;
563  }
564  }
565 
566  return;
567  }
computeValues($values, $self=null)
Definition: Message.php:493

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::endArray ( )

Stop an array.

Returns

Definition at line 232 of file Message.php.

233  {
234  $parent = $this->getParent();
235  $parent->_with($this->getValues(), self::TYPE_ARRAY);
236 
237  return $parent;
238  }

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::endStructure ( )

Stop a structure.

Returns

Definition at line 341 of file Message.php.

342  {
343  $parent = $this->getParent();
344  $parent->_with($this->getValues(), self::TYPE_STRUCTURE);
345 
346  return $parent;
347  }

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::getFormattedValues ( )

Get values formatted (comprehensive array).

Returns
array

Definition at line 461 of file Message.php.

462  {
463  return $this->_getFormattedValues($this->getValues());
464  }

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::getParent ( )

Get current parent.

Returns

Definition at line 379 of file Message.php.

380  {
381  return $this->_parent;
382  }

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::getValueAsString (   $value,
  $type 
)

Get a value as a XML string.

Parameters
mixed$valueValue.
int$typeType. Please, see the self::TYPE_* constants.
Returns
string

Definition at line 401 of file Message.php.

402  {
403  switch ($type) {
404  case self::TYPE_ARRAY:
405  $out = '<array>' . "\n" . ' <data>' . "\n";
406 
407  foreach ($value as $v) {
408  $out .=
409  ' <value>' . $this->getValueAsString(
410  $v[self::VALUE],
411  $v[self::TYPE]
412  ) . '</value>' . "\n";
413  }
414 
415  return $out . ' </data>' . "\n" . '</array>';
416 
417  case self::TYPE_BASE64:
418  return '<base64>' . base64_encode($value) . '</base64>';
419 
420  case self::TYPE_BOOLEAN:
421  return '<boolean>' . (true == $value ? '1' : '0') . '</boolean>';
422 
423  case self::TYPE_DATETIME:
424  return '<dateTime.iso8601>' . date('c', $value) . '</dateTime.iso8601>';
425 
426  case self::TYPE_FLOAT:
427  return '<double>' . $value . '</double>';
428 
429  case self::TYPE_INTEGER:
430  return '<i4>' . $value . '</i4>';
431 
432  case self::TYPE_STRING:
433  return '<string>' . htmlspecialchars($value) . '</string>';
434 
435  case self::TYPE_STRUCTURE:
436  $out = '<struct>' . "\n";
437 
438  foreach ($value as $name => $v) {
439  $out .=
440  ' <member>' . "\n" .
441  ' <name>' . $name . '</name>' . "\n" .
442  ' <value>' . $this->getValueAsString(
443  $v[self::VALUE],
444  $v[self::TYPE]
445  ) . '</value>' . "\n" .
446  ' </member>' . "\n";
447  }
448 
449  return $out . '</struct>';
450 
451  case self::TYPE_NULL:
452  return '<nil />';
453  }
454  }
getValueAsString($value, $type)
Definition: Message.php:401

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::getValues ( )

Get values bucket.

Returns
array

Definition at line 389 of file Message.php.

390  {
391  return $this->_values;
392  }

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::setParent (   $parent)
protected

Set current parent.

Parameters
\Hoa\XmlRpc\Message$parentParent.
Returns

Definition at line 366 of file Message.php.

367  {
368  $old = $this->_parent;
369  $this->_parent = $parent;
370 
371  return $old;
372  }

Here is the caller graph for this function:

Hoa\XmlRpc\Message\Message::withArray ( )

Start an array.

Returns

Definition at line 220 of file Message.php.

221  {
222  $self = __CLASS__;
223 
224  return new $self(self::IS_ARRAY, $this);
225  }
Hoa\XmlRpc\Message\Message::withBase64 (   $data)

Add a base64 value.

Parameters
mixed$dataData.
Returns

Definition at line 246 of file Message.php.

247  {
248  return $this->_with($data, self::TYPE_BASE64);
249  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withBoolean (   $data)

Add a boolean value.

Parameters
mixed$dataData.
Returns

Definition at line 257 of file Message.php.

258  {
259  return $this->_with((boolean) $data, self::TYPE_BOOLEAN);
260  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withDateTime (   $timestamp)

Add a date/time value.

Parameters
mixed$dataData.
Returns

Definition at line 268 of file Message.php.

269  {
270  return $this->_with($timestamp, self::TYPE_DATETIME);
271  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withFloat (   $float)

Add a float value.

Parameters
mixed$dataData.
Returns

Definition at line 279 of file Message.php.

280  {
281  return $this->_with((float) $float, self::TYPE_FLOAT);
282  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withInteger (   $integer)

Add an integer value.

Parameters
mixed$dataData.
Returns

Definition at line 290 of file Message.php.

291  {
292  return $this->_with((int) $integer, self::TYPE_INTEGER);
293  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withName (   $name)

Add a named value.

Parameters
string$nameName.
Returns

Definition at line 325 of file Message.php.

326  {
327  if (self::IS_STRUCTURE !== $this->_is) {
328  return $this;
329  }
330 
331  $this->_name = $name;
332 
333  return $this;
334  }
Hoa\XmlRpc\Message\Message::withNull ( )

Add a null value.

Parameters
mixed$dataData.
Returns

Definition at line 355 of file Message.php.

356  {
357  return $this->_with(null, self::TYPE_NULL);
358  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withString (   $string)

Add a string value.

Parameters
mixed$dataData.
Returns

Definition at line 301 of file Message.php.

302  {
303  return $this->_with((string) $string, self::TYPE_STRING);
304  }
_with($value, $type)
Definition: Message.php:204

Here is the call graph for this function:

Hoa\XmlRpc\Message\Message::withStructure ( )

Start a structure.

Parameters
mixed$dataData.
Returns

Definition at line 312 of file Message.php.

313  {
314  $self = __CLASS__;
315 
316  return new $self(self::IS_STRUCTURE, $this);
317  }

Member Data Documentation

Hoa\XmlRpc\Message\Message::$_is = self::IS_SCALAR
protected

Definition at line 176 of file Message.php.

Hoa\XmlRpc\Message\Message::$_name = 'undefined'
protected

Definition at line 169 of file Message.php.

Hoa\XmlRpc\Message\Message::$_parent = null
protected

Definition at line 162 of file Message.php.

Hoa\XmlRpc\Message\Message::$_values = []
protected

Definition at line 155 of file Message.php.

const Hoa\XmlRpc\Message\Message::IS_ARRAY = 12

Whether we manipulate an array.

int

Definition at line 141 of file Message.php.

const Hoa\XmlRpc\Message\Message::IS_SCALAR = 11

Whether we manipulate a scalar.

int

Definition at line 134 of file Message.php.

const Hoa\XmlRpc\Message\Message::IS_STRUCTURE = 13

Whether we manipulate a structure.

int

Definition at line 148 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE = 1

Values bucket: type index.

int

Definition at line 64 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_ARRAY = 2

Value type: <array>.

int

Definition at line 71 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_BASE64 = 3

Value type: <base64>.

int

Definition at line 78 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_BOOLEAN = 4

Value type: <boolean>.

int

Definition at line 85 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_DATETIME = 5

Value type: <datetime.iso8601>.

int

Definition at line 92 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_FLOAT = 6

Value type: <double>.

int

Definition at line 99 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_INTEGER = 7

Value type: <i4> or <integer>.

int

Definition at line 106 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_NULL = 10

Value type: <nil>.

int

Definition at line 127 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_STRING = 8

Value type: <string>.

int

Definition at line 113 of file Message.php.

const Hoa\XmlRpc\Message\Message::TYPE_STRUCTURE = 9

Value type: <structure>.

int

Definition at line 120 of file Message.php.

const Hoa\XmlRpc\Message\Message::VALUE = 0

Values bucket: value index.

int

Definition at line 57 of file Message.php.


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