ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Scalar.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 {{{
43require_once 'XML/RPC2/Exception.php';
44require_once 'XML/RPC2/Backend/Php/Value.php';
45// }}}
46
58{
59
60 // {{{ properties
61
67 private $_scalarType = null;
68
69 // }}}
70 // {{{ setScalarType()
71
77 protected function setScalarType($value)
78 {
79 switch ($value) {
80 case 'int':
81 case 'i4':
82 case 'boolean':
83 case 'string':
84 case 'double':
85 case 'dateTime.iso8601':
86 case 'base64':
87 $this->_scalarType = $value;
88 break;
89 default:
90 throw new XML_RPC2_InvalidTypeException(sprintf('Type \'%s\' is not an XML-RPC scalar type', $value));
91 }
92 }
93
94 // }}}
95 // {{{ getScalarType()
96
102 public function getScalarType()
103 {
104 return $this->_scalarType;
105 }
106
107 // }}}
108 // {{{ constructor
109
115 public function __construct($scalarType, $nativeValue)
116 {
117 $this->setScalarType($scalarType);
118 $this->setNativeValue($nativeValue);
119 }
120
121 // }}}
122 // {{{ createFromNative()
123
133 public static function createFromNative($nativeValue, $explicitType = null)
134 {
135 if (is_null($explicitType)) {
136 switch (gettype($nativeValue)) {
137 case 'boolean':
138 case 'integer':
139 case 'double':
140 case 'string':
141 $explicitType = gettype($nativeValue);
142 break;
143 default:
144 throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode scalar value \'%s\' from type \'%s\'. Native type is not a scalar XML_RPC type (boolean, integer, double, string)',
145 (string) $nativeValue,
146 gettype($nativeValue)));
147 }
148 }
149 $explicitType = ucfirst(strtolower($explicitType));
150 require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $explicitType));
151 $explicitType = sprintf('XML_RPC2_Backend_Php_Value_%s', $explicitType);
152 return new $explicitType($nativeValue);
153 }
154
155 // }}}
156 // {{{ encode()
157
163 public function encode()
164 {
165 return '<' . $this->getScalarType() . '>' . $this->getNativeValue() . '</' . $this->getScalarType() . '>';
166 }
167
168 // }}}
169
170}
171
172?>
__construct($scalarType, $nativeValue)
Constructor.
Definition: Scalar.php:115
setScalarType($value)
scalarType property setter
Definition: Scalar.php:77
getScalarType()
scalarType property getter
Definition: Scalar.php:102
static createFromNative($nativeValue, $explicitType=null)
Choose a XML_RPC2_Value subclass appropriate for the given value and create it.
Definition: Scalar.php:133
encode()
Encode the instance into XML, for transport.
Definition: Scalar.php:163
setNativeValue($value)
nativeValue setter
Definition: Value.php:89
getNativeValue()
nativeValue property getter
Definition: Value.php:76