4 * This file is part of the civicrm-cxn-rpc package.
6 * Copyright (c) CiviCRM LLC <info@civicrm.org>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this package.
12 namespace Civi\Cxn\Rpc
;
14 abstract class Message
{
16 protected $code = 200;
17 protected $headers = array();
20 public function __construct($data) {
28 abstract public function encode();
33 public function getCode() {
41 public function setCode($code) {
49 public function getData() {
57 public function setData($data) {
65 public function getHeaders() {
66 return $this->headers
;
70 * @param array $headers
73 public function setHeaders($headers) {
74 $this->headers
= $headers;
79 * Extract the necessary parts to return this
80 * message as an HTTP response.
83 * array($headers, $blob, $code)
85 public function toHttp() {
86 return array($this->headers
, $this->encode(), $this->code
);
90 * Send this message immediately.
92 public function send() {
93 list ($headers, $blob, $code) = $this->toHttp();
94 header('Content-Type: ' . Constants
::MIME_TYPE
);
95 header("X-PHP-Response-Code: $code", TRUE, $code);
96 foreach ($headers as $n => $v) {
103 * Convert this message a Symfony "Response" object.
105 * @return \Symfony\Component\HttpFoundation\Response
107 public function toSymfonyResponse() {
108 $headers = array_merge(
109 array('Content-Type' => Constants
::MIME_TYPE
),
112 return new \Symfony\Component\HttpFoundation\
Response(