AcknowledgeMessage.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * Used to generate a Flex Acknowledge message.
  12. * part of the AmfphpFlexMessaging plugin
  13. *
  14. * @package Amfphp_Plugins_FlexMessaging
  15. * @author Ariel Sommeria-Klein
  16. */
  17. class AmfphpFlexMessaging_AcknowledgeMessage {
  18. /**
  19. * correlation id. guid
  20. * @see generateRandomId
  21. * @var string
  22. */
  23. public $correlationId;
  24. /**
  25. * message id. guid
  26. * @see generateRandomId
  27. * @var string
  28. */
  29. public $messageId;
  30. /**
  31. * client id. guid
  32. * @see generateRandomId
  33. * @var string
  34. */
  35. public $clientId;
  36. /**
  37. * destination
  38. * @var string
  39. */
  40. public $destination;
  41. /**
  42. * body
  43. * @var stdClass
  44. */
  45. public $body;
  46. /**
  47. * time to live
  48. * @var int
  49. */
  50. public $timeToLive;
  51. /**
  52. * time stamp
  53. * @var int
  54. */
  55. public $timestamp;
  56. /**
  57. * headers. DSId(string), DSMessagingVersion(int)
  58. * @var stdClass
  59. */
  60. public $headers;
  61. /**
  62. * constructor
  63. * @param string $correlationId
  64. */
  65. public function __construct($correlationId) {
  66. $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
  67. $this->$explicitTypeField = AmfphpFlexMessaging::FLEX_TYPE_ACKNOWLEDGE_MESSAGE;
  68. $this->correlationId = $correlationId;
  69. $this->messageId = $this->generateRandomId();
  70. $this->clientId = $this->generateRandomId();
  71. $this->destination = null;
  72. $this->body = null;
  73. $this->timeToLive = 0;
  74. $this->timestamp = (int) (time() . '00');
  75. $this->headers = new stdClass();
  76. }
  77. /**
  78. * generate random id
  79. * @return string
  80. */
  81. public function generateRandomId() {
  82. // version 4 UUID
  83. return sprintf(
  84. '%08X-%04X-%04X-%02X%02X-%012X', mt_rand(), mt_rand(0, 65535), bindec(substr_replace(
  85. sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
  86. ), bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)), mt_rand(0, 255), mt_rand()
  87. );
  88. }
  89. }
  90. ?>