HttpRequestGatewayFactory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * This file is part of amfPHP
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the license that is bundled
  8. * with this package in the file license.txt.
  9. */
  10. /**
  11. * A gateway factory's job is to create a gateway. There can be many gateway factories, but as such the only one for now is this one,
  12. * which creates a gateway assuming that the data to be processed is in an http request and thus available through the usual php globals
  13. *
  14. * @package Amfphp_Core
  15. * @author Ariel Sommeria-Klein
  16. */
  17. class Amfphp_Core_HttpRequestGatewayFactory {
  18. /**
  19. * there seems to be some confusion in the php doc as to where best to get the raw post data from.
  20. * try $GLOBALS['HTTP_RAW_POST_DATA'] and php://input
  21. *
  22. * @return <String> it's a binary stream, but there seems to be no better type than String for this.
  23. */
  24. static protected function getRawPostData(){
  25. if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
  26. return $GLOBALS['HTTP_RAW_POST_DATA'];
  27. }else{
  28. return file_get_contents('php://input');
  29. }
  30. }
  31. /**
  32. * create the gateway.
  33. * content type is recovered by looking at the GET parameter contentType. If it isn't set, it looks in the content headers.
  34. * @param Amfphp_Core_Config $config optional. If null, the gateway will use the default
  35. * @return Amfphp_Core_Gateway
  36. */
  37. static public function createGateway(Amfphp_Core_Config $config = null){
  38. $contentType = null;
  39. if(isset ($_GET['contentType'])){
  40. $contentType = $_GET['contentType'];
  41. }else if(isset ($_SERVER['CONTENT_TYPE'])){
  42. $contentType = $_SERVER['CONTENT_TYPE'];
  43. }
  44. $rawInputData = self::getRawPostData();
  45. return new Amfphp_Core_Gateway($_GET, $_POST, $rawInputData, $contentType, $config);
  46. }
  47. }
  48. ?>