12 namespace fpoirotte\XRL;
101 if ($encoder === null) {
102 $encoder = new \fpoirotte\XRL\NativeEncoder(
103 new \fpoirotte\XRL\
Encoder(null,
false,
true)
107 if ($decoder === null) {
108 $decoder = new \fpoirotte\XRL\NativeDecoder(
109 new \fpoirotte\XRL\
Decoder(null,
true)
113 $this->XRLEncoder = $encoder;
114 $this->XRLDecoder = $decoder;
115 $this->XRLFunctions = array();
139 public function __set($func, $callback)
141 $this->XRLFunctions[$func] = new \fpoirotte\XRL\CallableObject($callback);
151 $this->XRLFunctions[$func] = new \fpoirotte\XRL\CallableObject($callback);
176 return $this->XRLFunctions[$func];
186 return $this->XRLFunctions[$func];
203 return isset($this->XRLFunctions[$func]);
213 return isset($this->XRLFunctions[$func]);
229 unset($this->XRLFunctions[$func]);
239 unset($this->XRLFunctions[$func]);
252 return count($this->XRLFunctions);
265 return new \ArrayIterator($this->XRLFunctions);
292 public function expose($other, $prefix =
'')
294 if (!is_string($other) && !is_object($other)) {
295 throw new \InvalidArgumentException(
'Invalid adoption');
298 if (!is_string($prefix)) {
299 throw new \InvalidArgumentException(
'Invalid prefix');
302 $prefix = rtrim($prefix,
'.');
303 if ($prefix !==
'') {
307 if (is_object($other)) {
309 $class = get_class($other);
310 foreach (get_class_methods($class) as $method) {
315 $reflector = new \ReflectionMethod($class, $method);
316 if ($reflector->isPublic() && !$reflector->isConstructor() &&
317 !$reflector->isStatic()) {
318 $this[$prefix . $method] = array($other, $method);
323 foreach (get_class_methods($other) as $method) {
325 $reflector = new \ReflectionMethod($other, $method);
326 if ($reflector->isPublic() && $reflector->isStatic()) {
327 $this[$prefix . $method] = array($other, $method);
357 $URI =
'php://input';
361 $request = $this->XRLDecoder->decodeRequest($URI);
362 $procedure = $request->getProcedure();
364 $params = $request->getParams();
366 $result = $this->
call($procedure, $params);
367 $response = $this->XRLEncoder->encodeResponse($result);
369 $response = $this->XRLEncoder->encodeError($result);
372 return new \fpoirotte\XRL\Response($response);
387 public function call($procedure, array $params)
389 if (!is_string($procedure)) {
390 throw new \BadFunctionCallException(
'Expected a string');
393 if (!isset($this->XRLFunctions[$procedure])) {
397 $callable = $this->XRLFunctions[$procedure];
398 return $callable->invokeArgs($params);
Interface to provide accessing objects as arrays.
Interface for an XML-RPC decoder.
Interface for an XML-RPC encoder.
$XRLEncoder
Encoder for the request.
Interface to create an external Iterator.
An XML-RPC encoder that can produce either compact documents or pretty documents. ...
An exception that is used to represent XML-RPC errors.
call($procedure, array $params)
offsetSet($func, $callback)
$XRLFunctions
Registered "procedures".
A decoder that can process XML-RPC requests and responses, with optional XML validation.
$XRLDecoder
Decoder for the response.
__construct(\fpoirotte\XRL\EncoderInterface $encoder=null,\fpoirotte\XRL\DecoderInterface $decoder=null)
const METHOD_NOT_FOUND
Alias for the corresponding interoperability fault.
expose($other, $prefix= '')
Classes implementing Countable can be used with the count() function.