xref: /plugin/davcal/vendor/sabre/http/examples/stringify.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehler/**
4*a1a3b679SAndreas Boehler * This simple example shows the capability of Request and Response objects to
5*a1a3b679SAndreas Boehler * serialize themselves as strings.
6*a1a3b679SAndreas Boehler *
7*a1a3b679SAndreas Boehler * This is mainly useful for debugging purposes.
8*a1a3b679SAndreas Boehler *
9*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
10*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
11*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
12*a1a3b679SAndreas Boehler */
13*a1a3b679SAndreas Boehleruse Sabre\HTTP\Request;
14*a1a3b679SAndreas Boehleruse Sabre\HTTP\Response;
15*a1a3b679SAndreas Boehler
16*a1a3b679SAndreas Boehler// Find the autoloader
17*a1a3b679SAndreas Boehler$paths = [
18*a1a3b679SAndreas Boehler    __DIR__ . '/../vendor/autoload.php',
19*a1a3b679SAndreas Boehler    __DIR__ . '/../../../autoload.php',
20*a1a3b679SAndreas Boehler    __DIR__ . '/vendor/autoload.php',
21*a1a3b679SAndreas Boehler
22*a1a3b679SAndreas Boehler];
23*a1a3b679SAndreas Boehlerforeach ($paths as $path) {
24*a1a3b679SAndreas Boehler    if (file_exists($path)) {
25*a1a3b679SAndreas Boehler        include $path;
26*a1a3b679SAndreas Boehler        break;
27*a1a3b679SAndreas Boehler    }
28*a1a3b679SAndreas Boehler}
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler$request = new Request('POST', '/foo');
31*a1a3b679SAndreas Boehler$request->setHeaders([
32*a1a3b679SAndreas Boehler    'Host'         => 'example.org',
33*a1a3b679SAndreas Boehler    'Content-Type' => 'application/json'
34*a1a3b679SAndreas Boehler    ]);
35*a1a3b679SAndreas Boehler
36*a1a3b679SAndreas Boehler$request->setBody(json_encode(['foo' => 'bar']));
37*a1a3b679SAndreas Boehler
38*a1a3b679SAndreas Boehlerecho $request;
39*a1a3b679SAndreas Boehlerecho "\r\n\r\n";
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler$response = new Response(424);
42*a1a3b679SAndreas Boehler$response->setHeaders([
43*a1a3b679SAndreas Boehler    'Content-Type' => 'text/plain',
44*a1a3b679SAndreas Boehler    'Connection'   => 'close',
45*a1a3b679SAndreas Boehler    ]);
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler$response->setBody("ABORT! ABORT!");
48*a1a3b679SAndreas Boehler
49*a1a3b679SAndreas Boehlerecho $response;
50*a1a3b679SAndreas Boehler
51*a1a3b679SAndreas Boehlerecho "\r\n";
52