stringify.php 1.1 KB

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