/** * {@inheritdoc} */ public function toLdap($guid) { $guid = strtolower($guid) === self::AUTO ? LdapUtilities::uuid4() : $guid; if (!LdapUtilities::isValidGuid($guid)) { throw new AttributeConverterException(sprintf('The value "%s" is not a valid GUID.', $guid)); } $guid = (new GUID($guid))->toBinary(); if ($this->getOperationType() == self::TYPE_SEARCH_TO) { $guid = implode('', preg_filter('/^/', '\\', str_split(bin2hex($guid), 2))); } return $guid; }
function it_should_check_if_a_value_is_a_valid_GUID() { $this::isValidGuid(LdapUtilities::uuid4())->shouldBeEqualTo(true); $this::isValidGuid('bc7d93d1-3d4d-4535-88bb-d61758684700')->shouldBeEqualTo(true); $this::isValidGuid('bc7d93d1-3d4d-4535-88bb')->shouldBeEqualTo(false); $this::isValidGuid('bc7d93d-3d4-4535-88bb-d6175868470')->shouldBeEqualTo(false); $this::isValidGuid('foo')->shouldBeEqualTo(false); }