PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/pear/php/PHP/Depend/Util/UUID.php

https://github.com/wrobel/horde-glue
PHP | 96 lines | 19 code | 3 blank | 74 comment | 0 complexity | eeade1d08a0a3b38c3555310be3939d3 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * This file is part of PHP_Depend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2009, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @category QualityAssurance
  40. * @package PHP_Depend
  41. * @subpackage Util
  42. * @author Manuel Pichler <mapi@pdepend.org>
  43. * @copyright 2008-2009 Manuel Pichler. All rights reserved.
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. * @version SVN: $Id$
  46. * @link http://pdepend.org/
  47. */
  48. /**
  49. * Simple utility class that creates uuid keys.
  50. *
  51. * This implementation is based on code from a user comment at php.net.
  52. * http://de3.php.net/manual/en/function.uniqid.php#69164
  53. *
  54. * @category QualityAssurance
  55. * @package PHP_Depend
  56. * @subpackage Util
  57. * @author Manuel Pichler <mapi@pdepend.org>
  58. * @copyright 2008-2009 Manuel Pichler. All rights reserved.
  59. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  60. * @version Release: 0.9.7
  61. * @link http://pdepend.org/
  62. */
  63. final class PHP_Depend_Util_UUID
  64. {
  65. /**
  66. * The generated uuid.
  67. *
  68. * @var string $_uuid
  69. */
  70. private $_uuid = null;
  71. /**
  72. * The ctor generates a uuid.
  73. */
  74. public function __construct()
  75. {
  76. $this->_uuid = sprintf(
  77. '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  78. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  79. mt_rand(0, 0x0fff) | 0x4000,
  80. mt_rand(0, 0x3fff) | 0x8000,
  81. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
  82. );
  83. }
  84. /**
  85. * Returns the string representation of this class.
  86. *
  87. * @return string
  88. */
  89. public function __toString()
  90. {
  91. return $this->_uuid;
  92. }
  93. }