Advertisement
fruffl

ILLI\System\UUID

Jul 30th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?PHP
  2.     /**
  3.      * ILLI
  4.      *
  5.      * @category   ILLI_System
  6.      * @package    ILLI
  7.      * @link       http://illi.be
  8.      * @license    http://l.illi.be
  9.      * @copyright  ILLI Conference
  10.      */
  11.     NAMESPACE ILLI\System;
  12.  
  13.     /**
  14.      * ILLI Initial Object
  15.      *
  16.      * @category   ILLI_Boot
  17.      * @package    ILLI
  18.      * @subpackage Boot
  19.      * @namespace  ILLI\Boot
  20.      * @link       http://illi.be
  21.      * @license    http://l.illi.be
  22.      * @copyright  ILLI Conference
  23.      * @since      2.0.1
  24.      * @version    3.0.1
  25.      */
  26.     CLASS UUID EXTENDS Object
  27.     {
  28.         /**
  29.          * @const int 00001111
  30.          */
  31.         const UUID_VERSION_CLEAR    = 15;
  32.        
  33.         /**
  34.          * @const int 01000000
  35.          */
  36.         const UUID_VERSION_4        = 64;
  37.        
  38.         /**
  39.          * @const int 00111111
  40.          */
  41.         const UUID_VARIANT_CLEAR    = 63;
  42.        
  43.         /**
  44.          * @const int 10000000
  45.          */
  46.         const UUID_VARIANT_RFC      = 128;
  47.        
  48.         /**
  49.          * result
  50.          */
  51.         private $__value        = '';
  52.        
  53.        
  54.         public function __construct()
  55.         {
  56.             parent::__construct();
  57.            
  58.             $uuid = (string) new Rand(16);
  59.             $uuid[6] = chr(ord($uuid[6]) & static::UUID_VERSION_CLEAR | static::UUID_VERSION_4);
  60.             $uuid[8] = chr(ord($uuid[8]) & static::UUID_VARIANT_CLEAR | static::UUID_VARIANT_RFC);
  61.        
  62.             $this->__value = implode('-', array(
  63.                 bin2hex(substr($uuid, 0, 4)),
  64.                 bin2hex(substr($uuid, 4, 2)),
  65.                 bin2hex(substr($uuid, 6, 2)),
  66.                 bin2hex(substr($uuid, 8, 2)),
  67.                 bin2hex(substr($uuid, 10, 6))
  68.             ));
  69.         }
  70.        
  71.         public function __tostring()
  72.         {
  73.             return $this->__value;
  74.         }
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement