99 if ($encoder === null) {
100 $encoder = new \fpoirotte\XRL\NativeEncoder(
105 if ($decoder === null) {
106 $decoder = new \fpoirotte\XRL\NativeDecoder(
111 $this->XRLEncoder = $encoder;
112 $this->XRLDecoder = $decoder;
113 $this->XRLFunctions = array();
137 public function __set($func, $callback)
139 $this->XRLFunctions[$func] = new \fpoirotte\XRL\CallableObject($callback);
149 $this->XRLFunctions[$func] = new \fpoirotte\XRL\CallableObject($callback);
174 return $this->XRLFunctions[$func];
184 return $this->XRLFunctions[$func];
201 return isset($this->XRLFunctions[$func]);
211 return isset($this->XRLFunctions[$func]);
227 unset($this->XRLFunctions[$func]);
237 unset($this->XRLFunctions[$func]);
250 return count($this->XRLFunctions);
263 return new \ArrayIterator($this->XRLFunctions);
290 public function expose($other, $prefix =
'')
292 if (!is_string($other) && !is_object($other)) {
293 throw new \InvalidArgumentException(
'Invalid adoption');
296 if (!is_string($prefix)) {
297 throw new \InvalidArgumentException(
'Invalid prefix');
300 $prefix = rtrim($prefix,
'.');
301 if ($prefix !==
'') {
305 if (is_object($other)) {
307 $class = get_class($other);
308 foreach (get_class_methods($class) as $method) {
313 $reflector = new \ReflectionMethod($class, $method);
314 if ($reflector->isPublic() && !$reflector->isConstructor() &&
315 !$reflector->isStatic()) {
316 $this[$prefix . $method] = array($other, $method);
321 foreach (get_class_methods($other) as $method) {
323 $reflector = new \ReflectionMethod($other, $method);
324 if ($reflector->isPublic() && $reflector->isStatic()) {
325 $this[$prefix . $method] = array($other, $method);
355 $URI =
'php://input';
359 $request = $this->XRLDecoder->decodeRequest($URI);
360 $procedure = $request->getProcedure();
362 $params = $request->getParams();
364 $result = $this->
call($procedure, $params);
365 $response = $this->XRLEncoder->encodeResponse($result);
367 $response = $this->XRLEncoder->encodeError($result);
370 return new \fpoirotte\XRL\Response($response);
385 public function call($procedure, array $params)
387 if (!is_string($procedure)) {
388 throw new \BadFunctionCallException(
'Expected a string');
391 if (!isset($this->XRLFunctions[$procedure])) {
392 throw new \fpoirotte\XRL\Faults\MethodNotFoundException();
395 $callable = $this->XRLFunctions[$procedure];
396 return $callable(...$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)
expose($other, $prefix= '')
Classes implementing Countable can be used with the count() function.