Adldap\Utilities::binaryGuidToString PHP Method

binaryGuidToString() public static method

Convert a binary GUID to a string GUID.
public static binaryGuidToString ( string $binGuid ) : string
$binGuid string
return string
    public static function binaryGuidToString($binGuid)
    {
        if (trim($binGuid) == '' || is_null($binGuid)) {
            return;
        }
        $hex = unpack('H*hex', $binGuid)['hex'];
        $hex1 = substr($hex, -26, 2) . substr($hex, -28, 2) . substr($hex, -30, 2) . substr($hex, -32, 2);
        $hex2 = substr($hex, -22, 2) . substr($hex, -24, 2);
        $hex3 = substr($hex, -18, 2) . substr($hex, -20, 2);
        $hex4 = substr($hex, -16, 4);
        $hex5 = substr($hex, -12, 12);
        $guid = sprintf('%s-%s-%s-%s-%s', $hex1, $hex2, $hex3, $hex4, $hex5);
        return $guid;
    }

Usage Example

Example #1
0
 /**
  * Returns the model's GUID.
  *
  * @return string
  */
 public function getGuid()
 {
     return Utilities::binaryGuidToString($this->getFirstAttribute($this->schema->objectGuid()));
 }