AmfphpDummy.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * This catches browser requests to the gateway, to show something more helpful than an error message.
  12. *
  13. * @package Amfphp_Plugins_Dummy
  14. * @author Ariel Sommeria-Klein, Daniel Hoffmann (intermedi8.de)
  15. */
  16. class AmfphpDummy implements Amfphp_Core_Common_IDeserializer, Amfphp_Core_Common_IDeserializedRequestHandler, Amfphp_Core_Common_IExceptionHandler, Amfphp_Core_Common_ISerializer {
  17. /**
  18. * if content type is not set or content is set to "application/x-www-form-urlencoded", this plugin will handle the request
  19. */
  20. const CONTENT_TYPE = "application/x-www-form-urlencoded";
  21. /**
  22. * constructor.
  23. * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  24. */
  25. public function __construct(array $config = null) {
  26. $filterManager = Amfphp_Core_FilterManager::getInstance();
  27. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZER, $this, "filterHandler");
  28. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST_HANDLER, $this, "filterHandler");
  29. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_EXCEPTION_HANDLER, $this, "filterHandler");
  30. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZER, $this, "filterHandler");
  31. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_HEADERS, $this, "filterHeaders");
  32. }
  33. /**
  34. * if no content type, then returns this.
  35. * @param mixed null at call in gateway.
  36. * @param String $contentType
  37. * @return this or null
  38. */
  39. public function filterHandler($handler, $contentType) {
  40. if (!$contentType || $contentType == self::CONTENT_TYPE) {
  41. return $this;
  42. }
  43. }
  44. /**
  45. * deserialize
  46. * @see Amfphp_Core_Common_IDeserializer
  47. * @param array $getData
  48. * @param array $postData
  49. * @param string $rawPostData
  50. * @return string
  51. */
  52. public function deserialize(array $getData, array $postData, $rawPostData) {
  53. $ret = new stdClass();
  54. return $ret;
  55. }
  56. /**
  57. * handle deserialized request
  58. * @see Amfphp_Core_Common_IDeserializedRequestHandler
  59. * @param mixed $deserializedRequest
  60. * @param Amfphp_Core_Common_ServiceRouter $serviceRouter
  61. * @return mixed
  62. */
  63. public function handleDeserializedRequest($deserializedRequest, Amfphp_Core_Common_ServiceRouter $serviceRouter) {
  64. }
  65. /**
  66. * handle exception
  67. * @see Amfphp_Core_Common_IExceptionHandler
  68. * @param Exception $exception
  69. */
  70. public function handleException(Exception $exception) {
  71. }
  72. /**
  73. * serialize. just includes index.html
  74. * @see Amfphp_Core_Common_ISerializer
  75. * @param mixed $data
  76. * @return mixed
  77. */
  78. public function serialize($data) {
  79. include(dirname(__FILE__) . "/index.html");
  80. }
  81. /**
  82. * filter the headers to make sure the content type is set to text/html if the request was handled by the service browser
  83. * @param array $headers
  84. * @param string $contentType
  85. * @return array
  86. */
  87. public function filterHeaders($headers, $contentType) {
  88. if (!$contentType || $contentType == self::CONTENT_TYPE) {
  89. return array();
  90. }
  91. }
  92. }
  93. ?>