Request.php 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace IXR;
  3. /**
  4. * IXR请求体
  5. *
  6. * @package IXR
  7. */
  8. class Request
  9. {
  10. /**
  11. * @var string
  12. */
  13. private $xml;
  14. /**
  15. * @param string $method
  16. * @param array $args
  17. */
  18. public function __construct(string $method, array $args)
  19. {
  20. $this->xml = <<<EOD
  21. <?xml version="1.0"?>
  22. <methodCall>
  23. <methodName>{$method}</methodName>
  24. <params>
  25. EOD;
  26. foreach ($args as $arg) {
  27. $this->xml .= '<param><value>';
  28. $v = new Value($arg);
  29. $this->xml .= $v->getXml();
  30. $this->xml .= "</value></param>\n";
  31. }
  32. $this->xml .= '</params></methodCall>';
  33. }
  34. /**
  35. * @return int
  36. */
  37. public function getLength(): int
  38. {
  39. return strlen($this->xml);
  40. }
  41. /**
  42. * @return string
  43. */
  44. public function getXml(): string
  45. {
  46. return $this->xml;
  47. }
  48. }