XRL  latest
Simple XML-RPC Library (both client and server)
Response.php
1 <?php
2 /*
3  * This file is part of XRL, a simple XML-RPC Library for PHP.
4  *
5  * Copyright (c) 2012, XRL Team. All rights reserved.
6  * XRL is licensed under the 3-clause BSD License.
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace fpoirotte\XRL;
13 
22 {
24  protected $result;
25 
33  public function __construct($xmlResult)
34  {
35  if (!is_string($xmlResult)) {
36  throw new \InvalidArgumentException('Not a valid response');
37  }
38 
39  $this->result = $xmlResult;
40  }
41 
43  public function __toString()
44  {
45  return (string) $this->result;
46  }
47 
59  protected function addHeader($header)
60  {
61  header($header);
62  return $this;
63  }
64 
73  protected function finalize($result)
74  {
75  exit($result);
76  }
77 
79  public function publish()
80  {
81  $result = (string) $this->result;
82  $this->addHeader('Content-Type: text/xml')
83  ->addHeader('Content-Length: ' . strlen($result))
84  ->finalize($result);
85  }
86 }
This class represents the response to an XML-RPC request.
Definition: Response.php:21
Interface for the response to an XML-RPC request, as produced by an XML-RPC server.
$result
The response to an XML-RPC request, as serialized XML.
Definition: Response.php:24
__construct($xmlResult)
Definition: Response.php:33