ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
Boolean.php
Go to the documentation of this file.
1 <?php
2 
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4 
5 // LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6 
40 // }}}
41 
42 // dependencies {{{
43 require_once 'XML/RPC2/Exception.php';
44 require_once 'XML/RPC2/Backend/Php/Value/Scalar.php';
45 // }}}
46 
58 {
59 
60  // {{{ constructor
61 
67  public function __construct($nativeValue)
68  {
69  parent::__construct('boolean', $nativeValue);
70  }
71 
72  // }}}
73  // {{{ encode()
74 
80  public function encode()
81  {
82  return '<boolean>' . ($this->getNativeValue() ? 1 : 0). '</boolean>';
83  }
84 
85  // }}}
86  // {{{ decode()
87 
93  public static function decode($xml)
94  {
95  // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
96  // xpath is used both in an element and in one of its children
97  $xml = simplexml_load_string($xml->asXML());
98  $value = $xml->xpath('/value/boolean/text()');
99 
100  // Double cast explanation: http://pear.php.net/bugs/bug.php?id=8644
101  return (boolean) ((string) $value[0]);
102  }
103 
104  // }}}
105 
106 }
107 
108 ?>