Extended use UUID function in PHP

Environment:
CentOS Linux Release 7.7.1908 (Core)
PHP 7.3.11
UUID Extention 1.0.4

PHP support for UUID feeling does not seem really serious, UUID PECL extension is merely to package libuuid, and not as straightforward to provide a complete realization UUID as other languages. Since libuuid provide only version 1 and version UUID 4, so ...... happy that these two suffice.


uuid_create( [int $uuid_type = UUID_TYPE_DEFAULT] ) : string

 $uuid_type 

  One of the following constants:
    UUID_TYPE_DEFAULT     // 0
     UUID_TYPE_TIME        // 1
     UUID_TYPE_DCE         // 4
     UUID_TYPE_NAME        // 1
     UUID_TYPE_RANDOM      // 4
  libuuid provides a UUID version 1 and 4 to achieve, but also defines only  UUID_TYPE_DCE_TIME  and  UUID_TYPE_DCE_RANDOM  two constants. PHP's UUID extensions, constants are constant mapping libuuid by definition. So, while the extension defines four constants according to UUID standard name, but for the current version of libuuid, it can only be mapped to two constants. UUID_TYPE_TIME  mapping the constant libuuid  UUID_TYPE_DCE_TIME  , UUID corresponding to version 1 implemented;  UUID_TYPE_RANDOM  mapped to the constant libuuid  UUID_TYPE_DCE_RANDOM  , corresponding to implement uuid version 4. The  UUID_TYPE_DCE  and UUID_TYPE_NAME  two constants, although it is easy to see from the constant's name corresponds to the UUID version 2 and version 3, 5, but can only be mapped to a constant libuuid of  UUID_TYPE_DCE_RANDOM  and  UUID_TYPE_DCE_TIME  , can be used but does not have practical significance.
  Constant  UUID_TYPE_DEFAULT  is the default value, indicating the default selection of libuuid. By default, if the present system is a high-quality random number (such as / dev / urandom or / dev / random available), provides the UUID 4 version, version or UUID 1 is provided. UUID version 1 is generally believed that the probability of duplication of a smaller, almost can guarantee true uniqueness, but considering the MAC leak caused by security concerns, most of the time or tend to use UUID version 4.
return
  If the parameters are valid (0,1 or 4), and returns the string UUID.
  If the argument can not be identified, throw a warning message and return to the default UUID string.


uuid_is_valid( string $uuid ) : bool

 $uuid 

  UUID string to be tested.
return
  return true or false. $ uuid are not case sensitive.


uuid_compare(string $uuid1, string $uuid2) : int

 $uuid1 ,  $uuid2 

  UUID string to be compared.
returen
  If  $ UUID1  or  $ UUID2  not valid UUID string, bool return value  to false  .
  If  $ UUID1  and  $ uui2  not identical:  $ UUID1 $ UUID2  , returns a positive integer;  $ UUID1 $ UUID2  , it returns a negative integer.
  If  $ UUID1 = $ UUID2  , returns integer value 0.


uuid_is_null(string $uuid) : bool

 $uuid 

  UUID string to be tested.
return
  if  $ uuid  is not a valid UUID string, it returns  false  .
  If  $ uuid  is not NULL UUID string, it returns  false  .
  If  $ uuid  is NULL UUID string, returns  to true  .
UUID NULL
  '00000000-0000-0000-0000-000000000000' it is the UUID string 0 is called a NULL UUID (or NIL UUID?).


uuid_type(string $uuid) : int

 $uuid 

  Uuid string to be tested.
return
  if  $ uuid  is not a valid UUID string, the return value bool  false  .
  If  $ UUID  is NULL UUID, returns the integer value of -1.
  If  $ UUID  is valid UUID string, returns 4 or 5, the corresponding version of the UUID.


uuid_variant(string $uuid) : int

 $uuid 

  UUID string to be tested.
return
  if  $ UUID  is not a valid string UUID, bool return type value  to false  .
  If  $ UUID  is NULL UUID, returns the integer value of -1.
  If  $ UUID  is valid UUID string, it returns an integer value 0, 1 or 3.
  The constant name libuuid defined, it is easy to distinguish the meaning of the return value:
    UUID_VARIANT_NCS           // 0 
     UUID_VARIANT_DCE           // . 1 
     UUID_VARIANT_MICROSOFT     // 2 
     UUID_VARIANT_OTHER         // . 3 


uuid_time(string $uuid) : int

 $uuid 

  UUID strings to be parsed.
return
  if  $ UUID  is not a valid string UUID, if  $ UUID  not rfc4122 defined variants (uuid_variant () returns a value of 1, in libuuid predefined constants  UUID_VARIANT_DCE  ), if  $ UUID  UUID not the version 1 (based on UUID time), bool value is returned  to false  .
  If  $ UUID  is defined based on the version of a configuration rfc4122 UUID, it returns an integer value. The UNIX timestamp value is constructed UUID string was used.


uuid_mac(string $uuid) : string

 $uuid 

  Uuid string to be parsed.
return
  if  $ UUID  is not a valid string UUID, if  $ UUID  not rfc4122 defined variants (uuid_variant () returns a value of 1, in libuuid predefined constants  UUID_VARIANT_DCE  ), if  $ UUID  UUID not the version 1 (based on UUID time), bool value is returned  to false  .
  If configured  $ UUID  is not a valid MAC address to be used when, bool value is returned  to false  .
  If  $ UUID  is defined based on the version of a configuration rfc4122 UUID, and configured  $ UUID  used when a valid MAC address, the MAC address is returned, represented as a string of 12 hexadecimal.


uuid_parse(string $uuid) : string

 $uuid 

  UUID string to be packaged.
return
  if  $ uuid  is not a valid UUID string, the return value bool  false  .
  If  $ UUID  is valid UUID string, then remove "-" after the package into a 16-bit binary strings of the front and high return. Similar functions in PHP pack ( 'L *') effects.


uuid_unparse(string $uuid) : string

  Function uuid_parse () of the inverse process. If the parameter data is valid, a UUID string is returned, otherwise bool value  to false  .

 

OK, that's all. Hope that helps.

Reference:
https://tools.ietf.org/html/rfc4122
https://sourceforge.net/p/libuuid/code/ci/master/tree/

Guess you like

Origin www.cnblogs.com/cndavidwang/p/11939424.html