AbstractMessage.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Amf
  17. * @subpackage Value
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AbstractMessage.php 2504 2011-12-28 07:35:29Z liu21st $
  21. */
  22. /**
  23. * This is the default Implementation of Message, which provides
  24. * a convenient base for behavior and association of common endpoints
  25. *
  26. * @package Zend_Amf
  27. * @subpackage Value
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Amf_Value_Messaging_AbstractMessage
  32. {
  33. /**
  34. * @var string Client identifier
  35. */
  36. public $clientId;
  37. /**
  38. * @var string Destination
  39. */
  40. public $destination;
  41. /**
  42. * @var string Message identifier
  43. */
  44. public $messageId;
  45. /**
  46. * @var int Message timestamp
  47. */
  48. public $timestamp;
  49. /**
  50. * @var int Message TTL
  51. */
  52. public $timeToLive;
  53. /**
  54. * @var object Message headers
  55. */
  56. public $headers;
  57. /**
  58. * @var string Message body
  59. */
  60. public $body;
  61. /**
  62. * generate a unique id
  63. *
  64. * Format is: ########-####-####-####-############
  65. * Where # is an uppercase letter or number
  66. * example: 6D9DC7EC-A273-83A9-ABE3-00005FD752D6
  67. *
  68. * @return string
  69. */
  70. public function generateId()
  71. {
  72. return sprintf(
  73. '%08X-%04X-%04X-%02X%02X-%012X',
  74. mt_rand(),
  75. mt_rand(0, 65535),
  76. bindec(substr_replace(
  77. sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
  78. ),
  79. bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)),
  80. mt_rand(0, 255),
  81. mt_rand()
  82. );
  83. }
  84. }