repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ldaptools/ldaptools | src/LdapTools/Object/LdapObject.php | LdapObject.addAttributeValue | protected function addAttributeValue($value, $valueToAdd)
{
$valueToAdd = is_array($valueToAdd) ? $valueToAdd : [ $valueToAdd ];
$value = is_array($value) ? $value : [ $value ];
return array_merge($value, $valueToAdd);
} | php | protected function addAttributeValue($value, $valueToAdd)
{
$valueToAdd = is_array($valueToAdd) ? $valueToAdd : [ $valueToAdd ];
$value = is_array($value) ? $value : [ $value ];
return array_merge($value, $valueToAdd);
} | [
"protected",
"function",
"addAttributeValue",
"(",
"$",
"value",
",",
"$",
"valueToAdd",
")",
"{",
"$",
"valueToAdd",
"=",
"is_array",
"(",
"$",
"valueToAdd",
")",
"?",
"$",
"valueToAdd",
":",
"[",
"$",
"valueToAdd",
"]",
";",
"$",
"value",
"=",
"is_arra... | Adds an additional value to an existing LDAP attribute value.
@param mixed $value
@param mixed $valueToAdd
@return array | [
"Adds",
"an",
"additional",
"value",
"to",
"an",
"existing",
"LDAP",
"attribute",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObject.php#L378-L384 | train |
ldaptools/ldaptools | src/LdapTools/Operation/QueryOperation.php | QueryOperation.setScope | public function setScope($scope)
{
if (!in_array($scope, self::SCOPE)) {
throw new LdapQueryException(sprintf(
'Scope type "%s" is invalid. See the QueryOperation::SCOPE[] constant for valid types.', $scope
));
}
$this->properties['scope'] = $scope;
return $this;
} | php | public function setScope($scope)
{
if (!in_array($scope, self::SCOPE)) {
throw new LdapQueryException(sprintf(
'Scope type "%s" is invalid. See the QueryOperation::SCOPE[] constant for valid types.', $scope
));
}
$this->properties['scope'] = $scope;
return $this;
} | [
"public",
"function",
"setScope",
"(",
"$",
"scope",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"scope",
",",
"self",
"::",
"SCOPE",
")",
")",
"{",
"throw",
"new",
"LdapQueryException",
"(",
"sprintf",
"(",
"'Scope type \"%s\" is invalid. See the QueryOpe... | Set the scope for the LDAP query operation.
@param $scope
@return $this
@throws LdapQueryException | [
"Set",
"the",
"scope",
"for",
"the",
"LDAP",
"query",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/QueryOperation.php#L135-L145 | train |
ldaptools/ldaptools | src/LdapTools/Enums/AD/ResponseCode.php | ResponseCode.getMessageForError | public static function getMessageForError($value)
{
if (self::isValidName($value)) {
$value = self::getNameValue($value);
}
return isset(self::$messages[$value]) ? self::$messages[$value] : null;
} | php | public static function getMessageForError($value)
{
if (self::isValidName($value)) {
$value = self::getNameValue($value);
}
return isset(self::$messages[$value]) ? self::$messages[$value] : null;
} | [
"public",
"static",
"function",
"getMessageForError",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"self",
"::",
"isValidName",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"getNameValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
... | Get the helpful error message for a specific error if it exists.
@param mixed $value
@return string|null | [
"Get",
"the",
"helpful",
"error",
"message",
"for",
"a",
"specific",
"error",
"if",
"it",
"exists",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Enums/AD/ResponseCode.php#L144-L151 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/LdifStringBuilderTrait.php | LdifStringBuilderTrait.addCommentsToString | protected function addCommentsToString($ldif)
{
foreach ($this->comments as $comment) {
$ldif .= Ldif::COMMENT.' '.$this->getValueForLine($comment).$this->lineEnding;
}
return $ldif;
} | php | protected function addCommentsToString($ldif)
{
foreach ($this->comments as $comment) {
$ldif .= Ldif::COMMENT.' '.$this->getValueForLine($comment).$this->lineEnding;
}
return $ldif;
} | [
"protected",
"function",
"addCommentsToString",
"(",
"$",
"ldif",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"comments",
"as",
"$",
"comment",
")",
"{",
"$",
"ldif",
".=",
"Ldif",
"::",
"COMMENT",
".",
"' '",
".",
"$",
"this",
"->",
"getValueForLine",
... | Add any specified comments to the generated LDIF.
@param string $ldif
@return string | [
"Add",
"any",
"specified",
"comments",
"to",
"the",
"generated",
"LDIF",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/LdifStringBuilderTrait.php#L145-L152 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/LdifStringBuilderTrait.php | LdifStringBuilderTrait.getLdifLine | protected function getLdifLine($directive, $value)
{
$separator = Ldif::KEY_VALUE_SEPARATOR;
// Per the RFC, any value starting with a space should be base64 encoded
if ((substr($value, 0, strlen(' ')) === ' ')) {
$separator .= Ldif::KEY_VALUE_SEPARATOR;
$value = base64_encode($value);
}
return $directive.$separator.' '.$this->getValueForLine($value).$this->lineEnding;
} | php | protected function getLdifLine($directive, $value)
{
$separator = Ldif::KEY_VALUE_SEPARATOR;
// Per the RFC, any value starting with a space should be base64 encoded
if ((substr($value, 0, strlen(' ')) === ' ')) {
$separator .= Ldif::KEY_VALUE_SEPARATOR;
$value = base64_encode($value);
}
return $directive.$separator.' '.$this->getValueForLine($value).$this->lineEnding;
} | [
"protected",
"function",
"getLdifLine",
"(",
"$",
"directive",
",",
"$",
"value",
")",
"{",
"$",
"separator",
"=",
"Ldif",
"::",
"KEY_VALUE_SEPARATOR",
";",
"// Per the RFC, any value starting with a space should be base64 encoded",
"if",
"(",
"(",
"substr",
"(",
"$",... | Construct a single line of the LDIF for a given directive and value.
@param string $directive
@param string $value
@return string | [
"Construct",
"a",
"single",
"line",
"of",
"the",
"LDIF",
"for",
"a",
"given",
"directive",
"and",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/LdifStringBuilderTrait.php#L161-L172 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/LdifStringBuilderTrait.php | LdifStringBuilderTrait.getValueForLine | protected function getValueForLine($value)
{
/**
* Is this the correct way to do line folding? If a folded line starts/ends with a space should the value,
* and this every line, be base64 encoded? Reading the RFC this does not seem clear.
*/
if ($this->lineFolding) {
$value = implode(
$this->lineEnding." ",
str_split($value, $this->maxLineLength)
);
}
return $value;
} | php | protected function getValueForLine($value)
{
/**
* Is this the correct way to do line folding? If a folded line starts/ends with a space should the value,
* and this every line, be base64 encoded? Reading the RFC this does not seem clear.
*/
if ($this->lineFolding) {
$value = implode(
$this->lineEnding." ",
str_split($value, $this->maxLineLength)
);
}
return $value;
} | [
"protected",
"function",
"getValueForLine",
"(",
"$",
"value",
")",
"{",
"/**\n * Is this the correct way to do line folding? If a folded line starts/ends with a space should the value,\n * and this every line, be base64 encoded? Reading the RFC this does not seem clear.\n */... | Gets the value for the line while taking into account any line folding set.
@param $value
@return string | [
"Gets",
"the",
"value",
"for",
"the",
"line",
"while",
"taking",
"into",
"account",
"any",
"line",
"folding",
"set",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/LdifStringBuilderTrait.php#L180-L194 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/MBString.php | MBString.ord | public static function ord($string)
{
if (self::isMbstringLoaded()) {
$result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));
if (is_array($result) === true) {
return $result[1];
}
}
return ord($string);
} | php | public static function ord($string)
{
if (self::isMbstringLoaded()) {
$result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));
if (is_array($result) === true) {
return $result[1];
}
}
return ord($string);
} | [
"public",
"static",
"function",
"ord",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"self",
"::",
"isMbstringLoaded",
"(",
")",
")",
"{",
"$",
"result",
"=",
"unpack",
"(",
"'N'",
",",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"'UCS-4BE'",
",",
"'UTF... | Get the integer value of a specific character.
@param $string
@return int | [
"Get",
"the",
"integer",
"value",
"of",
"a",
"specific",
"character",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/MBString.php#L42-L52 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/MBString.php | MBString.compare | public static function compare($value1, $value2)
{
if (self::isIntlLoaded()) {
return self::getCollator()->compare($value1, $value2);
}
return strnatcmp($value1, $value2);
} | php | public static function compare($value1, $value2)
{
if (self::isIntlLoaded()) {
return self::getCollator()->compare($value1, $value2);
}
return strnatcmp($value1, $value2);
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"if",
"(",
"self",
"::",
"isIntlLoaded",
"(",
")",
")",
"{",
"return",
"self",
"::",
"getCollator",
"(",
")",
"->",
"compare",
"(",
"$",
"value1",
",",
"$",
... | Performs a comparison between two values and returns an integer result, like strnatcmp.
@param string $value1
@param string $value2
@return int | [
"Performs",
"a",
"comparison",
"between",
"two",
"values",
"and",
"returns",
"an",
"integer",
"result",
"like",
"strnatcmp",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/MBString.php#L87-L94 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/MBString.php | MBString.array_change_value_case | public static function array_change_value_case(array $values)
{
$newValues = [];
foreach ($values as $key => $value) {
$newValues[$key] = self::strtolower($value);
}
return $newValues;
} | php | public static function array_change_value_case(array $values)
{
$newValues = [];
foreach ($values as $key => $value) {
$newValues[$key] = self::strtolower($value);
}
return $newValues;
} | [
"public",
"static",
"function",
"array_change_value_case",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"newValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"newValues",
"[",
"$",
"key",
... | Change the values in an array to lower-case values.
@param array $values
@return array | [
"Change",
"the",
"values",
"in",
"an",
"array",
"to",
"lower",
"-",
"case",
"values",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/MBString.php#L117-L126 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.setOwner | public function setOwner($owner)
{
$this->owner = $owner instanceof SID ? $owner : new SID($owner);
return $this;
} | php | public function setOwner($owner)
{
$this->owner = $owner instanceof SID ? $owner : new SID($owner);
return $this;
} | [
"public",
"function",
"setOwner",
"(",
"$",
"owner",
")",
"{",
"$",
"this",
"->",
"owner",
"=",
"$",
"owner",
"instanceof",
"SID",
"?",
"$",
"owner",
":",
"new",
"SID",
"(",
"$",
"owner",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the owner SID for the security descriptor.
@param SID|string $owner
@return $this | [
"Set",
"the",
"owner",
"SID",
"for",
"the",
"security",
"descriptor",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L133-L138 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.setGroup | public function setGroup($group)
{
$this->group = $group instanceof SID ? $group : new SID($group);
return $this;
} | php | public function setGroup($group)
{
$this->group = $group instanceof SID ? $group : new SID($group);
return $this;
} | [
"public",
"function",
"setGroup",
"(",
"$",
"group",
")",
"{",
"$",
"this",
"->",
"group",
"=",
"$",
"group",
"instanceof",
"SID",
"?",
"$",
"group",
":",
"new",
"SID",
"(",
"$",
"group",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the group SID for the security descriptor.
@param SID|string $group
@return $this | [
"Set",
"the",
"group",
"SID",
"for",
"the",
"security",
"descriptor",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L156-L161 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.setDacl | public function setDacl(Dacl $dacl = null)
{
$this->dacl = $dacl;
return $this->toggleAclPresent((bool) $dacl, Dacl::SDDL_CHAR);
} | php | public function setDacl(Dacl $dacl = null)
{
$this->dacl = $dacl;
return $this->toggleAclPresent((bool) $dacl, Dacl::SDDL_CHAR);
} | [
"public",
"function",
"setDacl",
"(",
"Dacl",
"$",
"dacl",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"dacl",
"=",
"$",
"dacl",
";",
"return",
"$",
"this",
"->",
"toggleAclPresent",
"(",
"(",
"bool",
")",
"$",
"dacl",
",",
"Dacl",
"::",
"SDDL_CHAR",
... | Set the Discretionary ACL.
@param Dacl $dacl
@return $this | [
"Set",
"the",
"Discretionary",
"ACL",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L189-L194 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.setSacl | public function setSacl(Sacl $sacl = null)
{
$this->sacl = $sacl;
return $this->toggleAclPresent((bool) $sacl, Sacl::SDDL_CHAR);
} | php | public function setSacl(Sacl $sacl = null)
{
$this->sacl = $sacl;
return $this->toggleAclPresent((bool) $sacl, Sacl::SDDL_CHAR);
} | [
"public",
"function",
"setSacl",
"(",
"Sacl",
"$",
"sacl",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"sacl",
"=",
"$",
"sacl",
";",
"return",
"$",
"this",
"->",
"toggleAclPresent",
"(",
"(",
"bool",
")",
"$",
"sacl",
",",
"Sacl",
"::",
"SDDL_CHAR",
... | Set the System ACL.
@param Sacl $sacl
@return $this | [
"Set",
"the",
"System",
"ACL",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L212-L217 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.toBinary | public function toBinary($canonicalize = true)
{
$offsetOwner = 0;
$offsetGroup = 0;
$offsetDacl = 0;
$offsetSacl = 0;
$owner = $this->owner ? $this->owner->toBinary() : null;
$group = $this->group ? $this->group->toBinary() : null;
$dacl = $this->dacl ? $this->dacl->toBinary($canonicalize) : null;
$sacl = $this->sacl ? $this->sacl->toBinary() : null;
/**
* According the the MS docs, the order of the elements is not important. And indeed, I have found no rhyme or
* reason as to how the owner/group/sacl/dacl elements are ordered in the security descriptor. As long as they
* point to the correct offset where the element is located then it will work. But the order seems unpredictable
* as far as coming from AD/Exchange/etc.
*/
$offset = 40;
if ($owner) {
$offsetOwner = $offset;
$offset += strlen(bin2hex($owner));
}
if ($group) {
$offsetGroup = $offset;
$offset += strlen(bin2hex($group));
}
if ($sacl) {
$offsetSacl = $offset;
$offset += strlen(bin2hex($sacl));
}
if ($dacl) {
$offsetDacl = $offset;
}
return pack(
'C1C1v1V1V1V1V1',
$this->revision,
$this->rmControlFlags->getValue(),
$this->controlFlags->getValue(),
($offsetOwner / 2),
($offsetGroup / 2),
($offsetSacl / 2),
($offsetDacl / 2)
).$owner.$group.$sacl.$dacl;
} | php | public function toBinary($canonicalize = true)
{
$offsetOwner = 0;
$offsetGroup = 0;
$offsetDacl = 0;
$offsetSacl = 0;
$owner = $this->owner ? $this->owner->toBinary() : null;
$group = $this->group ? $this->group->toBinary() : null;
$dacl = $this->dacl ? $this->dacl->toBinary($canonicalize) : null;
$sacl = $this->sacl ? $this->sacl->toBinary() : null;
/**
* According the the MS docs, the order of the elements is not important. And indeed, I have found no rhyme or
* reason as to how the owner/group/sacl/dacl elements are ordered in the security descriptor. As long as they
* point to the correct offset where the element is located then it will work. But the order seems unpredictable
* as far as coming from AD/Exchange/etc.
*/
$offset = 40;
if ($owner) {
$offsetOwner = $offset;
$offset += strlen(bin2hex($owner));
}
if ($group) {
$offsetGroup = $offset;
$offset += strlen(bin2hex($group));
}
if ($sacl) {
$offsetSacl = $offset;
$offset += strlen(bin2hex($sacl));
}
if ($dacl) {
$offsetDacl = $offset;
}
return pack(
'C1C1v1V1V1V1V1',
$this->revision,
$this->rmControlFlags->getValue(),
$this->controlFlags->getValue(),
($offsetOwner / 2),
($offsetGroup / 2),
($offsetSacl / 2),
($offsetDacl / 2)
).$owner.$group.$sacl.$dacl;
} | [
"public",
"function",
"toBinary",
"(",
"$",
"canonicalize",
"=",
"true",
")",
"{",
"$",
"offsetOwner",
"=",
"0",
";",
"$",
"offsetGroup",
"=",
"0",
";",
"$",
"offsetDacl",
"=",
"0",
";",
"$",
"offsetSacl",
"=",
"0",
";",
"$",
"owner",
"=",
"$",
"th... | Get the binary string form of the security descriptor.
@param bool $canonicalize Whether or not to canonicalize the DACL
@return string | [
"Get",
"the",
"binary",
"string",
"form",
"of",
"the",
"security",
"descriptor",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L225-L269 | train |
ldaptools/ldaptools | src/LdapTools/Security/SecurityDescriptor.php | SecurityDescriptor.toSddl | public function toSddl($canonicalize = true)
{
// These will always be present in the SDDL...
$sddl = 'O:'.($this->owner->getShortName() ?: $this->owner).'G:'.($this->group->getShortName() ?: $this->group);
foreach ([$this->dacl, $this->sacl] as $acl) {
// It should be omitted if empty or not set...
if ($acl && count($acl->getAces()) > 0) {
$sddl .= $acl->getSddlIdentifier().':'.$this->getAclSddlFlags($acl);
$sddl .= $acl instanceof Dacl ? $acl->toSddl($canonicalize) : $acl->toSddl();
}
}
return $sddl;
} | php | public function toSddl($canonicalize = true)
{
// These will always be present in the SDDL...
$sddl = 'O:'.($this->owner->getShortName() ?: $this->owner).'G:'.($this->group->getShortName() ?: $this->group);
foreach ([$this->dacl, $this->sacl] as $acl) {
// It should be omitted if empty or not set...
if ($acl && count($acl->getAces()) > 0) {
$sddl .= $acl->getSddlIdentifier().':'.$this->getAclSddlFlags($acl);
$sddl .= $acl instanceof Dacl ? $acl->toSddl($canonicalize) : $acl->toSddl();
}
}
return $sddl;
} | [
"public",
"function",
"toSddl",
"(",
"$",
"canonicalize",
"=",
"true",
")",
"{",
"// These will always be present in the SDDL...",
"$",
"sddl",
"=",
"'O:'",
".",
"(",
"$",
"this",
"->",
"owner",
"->",
"getShortName",
"(",
")",
"?",
":",
"$",
"this",
"->",
... | Get the SDDL string format that represents this Security Descriptor and everything it contains.
@param bool $canonicalize Whether or not to canonicalize the DACL
@return string | [
"Get",
"the",
"SDDL",
"string",
"format",
"that",
"represents",
"this",
"Security",
"Descriptor",
"and",
"everything",
"it",
"contains",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SecurityDescriptor.php#L277-L291 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertGroupMembership.php | ConvertGroupMembership.createOperationsFromValues | protected function createOperationsFromValues(array $values)
{
// In the case of a 'set' or 'reset' operation all current group membership should be removed.
if ($this->shouldRemoveCurrentGroups()) {
$this->removeCurrentGroups();
}
// Only if this is not a reset operation, otherwise there is nothing left to do.
if (!($this->getOperationType() == AttributeConverterInterface::TYPE_MODIFY && $this->getBatch()->isTypeRemoveAll())) {
$batchType = $this->getBatchTypeForOperation();
foreach ($values as $value) {
$this->addOperation(parent::toLdap($value), $batchType);
}
}
} | php | protected function createOperationsFromValues(array $values)
{
// In the case of a 'set' or 'reset' operation all current group membership should be removed.
if ($this->shouldRemoveCurrentGroups()) {
$this->removeCurrentGroups();
}
// Only if this is not a reset operation, otherwise there is nothing left to do.
if (!($this->getOperationType() == AttributeConverterInterface::TYPE_MODIFY && $this->getBatch()->isTypeRemoveAll())) {
$batchType = $this->getBatchTypeForOperation();
foreach ($values as $value) {
$this->addOperation(parent::toLdap($value), $batchType);
}
}
} | [
"protected",
"function",
"createOperationsFromValues",
"(",
"array",
"$",
"values",
")",
"{",
"// In the case of a 'set' or 'reset' operation all current group membership should be removed.",
"if",
"(",
"$",
"this",
"->",
"shouldRemoveCurrentGroups",
"(",
")",
")",
"{",
"$",
... | Given the set of array values create the correct operation.
@param array $values
@throws \LdapTools\Exception\AttributeConverterException | [
"Given",
"the",
"set",
"of",
"array",
"values",
"create",
"the",
"correct",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertGroupMembership.php#L78-L91 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertGroupMembership.php | ConvertGroupMembership.addOperation | protected function addOperation($dn, $batchType)
{
$collection = new BatchCollection($dn);
$valueDn = $this->getDn();
// The DN is unknown in the case of an add, as value/parameter resolution most occur first. If there is a better
// way to do this I'm not sure what it would be. The batch will resolve closures when producing an array to ldap.
if ($this->getOperationType() == AttributeConverterInterface::TYPE_CREATE) {
/** @var AddOperation $parentOp */
$parentOp = $this->getOperation();
$valueDn = function () use ($parentOp) {
return $parentOp->getDn();
};
}
$collection->add(new Batch($batchType, $this->options['to_attribute'], $valueDn));
$operation = new BatchModifyOperation($dn, $collection);
$this->operation->addPostOperation($operation);
} | php | protected function addOperation($dn, $batchType)
{
$collection = new BatchCollection($dn);
$valueDn = $this->getDn();
// The DN is unknown in the case of an add, as value/parameter resolution most occur first. If there is a better
// way to do this I'm not sure what it would be. The batch will resolve closures when producing an array to ldap.
if ($this->getOperationType() == AttributeConverterInterface::TYPE_CREATE) {
/** @var AddOperation $parentOp */
$parentOp = $this->getOperation();
$valueDn = function () use ($parentOp) {
return $parentOp->getDn();
};
}
$collection->add(new Batch($batchType, $this->options['to_attribute'], $valueDn));
$operation = new BatchModifyOperation($dn, $collection);
$this->operation->addPostOperation($operation);
} | [
"protected",
"function",
"addOperation",
"(",
"$",
"dn",
",",
"$",
"batchType",
")",
"{",
"$",
"collection",
"=",
"new",
"BatchCollection",
"(",
"$",
"dn",
")",
";",
"$",
"valueDn",
"=",
"$",
"this",
"->",
"getDn",
"(",
")",
";",
"// The DN is unknown in... | Add the correct operation for the action as a post operation to the current operation.
@param string $dn
@param int $batchType
@throws \LdapTools\Exception\AttributeConverterException | [
"Add",
"the",
"correct",
"operation",
"for",
"the",
"action",
"as",
"a",
"post",
"operation",
"to",
"the",
"current",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertGroupMembership.php#L100-L118 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertGroupMembership.php | ConvertGroupMembership.removeCurrentGroups | protected function removeCurrentGroups()
{
$valuesToRemove = $this->getCurrentLdapAttributeValue($this->options['from_attribute']);
$valuesToRemove = is_null($valuesToRemove) ? [] : $valuesToRemove;
$valuesToRemove = is_array($valuesToRemove) ? $valuesToRemove : [$valuesToRemove];
foreach ($valuesToRemove as $value) {
$this->addOperation(parent::toLdap($value), Batch::TYPE['REMOVE']);
} | php | protected function removeCurrentGroups()
{
$valuesToRemove = $this->getCurrentLdapAttributeValue($this->options['from_attribute']);
$valuesToRemove = is_null($valuesToRemove) ? [] : $valuesToRemove;
$valuesToRemove = is_array($valuesToRemove) ? $valuesToRemove : [$valuesToRemove];
foreach ($valuesToRemove as $value) {
$this->addOperation(parent::toLdap($value), Batch::TYPE['REMOVE']);
} | [
"protected",
"function",
"removeCurrentGroups",
"(",
")",
"{",
"$",
"valuesToRemove",
"=",
"$",
"this",
"->",
"getCurrentLdapAttributeValue",
"(",
"$",
"this",
"->",
"options",
"[",
"'from_attribute'",
"]",
")",
";",
"$",
"valuesToRemove",
"=",
"is_null",
"(",
... | Gets the current group membership and generates operations to remove them all.
@throws \LdapTools\Exception\AttributeConverterException | [
"Gets",
"the",
"current",
"group",
"membership",
"and",
"generates",
"operations",
"to",
"remove",
"them",
"all",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertGroupMembership.php#L134-L142 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.resolve | public function resolve()
{
if (!empty($this->resolvedParameters)) {
return $this->attributes;
}
$this->evaluateRequirements($this->attributes);
$this->resolveAllParameters();
return $this->attributes;
} | php | public function resolve()
{
if (!empty($this->resolvedParameters)) {
return $this->attributes;
}
$this->evaluateRequirements($this->attributes);
$this->resolveAllParameters();
return $this->attributes;
} | [
"public",
"function",
"resolve",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"resolvedParameters",
")",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
";",
"}",
"$",
"this",
"->",
"evaluateRequirements",
"(",
"$",
"this",
"->"... | Gets the attributes with all of the parameters resolved.
@return array | [
"Gets",
"the",
"attributes",
"with",
"all",
"of",
"the",
"parameters",
"resolved",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L63-L72 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.resolveAllParameters | protected function resolveAllParameters()
{
foreach ($this->requirements as $attribute => $parameters) {
// This parameter may have already been resolved as part of a dependency
if (!in_array($attribute, $this->resolvedParameters)) {
$this->resolveParametersForAttribute($attribute, $parameters);
}
}
} | php | protected function resolveAllParameters()
{
foreach ($this->requirements as $attribute => $parameters) {
// This parameter may have already been resolved as part of a dependency
if (!in_array($attribute, $this->resolvedParameters)) {
$this->resolveParametersForAttribute($attribute, $parameters);
}
}
} | [
"protected",
"function",
"resolveAllParameters",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"requirements",
"as",
"$",
"attribute",
"=>",
"$",
"parameters",
")",
"{",
"// This parameter may have already been resolved as part of a dependency",
"if",
"(",
"!",
"i... | Iterates over each requirement to resolve the parameters it contains. | [
"Iterates",
"over",
"each",
"requirement",
"to",
"resolve",
"the",
"parameters",
"it",
"contains",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L88-L96 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.resolveParametersForAttribute | protected function resolveParametersForAttribute($attribute, array $parameters)
{
$children = $this->getDependentAttributes($parameters);
if (!empty($children)) {
foreach ($children as $child) {
$this->resolveParametersForAttribute($child, $this->requirements[$child]);
}
}
$this->doResolveParametersForAttribute($attribute, $parameters);
$remainingParameters = self::getParametersInValue($this->attributes[$attribute]);
// A second pass may be required for attributes it depended on that contained parameters not based on attributes
if (!empty($remainingParameters)) {
$this->doResolveParametersForAttribute($attribute, $remainingParameters);
}
$this->resolvedParameters[] = $attribute;
} | php | protected function resolveParametersForAttribute($attribute, array $parameters)
{
$children = $this->getDependentAttributes($parameters);
if (!empty($children)) {
foreach ($children as $child) {
$this->resolveParametersForAttribute($child, $this->requirements[$child]);
}
}
$this->doResolveParametersForAttribute($attribute, $parameters);
$remainingParameters = self::getParametersInValue($this->attributes[$attribute]);
// A second pass may be required for attributes it depended on that contained parameters not based on attributes
if (!empty($remainingParameters)) {
$this->doResolveParametersForAttribute($attribute, $remainingParameters);
}
$this->resolvedParameters[] = $attribute;
} | [
"protected",
"function",
"resolveParametersForAttribute",
"(",
"$",
"attribute",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"getDependentAttributes",
"(",
"$",
"parameters",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$"... | Given a specific attribute with parameters, this will resolve it while first resolving any dependent attributes
that first need to be resolved.
@param $attribute
@param array $parameters | [
"Given",
"a",
"specific",
"attribute",
"with",
"parameters",
"this",
"will",
"resolve",
"it",
"while",
"first",
"resolving",
"any",
"dependent",
"attributes",
"that",
"first",
"need",
"to",
"be",
"resolved",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L105-L124 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.doResolveParametersForAttribute | protected function doResolveParametersForAttribute($attribute, $parameters)
{
$this->attributes[$attribute] = $this->getValueForParameters(
$parameters,
$this->attributes[$attribute],
$this->attributes
);
} | php | protected function doResolveParametersForAttribute($attribute, $parameters)
{
$this->attributes[$attribute] = $this->getValueForParameters(
$parameters,
$this->attributes[$attribute],
$this->attributes
);
} | [
"protected",
"function",
"doResolveParametersForAttribute",
"(",
"$",
"attribute",
",",
"$",
"parameters",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
"=",
"$",
"this",
"->",
"getValueForParameters",
"(",
"$",
"parameters",
",",
"$",... | Sets the value for an attribute with the specified parameters.
@param string $attribute
@param array $parameters | [
"Sets",
"the",
"value",
"for",
"an",
"attribute",
"with",
"the",
"specified",
"parameters",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L132-L139 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.getDependentAttributes | protected function getDependentAttributes($parameters)
{
$dependencies = [];
foreach ($parameters as $parameter) {
if (isset($this->requirements[$parameter]) && !in_array($parameter, $this->resolvedParameters)) {
$dependencies[] = $parameter;
}
}
return $dependencies;
} | php | protected function getDependentAttributes($parameters)
{
$dependencies = [];
foreach ($parameters as $parameter) {
if (isset($this->requirements[$parameter]) && !in_array($parameter, $this->resolvedParameters)) {
$dependencies[] = $parameter;
}
}
return $dependencies;
} | [
"protected",
"function",
"getDependentAttributes",
"(",
"$",
"parameters",
")",
"{",
"$",
"dependencies",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requirements",
... | Checks for required parameter attributes that depend on other parameter attributes. Returns an array of
of dependencies.
@param array $parameters
@return array | [
"Checks",
"for",
"required",
"parameter",
"attributes",
"that",
"depend",
"on",
"other",
"parameter",
"attributes",
".",
"Returns",
"an",
"array",
"of",
"of",
"dependencies",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L148-L159 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.setRequirementsForAttribute | protected function setRequirementsForAttribute($attribute, array $value)
{
$parameters = [];
foreach ($value as $attrValue) {
$parameters = array_filter(array_merge(
$parameters,
self::getParametersInValue($attrValue)
));
}
if (!empty($parameters)) {
$this->requirements[$attribute] = $parameters;
}
} | php | protected function setRequirementsForAttribute($attribute, array $value)
{
$parameters = [];
foreach ($value as $attrValue) {
$parameters = array_filter(array_merge(
$parameters,
self::getParametersInValue($attrValue)
));
}
if (!empty($parameters)) {
$this->requirements[$attribute] = $parameters;
}
} | [
"protected",
"function",
"setRequirementsForAttribute",
"(",
"$",
"attribute",
",",
"array",
"$",
"value",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"attrValue",
")",
"{",
"$",
"parameters",
"=",
"array_filte... | Given an attribute, set what parameters it requires.
@param string $attribute
@param array $value | [
"Given",
"an",
"attribute",
"set",
"what",
"parameters",
"it",
"requires",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L185-L199 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.getParametersInValue | protected static function getParametersInValue($value)
{
$parameters = [];
$regex = '/'.self::PARAM_MARKER.'(.*?)'.self::PARAM_MARKER.'/';
$value = is_array($value) ? $value : [$value];
foreach ($value as $attrValue) {
if (is_string($attrValue) && preg_match_all($regex, $attrValue, $matches) && isset($matches[1])) {
$parameters = array_merge($parameters, $matches[1]);
}
}
return $parameters;
} | php | protected static function getParametersInValue($value)
{
$parameters = [];
$regex = '/'.self::PARAM_MARKER.'(.*?)'.self::PARAM_MARKER.'/';
$value = is_array($value) ? $value : [$value];
foreach ($value as $attrValue) {
if (is_string($attrValue) && preg_match_all($regex, $attrValue, $matches) && isset($matches[1])) {
$parameters = array_merge($parameters, $matches[1]);
}
}
return $parameters;
} | [
"protected",
"static",
"function",
"getParametersInValue",
"(",
"$",
"value",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"regex",
"=",
"'/'",
".",
"self",
"::",
"PARAM_MARKER",
".",
"'(.*?)'",
".",
"self",
"::",
"PARAM_MARKER",
".",
"'/'",
";"... | Given an attribute value get all parameters it expects.
@param string|array $value
@return array | [
"Given",
"an",
"attribute",
"value",
"get",
"all",
"parameters",
"it",
"expects",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L207-L220 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/ParameterResolver.php | ParameterResolver.checkForCircularDependency | protected function checkForCircularDependency($parent, array $parentParameters)
{
foreach ($this->requirements as $attribute => $parameters) {
if (in_array($parent, $parameters) && in_array($attribute, $parentParameters)) {
throw new LogicException(sprintf(
'Circular parameter dependency detected. Parameters "%s" and "%s" depend on each other.',
$parent,
$attribute
));
}
}
} | php | protected function checkForCircularDependency($parent, array $parentParameters)
{
foreach ($this->requirements as $attribute => $parameters) {
if (in_array($parent, $parameters) && in_array($attribute, $parentParameters)) {
throw new LogicException(sprintf(
'Circular parameter dependency detected. Parameters "%s" and "%s" depend on each other.',
$parent,
$attribute
));
}
}
} | [
"protected",
"function",
"checkForCircularDependency",
"(",
"$",
"parent",
",",
"array",
"$",
"parentParameters",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"requirements",
"as",
"$",
"attribute",
"=>",
"$",
"parameters",
")",
"{",
"if",
"(",
"in_array",
"... | Given an attribute with parameter dependencies, check if any of them will become circular.
@param string $parent
@param array $parentParameters | [
"Given",
"an",
"attribute",
"with",
"parameter",
"dependencies",
"check",
"if",
"any",
"of",
"them",
"will",
"become",
"circular",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/ParameterResolver.php#L228-L239 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.getSingleResult | public function getSingleResult($hydratorType = HydratorFactory::TO_OBJECT)
{
$result = $this->execute($hydratorType);
$count = ($result instanceof LdapObjectCollection) ? $result->count() : count($result);
if ($count === 0) {
throw new EmptyResultException('LDAP returned no results.');
} elseif ($count > 1) {
throw new MultiResultException(sprintf('Expected a single result but LDAP returned %s result(s).', $count));
}
return ($result instanceof LdapObjectCollection) ? $result->first() : reset($result);
} | php | public function getSingleResult($hydratorType = HydratorFactory::TO_OBJECT)
{
$result = $this->execute($hydratorType);
$count = ($result instanceof LdapObjectCollection) ? $result->count() : count($result);
if ($count === 0) {
throw new EmptyResultException('LDAP returned no results.');
} elseif ($count > 1) {
throw new MultiResultException(sprintf('Expected a single result but LDAP returned %s result(s).', $count));
}
return ($result instanceof LdapObjectCollection) ? $result->first() : reset($result);
} | [
"public",
"function",
"getSingleResult",
"(",
"$",
"hydratorType",
"=",
"HydratorFactory",
"::",
"TO_OBJECT",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"hydratorType",
")",
";",
"$",
"count",
"=",
"(",
"$",
"result",
"instanceof... | Retrieve a single unique result from LDAP. If the result is empty or contains more than one entry, an exception
is thrown.
@param string $hydratorType A hyrdrator type constant from the factory.
@return array|\LdapTools\Object\LdapObject
@throws EmptyResultException
@throws MultiResultException | [
"Retrieve",
"a",
"single",
"unique",
"result",
"from",
"LDAP",
".",
"If",
"the",
"result",
"is",
"empty",
"or",
"contains",
"more",
"than",
"one",
"entry",
"an",
"exception",
"is",
"thrown",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L162-L174 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.getSingleScalarResult | public function getSingleScalarResult()
{
if (count($this->operation->getAttributes()) !== 1 || $this->isWildCardSelection()) {
$selected = $this->isWildCardSelection() ? 'All' : count($this->operation->getAttributes());
throw new LdapQueryException(sprintf(
'When retrieving a single value you should only select a single attribute. %s are selected.',
$selected
));
}
$attribute = $this->operation->getAttributes();
$attribute = reset($attribute);
$result = $this->getSingleResult();
if (!$result->has($attribute)) {
throw new AttributeNotFoundException(sprintf('Attribute "%s" not found for this LDAP object.', $attribute));
}
return $result->get($attribute);
} | php | public function getSingleScalarResult()
{
if (count($this->operation->getAttributes()) !== 1 || $this->isWildCardSelection()) {
$selected = $this->isWildCardSelection() ? 'All' : count($this->operation->getAttributes());
throw new LdapQueryException(sprintf(
'When retrieving a single value you should only select a single attribute. %s are selected.',
$selected
));
}
$attribute = $this->operation->getAttributes();
$attribute = reset($attribute);
$result = $this->getSingleResult();
if (!$result->has($attribute)) {
throw new AttributeNotFoundException(sprintf('Attribute "%s" not found for this LDAP object.', $attribute));
}
return $result->get($attribute);
} | [
"public",
"function",
"getSingleScalarResult",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"operation",
"->",
"getAttributes",
"(",
")",
")",
"!==",
"1",
"||",
"$",
"this",
"->",
"isWildCardSelection",
"(",
")",
")",
"{",
"$",
"selected",
... | Retrieve a single selected attribute value from LDAP.
@return mixed
@throws LdapQueryException
@throws AttributeNotFoundException
@throws EmptyResultException
@throws MultiResultException | [
"Retrieve",
"a",
"single",
"selected",
"attribute",
"value",
"from",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L185-L203 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.execute | public function execute($hydratorType = HydratorFactory::TO_OBJECT)
{
if (is_string($this->operation->getFilter()) || empty($this->operation->getFilter()->getAliases())) {
$results = $this->getResultsFromLdap(clone $this->operation, $hydratorType);
} else {
$results = $this->getResultsForAliases($hydratorType);
}
return $this->sortResults($results);
} | php | public function execute($hydratorType = HydratorFactory::TO_OBJECT)
{
if (is_string($this->operation->getFilter()) || empty($this->operation->getFilter()->getAliases())) {
$results = $this->getResultsFromLdap(clone $this->operation, $hydratorType);
} else {
$results = $this->getResultsForAliases($hydratorType);
}
return $this->sortResults($results);
} | [
"public",
"function",
"execute",
"(",
"$",
"hydratorType",
"=",
"HydratorFactory",
"::",
"TO_OBJECT",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"operation",
"->",
"getFilter",
"(",
")",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"operati... | Execute a query based on the set parameters. Optionally choose a mode to hydrate the results in.
@param string $hydratorType A hyrdrator type constant from the factory.
@return mixed|\LdapTools\Object\LdapObject|\LdapTools\Object\LdapObjectCollection | [
"Execute",
"a",
"query",
"based",
"on",
"the",
"set",
"parameters",
".",
"Optionally",
"choose",
"a",
"mode",
"to",
"hydrate",
"the",
"results",
"in",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L251-L260 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.setOrderBy | public function setOrderBy(array $orderBy)
{
// Validate and force the case for the direction.
foreach ($orderBy as $attribute => $direction) {
if (!in_array(strtoupper($direction), self::ORDER)) {
throw new \InvalidArgumentException(sprintf(
'Order direction "%s" is invalid. Valid values are ASC and DESC',
$direction
));
}
$orderBy[$attribute] = strtoupper($direction);
}
$this->orderBy = $orderBy;
return $this;
} | php | public function setOrderBy(array $orderBy)
{
// Validate and force the case for the direction.
foreach ($orderBy as $attribute => $direction) {
if (!in_array(strtoupper($direction), self::ORDER)) {
throw new \InvalidArgumentException(sprintf(
'Order direction "%s" is invalid. Valid values are ASC and DESC',
$direction
));
}
$orderBy[$attribute] = strtoupper($direction);
}
$this->orderBy = $orderBy;
return $this;
} | [
"public",
"function",
"setOrderBy",
"(",
"array",
"$",
"orderBy",
")",
"{",
"// Validate and force the case for the direction.",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"attribute",
"=>",
"$",
"direction",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strtouppe... | Set the attributes to order the results by.
@param array $orderBy In the form of ['attribute' => 'ASC', ...]
@return $this | [
"Set",
"the",
"attributes",
"to",
"order",
"the",
"results",
"by",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L291-L306 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.getResultsForAliases | protected function getResultsForAliases($hydratorType)
{
/** @var LdapObjectCollection|array $results */
$results = [];
foreach ($this->operation->getFilter()->getAliases() as $alias => $schema) {
$operation = clone $this->operation;
/**
* If we received the partial limit of results, re-adjust the next operations limit so we don't go over.
*
* @todo This is getting difficult due to multiple operations needed to select all schema types. If this was
* a single operation the issue would not exist. But with a single query and multiple types I cannot
* easily determine which result is what type. Unsure of the best way to fix this at the moment.
*/
if ($operation->getSizeLimit() && count($results) < $operation->getSizeLimit()) {
$operation->setSizeLimit($operation->getSizeLimit() - count($results));
}
$objects = $this->getResultsFromLdap($operation, $hydratorType, $schema, $alias);
if ($objects instanceof LdapObjectCollection && $results) {
$results->add(...$objects->toArray());
} elseif ($objects instanceof LdapObjectCollection) {
$results = $objects;
} else {
$results = array_merge($results, $objects);
}
// If the results have reached the expected size limit then end the loop.
if ($this->operation->getSizeLimit() && count($results) == $operation->getSizeLimit()) {
break;
}
}
return $results;
} | php | protected function getResultsForAliases($hydratorType)
{
/** @var LdapObjectCollection|array $results */
$results = [];
foreach ($this->operation->getFilter()->getAliases() as $alias => $schema) {
$operation = clone $this->operation;
/**
* If we received the partial limit of results, re-adjust the next operations limit so we don't go over.
*
* @todo This is getting difficult due to multiple operations needed to select all schema types. If this was
* a single operation the issue would not exist. But with a single query and multiple types I cannot
* easily determine which result is what type. Unsure of the best way to fix this at the moment.
*/
if ($operation->getSizeLimit() && count($results) < $operation->getSizeLimit()) {
$operation->setSizeLimit($operation->getSizeLimit() - count($results));
}
$objects = $this->getResultsFromLdap($operation, $hydratorType, $schema, $alias);
if ($objects instanceof LdapObjectCollection && $results) {
$results->add(...$objects->toArray());
} elseif ($objects instanceof LdapObjectCollection) {
$results = $objects;
} else {
$results = array_merge($results, $objects);
}
// If the results have reached the expected size limit then end the loop.
if ($this->operation->getSizeLimit() && count($results) == $operation->getSizeLimit()) {
break;
}
}
return $results;
} | [
"protected",
"function",
"getResultsForAliases",
"(",
"$",
"hydratorType",
")",
"{",
"/** @var LdapObjectCollection|array $results */",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"operation",
"->",
"getFilter",
"(",
")",
"->",
"getAlias... | Goes through each alias for the operation to get results only for that specific type, then combine and return
them all.
@param string $hydratorType
@return array|LdapObjectCollection|mixed | [
"Goes",
"through",
"each",
"alias",
"for",
"the",
"operation",
"to",
"get",
"results",
"only",
"for",
"that",
"specific",
"type",
"then",
"combine",
"and",
"return",
"them",
"all",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L393-L428 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.getSelectedForAllAliases | protected function getSelectedForAllAliases(array $aliases)
{
if (empty($aliases)) {
$selected = $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes()));
} else {
// If there are aliases, then we need to loop through each one to determine was was actually selected for each.
$selected = [];
foreach ($aliases as $alias => $schema) {
$selected = array_replace(
$selected,
$this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes(), $schema), $alias)
);
}
}
return $selected;
} | php | protected function getSelectedForAllAliases(array $aliases)
{
if (empty($aliases)) {
$selected = $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes()));
} else {
// If there are aliases, then we need to loop through each one to determine was was actually selected for each.
$selected = [];
foreach ($aliases as $alias => $schema) {
$selected = array_replace(
$selected,
$this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes(), $schema), $alias)
);
}
}
return $selected;
} | [
"protected",
"function",
"getSelectedForAllAliases",
"(",
"array",
"$",
"aliases",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"selected",
"=",
"$",
"this",
"->",
"mergeOrderByAttributes",
"(",
"$",
"this",
"->",
"getSelectedQueryA... | Get all the attributes that were selected for the query taking into account all of the aliases used.
@param array $aliases
@return array | [
"Get",
"all",
"the",
"attributes",
"that",
"were",
"selected",
"for",
"the",
"query",
"taking",
"into",
"account",
"all",
"of",
"the",
"aliases",
"used",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L436-L452 | train |
ldaptools/ldaptools | src/LdapTools/Query/LdapQuery.php | LdapQuery.getFormattedOrderBy | protected function getFormattedOrderBy($selected, $aliases)
{
if (!empty($aliases) && !$this->isWildCardSelection()) {
$orderBy = [];
foreach ($this->orderBy as $attribute => $direction) {
list($alias, $attr) = LdapUtilities::getAliasAndAttribute($attribute);
$orderAttr = AttributeNameResolver::arraySearchGetValue($attr, $selected);
$orderAttr = $alias ? "$alias.$orderAttr" : $orderAttr;
$orderBy[$orderAttr] = $direction;
}
} else {
$orderBy = $this->orderBy;
}
return $orderBy;
} | php | protected function getFormattedOrderBy($selected, $aliases)
{
if (!empty($aliases) && !$this->isWildCardSelection()) {
$orderBy = [];
foreach ($this->orderBy as $attribute => $direction) {
list($alias, $attr) = LdapUtilities::getAliasAndAttribute($attribute);
$orderAttr = AttributeNameResolver::arraySearchGetValue($attr, $selected);
$orderAttr = $alias ? "$alias.$orderAttr" : $orderAttr;
$orderBy[$orderAttr] = $direction;
}
} else {
$orderBy = $this->orderBy;
}
return $orderBy;
} | [
"protected",
"function",
"getFormattedOrderBy",
"(",
"$",
"selected",
",",
"$",
"aliases",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aliases",
")",
"&&",
"!",
"$",
"this",
"->",
"isWildCardSelection",
"(",
")",
")",
"{",
"$",
"orderBy",
"=",
"[",
... | This formats the orderBy array to ignore case differences between the orderBy name and the actually selected name,
such as for sorting arrays.
@param $selected
@param $aliases
@return array | [
"This",
"formats",
"the",
"orderBy",
"array",
"to",
"ignore",
"case",
"differences",
"between",
"the",
"orderBy",
"name",
"and",
"the",
"actually",
"selected",
"name",
"such",
"as",
"for",
"sorting",
"arrays",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Query/LdapQuery.php#L462-L477 | train |
ldaptools/ldaptools | src/LdapTools/Factory/LdapObjectSchemaFactory.php | LdapObjectSchemaFactory.get | public function get($schemaName, $objectType)
{
$key = CacheItem::TYPE['SCHEMA_OBJECT'].'.'.$schemaName.'.'.$objectType;
if ($this->shouldBuildCacheItem($key, $schemaName)) {
$ldapObjectSchema = $this->parser->parse($schemaName, $objectType);
$this->dispatcher->dispatch(new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, $ldapObjectSchema));
$this->cache->set(new CacheItem($key, $ldapObjectSchema));
} else {
$ldapObjectSchema = $this->cache->get($key)->getValue();
}
return $ldapObjectSchema;
} | php | public function get($schemaName, $objectType)
{
$key = CacheItem::TYPE['SCHEMA_OBJECT'].'.'.$schemaName.'.'.$objectType;
if ($this->shouldBuildCacheItem($key, $schemaName)) {
$ldapObjectSchema = $this->parser->parse($schemaName, $objectType);
$this->dispatcher->dispatch(new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, $ldapObjectSchema));
$this->cache->set(new CacheItem($key, $ldapObjectSchema));
} else {
$ldapObjectSchema = $this->cache->get($key)->getValue();
}
return $ldapObjectSchema;
} | [
"public",
"function",
"get",
"(",
"$",
"schemaName",
",",
"$",
"objectType",
")",
"{",
"$",
"key",
"=",
"CacheItem",
"::",
"TYPE",
"[",
"'SCHEMA_OBJECT'",
"]",
".",
"'.'",
".",
"$",
"schemaName",
".",
"'.'",
".",
"$",
"objectType",
";",
"if",
"(",
"$... | Get the LdapObjectSchema for a specific schema name and object type.
@param string $schemaName
@param string $objectType
@return LdapObjectSchema | [
"Get",
"the",
"LdapObjectSchema",
"for",
"a",
"specific",
"schema",
"name",
"and",
"object",
"type",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Factory/LdapObjectSchemaFactory.php#L62-L75 | train |
ldaptools/ldaptools | src/LdapTools/Factory/LdapObjectSchemaFactory.php | LdapObjectSchemaFactory.shouldBuildCacheItem | protected function shouldBuildCacheItem($key, $schemaName)
{
$cacheOutOfDate = false;
if ($this->cache->getUseAutoCache()) {
$lastModTime = $this->parser->getSchemaModificationTime($schemaName);
$cacheCreationTime = $this->cache->getCacheCreationTime($key);
$cacheOutOfDate = (!$lastModTime || ($lastModTime > $cacheCreationTime));
}
return ($cacheOutOfDate || !$this->cache->contains($key));
} | php | protected function shouldBuildCacheItem($key, $schemaName)
{
$cacheOutOfDate = false;
if ($this->cache->getUseAutoCache()) {
$lastModTime = $this->parser->getSchemaModificationTime($schemaName);
$cacheCreationTime = $this->cache->getCacheCreationTime($key);
$cacheOutOfDate = (!$lastModTime || ($lastModTime > $cacheCreationTime));
}
return ($cacheOutOfDate || !$this->cache->contains($key));
} | [
"protected",
"function",
"shouldBuildCacheItem",
"(",
"$",
"key",
",",
"$",
"schemaName",
")",
"{",
"$",
"cacheOutOfDate",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"cache",
"->",
"getUseAutoCache",
"(",
")",
")",
"{",
"$",
"lastModTime",
"=",
"$"... | Whether or not the item needs to be parsed and cached.
@param string $key The cache key.
@param string $schemaName The schema name.
@return bool | [
"Whether",
"or",
"not",
"the",
"item",
"needs",
"to",
"be",
"parsed",
"and",
"cached",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Factory/LdapObjectSchemaFactory.php#L84-L94 | train |
ldaptools/ldaptools | src/LdapTools/Connection/LdapControl.php | LdapControl.toArray | public function toArray()
{
$control = [
'oid' => $this->resolveOid(),
'iscritical' => $this->criticality
];
if (!is_null($this->value)) {
$control['value'] = $this->value;
}
return $control;
} | php | public function toArray()
{
$control = [
'oid' => $this->resolveOid(),
'iscritical' => $this->criticality
];
if (!is_null($this->value)) {
$control['value'] = $this->value;
}
return $control;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"control",
"=",
"[",
"'oid'",
"=>",
"$",
"this",
"->",
"resolveOid",
"(",
")",
",",
"'iscritical'",
"=>",
"$",
"this",
"->",
"criticality",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
... | Get the control array structure that ldap_set_option expects.
@return array | [
"Get",
"the",
"control",
"array",
"structure",
"that",
"ldap_set_option",
"expects",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/LdapControl.php#L153-L164 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.setAttributeFromLdap | protected function setAttributeFromLdap(array $entry, $attribute, $value)
{
if (isset($value['count']) && $value['count'] == 1) {
$entry[$attribute] = $value[0];
} elseif (isset($value['count']) && $value['count'] > 0) {
$entry[$attribute] = [];
for ($i = 0; $i < $value['count']; $i++) {
$entry[$attribute][] = $value[$i];
}
} elseif ($attribute === 'dn') {
$entry[$attribute] = $value;
}
return $entry;
} | php | protected function setAttributeFromLdap(array $entry, $attribute, $value)
{
if (isset($value['count']) && $value['count'] == 1) {
$entry[$attribute] = $value[0];
} elseif (isset($value['count']) && $value['count'] > 0) {
$entry[$attribute] = [];
for ($i = 0; $i < $value['count']; $i++) {
$entry[$attribute][] = $value[$i];
}
} elseif ($attribute === 'dn') {
$entry[$attribute] = $value;
}
return $entry;
} | [
"protected",
"function",
"setAttributeFromLdap",
"(",
"array",
"$",
"entry",
",",
"$",
"attribute",
",",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'count'",
"]",
")",
"&&",
"$",
"value",
"[",
"'count'",
"]",
"==",
"1",
")",... | Given a specific attribute and value add it to the newly formed LDAP entry array.
@param array $entry
@param string $attribute
@param string|array $value
@return array | [
"Given",
"a",
"specific",
"attribute",
"and",
"value",
"add",
"it",
"to",
"the",
"newly",
"formed",
"LDAP",
"entry",
"array",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L204-L218 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.convertValuesFromLdap | protected function convertValuesFromLdap(array $entry)
{
if (!$this->schema) {
return $entry;
}
$valueResolver = BaseValueResolver::getInstance(
$this->schema,
$entry,
$this->type
);
$this->configureValueResolver($valueResolver, isset($entry['dn']) ? $entry['dn'] : null);
return $valueResolver->fromLdap();
} | php | protected function convertValuesFromLdap(array $entry)
{
if (!$this->schema) {
return $entry;
}
$valueResolver = BaseValueResolver::getInstance(
$this->schema,
$entry,
$this->type
);
$this->configureValueResolver($valueResolver, isset($entry['dn']) ? $entry['dn'] : null);
return $valueResolver->fromLdap();
} | [
"protected",
"function",
"convertValuesFromLdap",
"(",
"array",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"schema",
")",
"{",
"return",
"$",
"entry",
";",
"}",
"$",
"valueResolver",
"=",
"BaseValueResolver",
"::",
"getInstance",
"(",
"$",
... | Replace attribute values with the converted values if the attribute has a converter defined.
@param array $entry
@return array | [
"Replace",
"attribute",
"values",
"with",
"the",
"converted",
"values",
"if",
"the",
"attribute",
"has",
"a",
"converter",
"defined",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L237-L250 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.mergeDefaultAttributes | protected function mergeDefaultAttributes(array $attributes)
{
if ($this->schema && !empty($this->schema->getDefaultValues())) {
$attributes = array_merge($this->schema->getDefaultValues(), $attributes);
}
return $attributes;
} | php | protected function mergeDefaultAttributes(array $attributes)
{
if ($this->schema && !empty($this->schema->getDefaultValues())) {
$attributes = array_merge($this->schema->getDefaultValues(), $attributes);
}
return $attributes;
} | [
"protected",
"function",
"mergeDefaultAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"schema",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"schema",
"->",
"getDefaultValues",
"(",
")",
")",
")",
"{",
"$",
"attribute... | Returns all of the attributes to be sent to LDAP after factoring in possible default schema values.
@param array $attributes
@return array | [
"Returns",
"all",
"of",
"the",
"attributes",
"to",
"be",
"sent",
"to",
"LDAP",
"after",
"factoring",
"in",
"possible",
"default",
"schema",
"values",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L258-L265 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.validateAttributesToLdap | protected function validateAttributesToLdap(array $attributes)
{
if (!$this->schema) {
return;
}
$missing = [];
foreach ($this->schema->getRequiredAttributes() as $attribute) {
if (!array_key_exists(strtolower($attribute), array_change_key_case($attributes))) {
$missing[] = $attribute;
}
}
if (!empty($missing)) {
throw new LogicException(
sprintf('The following required attributes are missing: %s', implode(', ', $missing))
);
}
} | php | protected function validateAttributesToLdap(array $attributes)
{
if (!$this->schema) {
return;
}
$missing = [];
foreach ($this->schema->getRequiredAttributes() as $attribute) {
if (!array_key_exists(strtolower($attribute), array_change_key_case($attributes))) {
$missing[] = $attribute;
}
}
if (!empty($missing)) {
throw new LogicException(
sprintf('The following required attributes are missing: %s', implode(', ', $missing))
);
}
} | [
"protected",
"function",
"validateAttributesToLdap",
"(",
"array",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"schema",
")",
"{",
"return",
";",
"}",
"$",
"missing",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
... | Checks to make sure all required attributes are present.
@param array $attributes | [
"Checks",
"to",
"make",
"sure",
"all",
"required",
"attributes",
"are",
"present",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L273-L291 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.convertValuesToLdap | protected function convertValuesToLdap($values, $dn = null)
{
if (!($values instanceof OperatorCollection) && !$this->schema) {
return $values;
}
$valueResolver = BaseValueResolver::getInstance(
$this->schema,
$values,
$this->type
);
$this->configureValueResolver($valueResolver, $dn);
return $valueResolver->toLdap();
} | php | protected function convertValuesToLdap($values, $dn = null)
{
if (!($values instanceof OperatorCollection) && !$this->schema) {
return $values;
}
$valueResolver = BaseValueResolver::getInstance(
$this->schema,
$values,
$this->type
);
$this->configureValueResolver($valueResolver, $dn);
return $valueResolver->toLdap();
} | [
"protected",
"function",
"convertValuesToLdap",
"(",
"$",
"values",
",",
"$",
"dn",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"values",
"instanceof",
"OperatorCollection",
")",
"&&",
"!",
"$",
"this",
"->",
"schema",
")",
"{",
"return",
"$",
"va... | Checks for attributes assigned an attribute converter. It will replace the value with the converted value then
send back all the attributes.
@param array|BatchCollection|OperatorCollection $values
@param string|null $dn
@return array|BatchCollection|OperatorCollection | [
"Checks",
"for",
"attributes",
"assigned",
"an",
"attribute",
"converter",
".",
"It",
"will",
"replace",
"the",
"value",
"with",
"the",
"converted",
"value",
"then",
"send",
"back",
"all",
"the",
"attributes",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L301-L314 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.convertNamesToLdap | protected function convertNamesToLdap(array $attributes)
{
return !$this->schema ? $attributes : (new AttributeNameResolver($this->schema))->toLdap($attributes);
} | php | protected function convertNamesToLdap(array $attributes)
{
return !$this->schema ? $attributes : (new AttributeNameResolver($this->schema))->toLdap($attributes);
} | [
"protected",
"function",
"convertNamesToLdap",
"(",
"array",
"$",
"attributes",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"schema",
"?",
"$",
"attributes",
":",
"(",
"new",
"AttributeNameResolver",
"(",
"$",
"this",
"->",
"schema",
")",
")",
"->",
"toLda... | Converts attribute names from their schema defined value to the value LDAP needs them in.
@param array $attributes
@return array | [
"Converts",
"attribute",
"names",
"from",
"their",
"schema",
"defined",
"value",
"to",
"the",
"value",
"LDAP",
"needs",
"them",
"in",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L322-L325 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/ArrayHydrator.php | ArrayHydrator.configureValueResolver | protected function configureValueResolver(BaseValueResolver $valueResolver, $dn = null)
{
if ($this->connection) {
$valueResolver->setLdapConnection($this->connection);
}
if (!is_null($dn)) {
$valueResolver->setDn($dn);
}
} | php | protected function configureValueResolver(BaseValueResolver $valueResolver, $dn = null)
{
if ($this->connection) {
$valueResolver->setLdapConnection($this->connection);
}
if (!is_null($dn)) {
$valueResolver->setDn($dn);
}
} | [
"protected",
"function",
"configureValueResolver",
"(",
"BaseValueResolver",
"$",
"valueResolver",
",",
"$",
"dn",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"valueResolver",
"->",
"setLdapConnection",
"(",
"$",
"this",
... | Retrieve the AttributeValueResolver instance with the connection and other information set if needed.
@param BaseValueResolver $valueResolver
@param null|string $dn | [
"Retrieve",
"the",
"AttributeValueResolver",
"instance",
"with",
"the",
"connection",
"and",
"other",
"information",
"set",
"if",
"needed",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/ArrayHydrator.php#L344-L352 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/AttributeValueResolver.php | AttributeValueResolver.fromLdap | public function fromLdap()
{
$entry = $this->convert($this->entry, false);
foreach ($entry as $attribute => $value) {
if ($this->schema->isMultivaluedAttribute($attribute) && !is_array($value)) {
$entry[$attribute] = [$value];
}
}
return $entry;
} | php | public function fromLdap()
{
$entry = $this->convert($this->entry, false);
foreach ($entry as $attribute => $value) {
if ($this->schema->isMultivaluedAttribute($attribute) && !is_array($value)) {
$entry[$attribute] = [$value];
}
}
return $entry;
} | [
"public",
"function",
"fromLdap",
"(",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"convert",
"(",
"$",
"this",
"->",
"entry",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"entry",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"... | Convert values from LDAP.
@return array | [
"Convert",
"values",
"from",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/AttributeValueResolver.php#L50-L61 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/AttributeValueResolver.php | AttributeValueResolver.convert | protected function convert(array $attributes, $toLdap = true)
{
$direction = $toLdap ? 'toLdap' : 'fromLdap';
foreach ($attributes as $attribute => $values) {
// No converter, but the value should still be encoded.
if (!$this->schema->hasConverter($attribute) && !isset($this->converted[$attribute])) {
$attributes[$attribute] = $this->encodeValues($values);
// Only continue if it has a converter and has not already been converted.
} elseif ($this->schema->hasConverter($attribute) && !in_array($attribute, $this->converted)) {
$values = $this->getConvertedValues($values, $attribute, $direction);
if (in_array($attribute, $this->aggregated)) {
$attribute = $this->schema->getAttributeToLdap($attribute);
}
$attributes[$attribute] = (count($values) == 1) ? reset($values) : $values;
}
}
return $this->removeValuesFromEntry($attributes, array_merge($this->aggregated, $this->remove));
} | php | protected function convert(array $attributes, $toLdap = true)
{
$direction = $toLdap ? 'toLdap' : 'fromLdap';
foreach ($attributes as $attribute => $values) {
// No converter, but the value should still be encoded.
if (!$this->schema->hasConverter($attribute) && !isset($this->converted[$attribute])) {
$attributes[$attribute] = $this->encodeValues($values);
// Only continue if it has a converter and has not already been converted.
} elseif ($this->schema->hasConverter($attribute) && !in_array($attribute, $this->converted)) {
$values = $this->getConvertedValues($values, $attribute, $direction);
if (in_array($attribute, $this->aggregated)) {
$attribute = $this->schema->getAttributeToLdap($attribute);
}
$attributes[$attribute] = (count($values) == 1) ? reset($values) : $values;
}
}
return $this->removeValuesFromEntry($attributes, array_merge($this->aggregated, $this->remove));
} | [
"protected",
"function",
"convert",
"(",
"array",
"$",
"attributes",
",",
"$",
"toLdap",
"=",
"true",
")",
"{",
"$",
"direction",
"=",
"$",
"toLdap",
"?",
"'toLdap'",
":",
"'fromLdap'",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>"... | Perform the attribute conversion process.
@param array $attributes
@param bool $toLdap
@return array | [
"Perform",
"the",
"attribute",
"conversion",
"process",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/AttributeValueResolver.php#L80-L99 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/HydrateQueryTrait.php | HydrateQueryTrait.mergeOrderByAttributes | protected function mergeOrderByAttributes(array $attributes, $alias = null)
{
if (!$this->isWildCardSelection() && !empty($this->orderBy)) {
$orderBy = $this->getAttributesForAlias(array_keys($this->orderBy), $alias);
$lcAttributes = array_map('strtolower', $attributes);
foreach ($orderBy as $attribute) {
if (!in_array(strtolower($attribute), $lcAttributes)) {
$attributes[] = $attribute;
}
}
}
return $attributes;
} | php | protected function mergeOrderByAttributes(array $attributes, $alias = null)
{
if (!$this->isWildCardSelection() && !empty($this->orderBy)) {
$orderBy = $this->getAttributesForAlias(array_keys($this->orderBy), $alias);
$lcAttributes = array_map('strtolower', $attributes);
foreach ($orderBy as $attribute) {
if (!in_array(strtolower($attribute), $lcAttributes)) {
$attributes[] = $attribute;
}
}
}
return $attributes;
} | [
"protected",
"function",
"mergeOrderByAttributes",
"(",
"array",
"$",
"attributes",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isWildCardSelection",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"orderBy",
")",
... | If any attributes that were requested to be ordered by are not explicitly in the attribute selection, add them.
@param array $attributes
@param null|string $alias
@return array | [
"If",
"any",
"attributes",
"that",
"were",
"requested",
"to",
"be",
"ordered",
"by",
"are",
"not",
"explicitly",
"in",
"the",
"attribute",
"selection",
"add",
"them",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/HydrateQueryTrait.php#L32-L45 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/HydrateQueryTrait.php | HydrateQueryTrait.getSelectedQueryAttributes | protected function getSelectedQueryAttributes(array $attributes, LdapObjectSchema $schema = null)
{
// Interpret a single wildcard as only schema attributes.
if ($schema && !empty($attributes) && $attributes[0] == '*') {
$attributes = array_keys($schema->getAttributeMap());
// Interpret a double wildcard as all LDAP attributes even if they aren't in the schema file.
} elseif ($schema && !empty($attributes) && $attributes[0] == '**') {
$attributes = ['*'];
}
return $attributes;
} | php | protected function getSelectedQueryAttributes(array $attributes, LdapObjectSchema $schema = null)
{
// Interpret a single wildcard as only schema attributes.
if ($schema && !empty($attributes) && $attributes[0] == '*') {
$attributes = array_keys($schema->getAttributeMap());
// Interpret a double wildcard as all LDAP attributes even if they aren't in the schema file.
} elseif ($schema && !empty($attributes) && $attributes[0] == '**') {
$attributes = ['*'];
}
return $attributes;
} | [
"protected",
"function",
"getSelectedQueryAttributes",
"(",
"array",
"$",
"attributes",
",",
"LdapObjectSchema",
"$",
"schema",
"=",
"null",
")",
"{",
"// Interpret a single wildcard as only schema attributes.",
"if",
"(",
"$",
"schema",
"&&",
"!",
"empty",
"(",
"$",
... | Determine what attributes should be selected. This helps account for all attributes being selected both within
and out of the context of a schema.
@param array $attributes
@param LdapObjectSchema|null $schema
@return array | [
"Determine",
"what",
"attributes",
"should",
"be",
"selected",
".",
"This",
"helps",
"account",
"for",
"all",
"attributes",
"being",
"selected",
"both",
"within",
"and",
"out",
"of",
"the",
"context",
"of",
"a",
"schema",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/HydrateQueryTrait.php#L55-L66 | train |
ldaptools/ldaptools | src/LdapTools/Hydrator/HydrateQueryTrait.php | HydrateQueryTrait.getAttributesToLdap | protected function getAttributesToLdap(array $attributes, $translate, LdapObjectSchema $schema = null, $alias = null)
{
// First determine if this was some sort of wildcard selection
$attributes = $this->getSelectedQueryAttributes($attributes, $schema);
// This will return only the attributes for the current alias, minus the possible alias prefix.
if ($schema) {
$attributes = $this->getAttributesForAlias($attributes, $alias);
}
// If we still have an empty array here, then fill it with the defaults because nothing was selected specifically.
if ($schema && empty($attributes)) {
$attributes = $schema->getAttributesToSelect();
}
// At this point we add any orderBy attributes that are not being specifically selected already.
if (!empty($this->orderBy)) {
$attributes = $this->mergeOrderByAttributes($attributes, $alias);
}
if ($schema && $translate) {
$newAttributes = [];
foreach ($attributes as $attribute) {
$newAttributes[] = $schema->getAttributeToLdap($attribute);
}
$attributes = $newAttributes;
}
return $attributes;
} | php | protected function getAttributesToLdap(array $attributes, $translate, LdapObjectSchema $schema = null, $alias = null)
{
// First determine if this was some sort of wildcard selection
$attributes = $this->getSelectedQueryAttributes($attributes, $schema);
// This will return only the attributes for the current alias, minus the possible alias prefix.
if ($schema) {
$attributes = $this->getAttributesForAlias($attributes, $alias);
}
// If we still have an empty array here, then fill it with the defaults because nothing was selected specifically.
if ($schema && empty($attributes)) {
$attributes = $schema->getAttributesToSelect();
}
// At this point we add any orderBy attributes that are not being specifically selected already.
if (!empty($this->orderBy)) {
$attributes = $this->mergeOrderByAttributes($attributes, $alias);
}
if ($schema && $translate) {
$newAttributes = [];
foreach ($attributes as $attribute) {
$newAttributes[] = $schema->getAttributeToLdap($attribute);
}
$attributes = $newAttributes;
}
return $attributes;
} | [
"protected",
"function",
"getAttributesToLdap",
"(",
"array",
"$",
"attributes",
",",
"$",
"translate",
",",
"LdapObjectSchema",
"$",
"schema",
"=",
"null",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"// First determine if this was some sort of wildcard selection",
"$"... | Performs the logic needed to determine what attributes were actually selected, or should be selected, when going
to LDAP and whether they should be returned as schema translated names.
@param array $attributes
@param bool
@param LdapObjectSchema|null $schema
@param null|string $alias
@return array | [
"Performs",
"the",
"logic",
"needed",
"to",
"determine",
"what",
"attributes",
"were",
"actually",
"selected",
"or",
"should",
"be",
"selected",
"when",
"going",
"to",
"LDAP",
"and",
"whether",
"they",
"should",
"be",
"returned",
"as",
"schema",
"translated",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Hydrator/HydrateQueryTrait.php#L98-L124 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/DialInData.php | DialInData.toBinary | public function toBinary()
{
$binary = hex2bin(str_pad(dechex(ord($this->signature)), 2, 0, STR_PAD_LEFT));
$binary .= hex2bin($this->dec2hex($this->userPrivilege));
$binary .= hex2bin($this->callbackPhoneNumber);
return $binary;
} | php | public function toBinary()
{
$binary = hex2bin(str_pad(dechex(ord($this->signature)), 2, 0, STR_PAD_LEFT));
$binary .= hex2bin($this->dec2hex($this->userPrivilege));
$binary .= hex2bin($this->callbackPhoneNumber);
return $binary;
} | [
"public",
"function",
"toBinary",
"(",
")",
"{",
"$",
"binary",
"=",
"hex2bin",
"(",
"str_pad",
"(",
"dechex",
"(",
"ord",
"(",
"$",
"this",
"->",
"signature",
")",
")",
",",
"2",
",",
"0",
",",
"STR_PAD_LEFT",
")",
")",
";",
"$",
"binary",
".=",
... | Get the binary representation of the dial-in data for the userParameters value.
@return string | [
"Get",
"the",
"binary",
"representation",
"of",
"the",
"dial",
"-",
"in",
"data",
"for",
"the",
"userParameters",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/DialInData.php#L123-L130 | train |
ldaptools/ldaptools | src/LdapTools/Connection/BindUserStrategy.php | BindUserStrategy.getInstance | public static function getInstance(DomainConfiguration $config)
{
if (LdapConnection::TYPE_AD == $config->getLdapType()) {
return new ADBindUserStrategy($config);
} else {
return new self($config);
}
} | php | public static function getInstance(DomainConfiguration $config)
{
if (LdapConnection::TYPE_AD == $config->getLdapType()) {
return new ADBindUserStrategy($config);
} else {
return new self($config);
}
} | [
"public",
"static",
"function",
"getInstance",
"(",
"DomainConfiguration",
"$",
"config",
")",
"{",
"if",
"(",
"LdapConnection",
"::",
"TYPE_AD",
"==",
"$",
"config",
"->",
"getLdapType",
"(",
")",
")",
"{",
"return",
"new",
"ADBindUserStrategy",
"(",
"$",
"... | Given the LDAP type, determine the BindStrategy to use.
@param DomainConfiguration $config
@return ADBindUserStrategy|BindUserStrategy | [
"Given",
"the",
"LDAP",
"type",
"determine",
"the",
"BindStrategy",
"to",
"use",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/BindUserStrategy.php#L59-L66 | train |
ldaptools/ldaptools | src/LdapTools/Connection/BindUserStrategy.php | BindUserStrategy.getUsername | public function getUsername($username)
{
if ($this->isValidUserDn($username)) {
return $username;
}
$replacements = [
$username,
$this->config->getDomainName(),
];
return preg_replace($this->params, $replacements, $this->bindFormat);
} | php | public function getUsername($username)
{
if ($this->isValidUserDn($username)) {
return $username;
}
$replacements = [
$username,
$this->config->getDomainName(),
];
return preg_replace($this->params, $replacements, $this->bindFormat);
} | [
"public",
"function",
"getUsername",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isValidUserDn",
"(",
"$",
"username",
")",
")",
"{",
"return",
"$",
"username",
";",
"}",
"$",
"replacements",
"=",
"[",
"$",
"username",
",",
"$",
"t... | Determine the format to use for a bind username going to LDAP.
@param string $username
@return string | [
"Determine",
"the",
"format",
"to",
"use",
"for",
"a",
"bind",
"username",
"going",
"to",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/BindUserStrategy.php#L74-L85 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/Ldif.php | Ldif.addEntry | public function addEntry(LdifEntryInterface ...$entries)
{
foreach ($entries as $entry) {
$this->entries[] = $entry;
}
return $this;
} | php | public function addEntry(LdifEntryInterface ...$entries)
{
foreach ($entries as $entry) {
$this->entries[] = $entry;
}
return $this;
} | [
"public",
"function",
"addEntry",
"(",
"LdifEntryInterface",
"...",
"$",
"entries",
")",
"{",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"this",
"->",
"entries",
"[",
"]",
"=",
"$",
"entry",
";",
"}",
"return",
"$",
"this",
";... | Add one or more LDIF entry objects.
@param LdifEntryInterface[] ...$entries
@return $this | [
"Add",
"one",
"or",
"more",
"LDIF",
"entry",
"objects",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/Ldif.php#L160-L167 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/Ldif.php | Ldif.toString | public function toString()
{
$ldif = $this->addCommentsToString('');
if (!is_null($this->version)) {
$ldif .= $this->getLdifLine(self::DIRECTIVE_VERSION, $this->version);
}
foreach ($this->entries as $entry) {
$this->setupEntry($entry);
$ldif .= $this->lineEnding.$entry->toString();
}
return $ldif;
} | php | public function toString()
{
$ldif = $this->addCommentsToString('');
if (!is_null($this->version)) {
$ldif .= $this->getLdifLine(self::DIRECTIVE_VERSION, $this->version);
}
foreach ($this->entries as $entry) {
$this->setupEntry($entry);
$ldif .= $this->lineEnding.$entry->toString();
}
return $ldif;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"ldif",
"=",
"$",
"this",
"->",
"addCommentsToString",
"(",
"''",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"version",
")",
")",
"{",
"$",
"ldif",
".=",
"$",
"this",
"->",
"... | Get the string representation of the LDIF object with all of the entries it has.
@return string | [
"Get",
"the",
"string",
"representation",
"of",
"the",
"LDIF",
"object",
"with",
"all",
"of",
"the",
"entries",
"it",
"has",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/Ldif.php#L184-L196 | train |
ldaptools/ldaptools | src/LdapTools/Ldif/Ldif.php | Ldif.toOperations | public function toOperations()
{
$operations = [];
foreach ($this->entries as $entry) {
$this->setupEntry($entry);
$operations[] = $entry->toOperation();
}
return $operations;
} | php | public function toOperations()
{
$operations = [];
foreach ($this->entries as $entry) {
$this->setupEntry($entry);
$operations[] = $entry->toOperation();
}
return $operations;
} | [
"public",
"function",
"toOperations",
"(",
")",
"{",
"$",
"operations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"this",
"->",
"setupEntry",
"(",
"$",
"entry",
")",
";",
"$",
"operations",
... | Get all of the operations represented by all of the entries for this LDIF object.
@return LdapOperationInterface[] | [
"Get",
"all",
"of",
"the",
"operations",
"represented",
"by",
"all",
"of",
"the",
"entries",
"for",
"this",
"LDIF",
"object",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Ldif/Ldif.php#L203-L213 | train |
ldaptools/ldaptools | src/LdapTools/Security/Flags.php | Flags.remove | public function remove(...$flags)
{
foreach ($flags as $flag) {
if ($this->has($flag)) {
$this->flags = $this->flags ^ (int) $flag;
}
}
return $this;
} | php | public function remove(...$flags)
{
foreach ($flags as $flag) {
if ($this->has($flag)) {
$this->flags = $this->flags ^ (int) $flag;
}
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"...",
"$",
"flags",
")",
"{",
"foreach",
"(",
"$",
"flags",
"as",
"$",
"flag",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"flag",
")",
")",
"{",
"$",
"this",
"->",
"flags",
"=",
"$",
"this",
... | Remove a flag from the value.
@param int[] ...$flags
@return $this | [
"Remove",
"a",
"flag",
"from",
"the",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/Flags.php#L56-L65 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.addConnection | public function addConnection(LdapConnectionInterface ...$connections)
{
foreach ($connections as $connection) {
$this->domains[$connection->getConfig()->getDomainName()] = $connection->getConfig();
$this->connections[$connection->getConfig()->getDomainName()] = $connection;
}
return $this;
} | php | public function addConnection(LdapConnectionInterface ...$connections)
{
foreach ($connections as $connection) {
$this->domains[$connection->getConfig()->getDomainName()] = $connection->getConfig();
$this->connections[$connection->getConfig()->getDomainName()] = $connection;
}
return $this;
} | [
"public",
"function",
"addConnection",
"(",
"LdapConnectionInterface",
"...",
"$",
"connections",
")",
"{",
"foreach",
"(",
"$",
"connections",
"as",
"$",
"connection",
")",
"{",
"$",
"this",
"->",
"domains",
"[",
"$",
"connection",
"->",
"getConfig",
"(",
"... | Explicitly add connections using already constructed connection objects.
@param Connection\LdapConnectionInterface[] $connections
@return $this | [
"Explicitly",
"add",
"connections",
"using",
"already",
"constructed",
"connection",
"objects",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L144-L152 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getConnection | public function getConnection($domain = null)
{
$domain = $domain ?: $this->context;
$this->validateDomainName($domain);
if (!$this->connections[$domain]) {
$this->connections[$domain] = new LdapConnection(
$this->domains[$domain],
$this->config->getEventDispatcher(),
$this->config->getLogger(),
$this->getCache()
);
}
return $this->connections[$domain];
} | php | public function getConnection($domain = null)
{
$domain = $domain ?: $this->context;
$this->validateDomainName($domain);
if (!$this->connections[$domain]) {
$this->connections[$domain] = new LdapConnection(
$this->domains[$domain],
$this->config->getEventDispatcher(),
$this->config->getLogger(),
$this->getCache()
);
}
return $this->connections[$domain];
} | [
"public",
"function",
"getConnection",
"(",
"$",
"domain",
"=",
"null",
")",
"{",
"$",
"domain",
"=",
"$",
"domain",
"?",
":",
"$",
"this",
"->",
"context",
";",
"$",
"this",
"->",
"validateDomainName",
"(",
"$",
"domain",
")",
";",
"if",
"(",
"!",
... | Get the Ldap Connection object. By default it will get the connection of the domain currently in context. To get
a different domain connection pass the domain name as a parameter.
@param null|string $domain
@return Connection\LdapConnectionInterface | [
"Get",
"the",
"Ldap",
"Connection",
"object",
".",
"By",
"default",
"it",
"will",
"get",
"the",
"connection",
"of",
"the",
"domain",
"currently",
"in",
"context",
".",
"To",
"get",
"a",
"different",
"domain",
"connection",
"pass",
"the",
"domain",
"name",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L161-L176 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.createLdapObject | public function createLdapObject($type = null)
{
$creator = new LdapObjectCreator(
$this->getConnection(),
$this->getSchemaFactory(),
$this->config->getEventDispatcher()
);
if ($type) {
$creator->create($type);
}
return $creator;
} | php | public function createLdapObject($type = null)
{
$creator = new LdapObjectCreator(
$this->getConnection(),
$this->getSchemaFactory(),
$this->config->getEventDispatcher()
);
if ($type) {
$creator->create($type);
}
return $creator;
} | [
"public",
"function",
"createLdapObject",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"creator",
"=",
"new",
"LdapObjectCreator",
"(",
"$",
"this",
"->",
"getConnection",
"(",
")",
",",
"$",
"this",
"->",
"getSchemaFactory",
"(",
")",
",",
"$",
"this",... | Get a LdapObjectCreator object.
@param string|null $type
@return LdapObjectCreator | [
"Get",
"a",
"LdapObjectCreator",
"object",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L194-L206 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getRepository | public function getRepository($type)
{
try {
$ldapObjectSchema = $this->getLdapObjectSchema($type);
$repositoryClass = $ldapObjectSchema->getRepository();
if (!class_exists($repositoryClass)) {
throw new \RuntimeException(sprintf('Repository class "%s" not found.', $repositoryClass));
}
$repository = new $repositoryClass($ldapObjectSchema, $this->getConnection());
if (!($repository instanceof LdapObjectRepository)) {
throw new \RuntimeException('Your repository class must extend \LdapTools\Object\LdapObjectRepository.');
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
} catch (\Throwable $e) {
throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
}
return $repository;
} | php | public function getRepository($type)
{
try {
$ldapObjectSchema = $this->getLdapObjectSchema($type);
$repositoryClass = $ldapObjectSchema->getRepository();
if (!class_exists($repositoryClass)) {
throw new \RuntimeException(sprintf('Repository class "%s" not found.', $repositoryClass));
}
$repository = new $repositoryClass($ldapObjectSchema, $this->getConnection());
if (!($repository instanceof LdapObjectRepository)) {
throw new \RuntimeException('Your repository class must extend \LdapTools\Object\LdapObjectRepository.');
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
} catch (\Throwable $e) {
throw new \RuntimeException(sprintf('Unable to load Repository for type "%s": %s', $type, $e->getMessage()));
}
return $repository;
} | [
"public",
"function",
"getRepository",
"(",
"$",
"type",
")",
"{",
"try",
"{",
"$",
"ldapObjectSchema",
"=",
"$",
"this",
"->",
"getLdapObjectSchema",
"(",
"$",
"type",
")",
";",
"$",
"repositoryClass",
"=",
"$",
"ldapObjectSchema",
"->",
"getRepository",
"(... | Get a repository for a specific LDAP object type.
@param string $type
@return LdapObjectRepository | [
"Get",
"a",
"repository",
"for",
"a",
"specific",
"LDAP",
"object",
"type",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L224-L243 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.delete | public function delete(LdapObject $ldapObject, $recursively = false)
{
$this->getObjectManager()->delete($ldapObject, $recursively);
return $this;
} | php | public function delete(LdapObject $ldapObject, $recursively = false)
{
$this->getObjectManager()->delete($ldapObject, $recursively);
return $this;
} | [
"public",
"function",
"delete",
"(",
"LdapObject",
"$",
"ldapObject",
",",
"$",
"recursively",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"getObjectManager",
"(",
")",
"->",
"delete",
"(",
"$",
"ldapObject",
",",
"$",
"recursively",
")",
";",
"return",
"... | Delete an object from LDAP. Optionally you can set the second argument to true which sends a control to LDAP to
perform a recursive deletion. This is helpful in the case of deleting an OU with with objects underneath it. By
setting the second parameter to true the OU and all objects below it would be deleted. Use with care!
If recursive deletion does not work, first check that 'accidental deletion' is not enabled on the object (AD).
@param LdapObject $ldapObject
@param bool $recursively
@return $this | [
"Delete",
"an",
"object",
"from",
"LDAP",
".",
"Optionally",
"you",
"can",
"set",
"the",
"second",
"argument",
"to",
"true",
"which",
"sends",
"a",
"control",
"to",
"LDAP",
"to",
"perform",
"a",
"recursive",
"deletion",
".",
"This",
"is",
"helpful",
"in",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L269-L274 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getSchemaFactory | public function getSchemaFactory()
{
if (!$this->schemaFactory) {
$this->schemaFactory = new LdapObjectSchemaFactory(
$this->getCache(), $this->getSchemaParser(), $this->config->getEventDispatcher()
);
}
return $this->schemaFactory;
} | php | public function getSchemaFactory()
{
if (!$this->schemaFactory) {
$this->schemaFactory = new LdapObjectSchemaFactory(
$this->getCache(), $this->getSchemaParser(), $this->config->getEventDispatcher()
);
}
return $this->schemaFactory;
} | [
"public",
"function",
"getSchemaFactory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"schemaFactory",
")",
"{",
"$",
"this",
"->",
"schemaFactory",
"=",
"new",
"LdapObjectSchemaFactory",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
",",
"$",
"thi... | Retrieve the schema factory instance.
@return LdapObjectSchemaFactory | [
"Retrieve",
"the",
"schema",
"factory",
"instance",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L336-L345 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getCache | public function getCache()
{
if (!$this->config->getCache()) {
// This will be removed eventually. The default cache will be instantiated directly in the config class.
$this->config->setCache(CacheFactory::get($this->config->getCacheType(), $this->config->getCacheOptions()));
}
return $this->config->getCache();
} | php | public function getCache()
{
if (!$this->config->getCache()) {
// This will be removed eventually. The default cache will be instantiated directly in the config class.
$this->config->setCache(CacheFactory::get($this->config->getCacheType(), $this->config->getCacheOptions()));
}
return $this->config->getCache();
} | [
"public",
"function",
"getCache",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"getCache",
"(",
")",
")",
"{",
"// This will be removed eventually. The default cache will be instantiated directly in the config class.",
"$",
"this",
"->",
"config",
... | Retrieve the cache instance.
@return Cache\CacheInterface | [
"Retrieve",
"the",
"cache",
"instance",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L352-L360 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getSchemaParser | public function getSchemaParser()
{
if (!$this->schemaParser) {
$this->schemaParser = SchemaParserFactory::get(
$this->config->getSchemaFormat(),
$this->config->getSchemaFolder()
);
}
return $this->schemaParser;
} | php | public function getSchemaParser()
{
if (!$this->schemaParser) {
$this->schemaParser = SchemaParserFactory::get(
$this->config->getSchemaFormat(),
$this->config->getSchemaFolder()
);
}
return $this->schemaParser;
} | [
"public",
"function",
"getSchemaParser",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"schemaParser",
")",
"{",
"$",
"this",
"->",
"schemaParser",
"=",
"SchemaParserFactory",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
"->",
"getSchemaFormat",
"(",... | Retrieve the schema parser instance.
@return Schema\Parser\SchemaParserInterface | [
"Retrieve",
"the",
"schema",
"parser",
"instance",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L367-L377 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.validateDomainName | protected function validateDomainName($domain)
{
if (!array_key_exists($domain, $this->domains)) {
throw new InvalidArgumentException(sprintf(
'Domain "%s" is not valid. Valid domains are: %s',
$domain,
implode(', ', array_keys($this->domains))
));
}
} | php | protected function validateDomainName($domain)
{
if (!array_key_exists($domain, $this->domains)) {
throw new InvalidArgumentException(sprintf(
'Domain "%s" is not valid. Valid domains are: %s',
$domain,
implode(', ', array_keys($this->domains))
));
}
} | [
"protected",
"function",
"validateDomainName",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"domain",
",",
"$",
"this",
"->",
"domains",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Domain \... | Validates that the domain name actually exists.
@param string $domain | [
"Validates",
"that",
"the",
"domain",
"name",
"actually",
"exists",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L394-L403 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getObjectManager | protected function getObjectManager()
{
if (!isset($this->ldapObjectManager[$this->context])) {
$this->ldapObjectManager[$this->context] = new LdapObjectManager(
$this->getConnection(),
$this->getSchemaFactory(),
$this->config->getEventDispatcher()
);
}
return $this->ldapObjectManager[$this->context];
} | php | protected function getObjectManager()
{
if (!isset($this->ldapObjectManager[$this->context])) {
$this->ldapObjectManager[$this->context] = new LdapObjectManager(
$this->getConnection(),
$this->getSchemaFactory(),
$this->config->getEventDispatcher()
);
}
return $this->ldapObjectManager[$this->context];
} | [
"protected",
"function",
"getObjectManager",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"ldapObjectManager",
"[",
"$",
"this",
"->",
"context",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ldapObjectManager",
"[",
"$",
"this",
"->",
"co... | Retrieve the LdapObjectManager for the current domain context.
@return LdapObjectManager | [
"Retrieve",
"the",
"LdapObjectManager",
"for",
"the",
"current",
"domain",
"context",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L410-L421 | train |
ldaptools/ldaptools | src/LdapTools/LdapManager.php | LdapManager.getLdapObjectSchema | protected function getLdapObjectSchema($type)
{
return $this->getSchemaFactory()->get($this->getConnection()->getConfig()->getSchemaName(), $type);
} | php | protected function getLdapObjectSchema($type)
{
return $this->getSchemaFactory()->get($this->getConnection()->getConfig()->getSchemaName(), $type);
} | [
"protected",
"function",
"getLdapObjectSchema",
"(",
"$",
"type",
")",
"{",
"return",
"$",
"this",
"->",
"getSchemaFactory",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getConfig",
"(",
")",
"->",
"getSchemaName",
"(",
... | Get the LDAP object schema from the factory by its type.
@param string $type
@return Schema\LdapObjectSchema | [
"Get",
"the",
"LDAP",
"object",
"schema",
"from",
"the",
"factory",
"by",
"its",
"type",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/LdapManager.php#L429-L432 | train |
ldaptools/ldaptools | src/LdapTools/Cache/DoctrineCache.php | DoctrineCache.parseOptions | protected function parseOptions(array $options)
{
if (isset($options['cache_folder'])) {
$this->setCacheFolder($options['cache_folder']);
}
if (isset($options['cache_prefix'])) {
$this->cachePrefix = $options['cache_prefix'];
}
} | php | protected function parseOptions(array $options)
{
if (isset($options['cache_folder'])) {
$this->setCacheFolder($options['cache_folder']);
}
if (isset($options['cache_prefix'])) {
$this->cachePrefix = $options['cache_prefix'];
}
} | [
"protected",
"function",
"parseOptions",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'cache_folder'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setCacheFolder",
"(",
"$",
"options",
"[",
"'cache_folder'",
"]",
")"... | Check for any options that apply to the Doctrine cache.
@param array $options | [
"Check",
"for",
"any",
"options",
"that",
"apply",
"to",
"the",
"Doctrine",
"cache",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Cache/DoctrineCache.php#L155-L163 | train |
ldaptools/ldaptools | src/LdapTools/Security/SddlParser.php | SddlParser.parse | public function parse($sddl)
{
if (!preg_match(self::MATCH_SDDL, (string) $sddl, $matches)) {
throw new SddlParserException('The SDDL string is not valid.');
}
$sd = (new SecurityDescriptor())
->setOwner($this->getSid($matches[1], 'owner'))
->setGroup($this->getSid($matches[2], 'group'));
$this->parseAcl(strtoupper($matches[4]), $matches[5], $sd);
if (isset($matches[7])) {
$this->parseAcl(strtoupper($matches[7]), $matches[8], $sd);
}
return $sd;
} | php | public function parse($sddl)
{
if (!preg_match(self::MATCH_SDDL, (string) $sddl, $matches)) {
throw new SddlParserException('The SDDL string is not valid.');
}
$sd = (new SecurityDescriptor())
->setOwner($this->getSid($matches[1], 'owner'))
->setGroup($this->getSid($matches[2], 'group'));
$this->parseAcl(strtoupper($matches[4]), $matches[5], $sd);
if (isset($matches[7])) {
$this->parseAcl(strtoupper($matches[7]), $matches[8], $sd);
}
return $sd;
} | [
"public",
"function",
"parse",
"(",
"$",
"sddl",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"self",
"::",
"MATCH_SDDL",
",",
"(",
"string",
")",
"$",
"sddl",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"SddlParserException",
"(",
"'The SDDL s... | Given a full SDDL string, parse it and return the SecurityDescriptor object that it represents.
@param string $sddl
@return SecurityDescriptor
@throws SddlParserException | [
"Given",
"a",
"full",
"SDDL",
"string",
"parse",
"it",
"and",
"return",
"the",
"SecurityDescriptor",
"object",
"that",
"it",
"represents",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/SddlParser.php#L71-L87 | train |
ldaptools/ldaptools | src/LdapTools/AttributeConverter/ConvertFlags.php | ConvertFlags.modifyFlagValue | protected function modifyFlagValue($value)
{
$this->setDefaultLastValue($this->getEnumAttribute(), $this->getDefaultEnumValue());
$flags = $this->getFlagFromLastValue($this->getLastValue());
$value = $this->options['invert'] ? !$value : $value;
if ($value) {
$flags->add($this->flagName);
} else {
$flags->remove($this->flagName);
}
return $flags->getValue();
} | php | protected function modifyFlagValue($value)
{
$this->setDefaultLastValue($this->getEnumAttribute(), $this->getDefaultEnumValue());
$flags = $this->getFlagFromLastValue($this->getLastValue());
$value = $this->options['invert'] ? !$value : $value;
if ($value) {
$flags->add($this->flagName);
} else {
$flags->remove($this->flagName);
}
return $flags->getValue();
} | [
"protected",
"function",
"modifyFlagValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setDefaultLastValue",
"(",
"$",
"this",
"->",
"getEnumAttribute",
"(",
")",
",",
"$",
"this",
"->",
"getDefaultEnumValue",
"(",
")",
")",
";",
"$",
"flags",
"=",
... | Given a bool value, do the needed bitwise comparison against the flag value to either remove or add the bit from
the overall value.
@param bool $value
@return int | [
"Given",
"a",
"bool",
"value",
"do",
"the",
"needed",
"bitwise",
"comparison",
"against",
"the",
"flag",
"value",
"to",
"either",
"remove",
"or",
"add",
"the",
"bit",
"from",
"the",
"overall",
"value",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/AttributeConverter/ConvertFlags.php#L102-L115 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.executeOperation | protected function executeOperation(LdapOperationInterface $operation, LogOperation $log = null)
{
$lastServer = $this->connection->getServer();
try {
$this->connectIfNotBound($operation);
$lastServer = $this->connection->getServer();
$handler = $this->getOperationHandler($operation);
$handler->setOperationDefaults($operation);
$this->logStart($log);
$this->invalidateCacheIfNeeded($operation);
list($result, $usedCache, $cacheKey) = $this->getCacheOrHandlerResult($operation, $handler, $log);
$this->cacheResultIfNeeded($operation, $result, $usedCache, $cacheKey);
return $result;
} catch (\Throwable $e) {
$this->logExceptionAndThrow($e, $log);
} catch (\Exception $e) {
$this->logExceptionAndThrow($e, $log);
} finally {
$this->logEnd($log);
// It would not have set controls or switched servers if the cache was used...
if (isset($usedCache) && $usedCache === false) {
$this->resetLdapControls($operation);
$this->switchServerIfNeeded($this->connection->getServer(), $lastServer, $operation);
}
$this->dispatcher->dispatch(new LdapOperationEvent(Event::LDAP_OPERATION_EXECUTE_AFTER, $operation, $this->connection));
}
} | php | protected function executeOperation(LdapOperationInterface $operation, LogOperation $log = null)
{
$lastServer = $this->connection->getServer();
try {
$this->connectIfNotBound($operation);
$lastServer = $this->connection->getServer();
$handler = $this->getOperationHandler($operation);
$handler->setOperationDefaults($operation);
$this->logStart($log);
$this->invalidateCacheIfNeeded($operation);
list($result, $usedCache, $cacheKey) = $this->getCacheOrHandlerResult($operation, $handler, $log);
$this->cacheResultIfNeeded($operation, $result, $usedCache, $cacheKey);
return $result;
} catch (\Throwable $e) {
$this->logExceptionAndThrow($e, $log);
} catch (\Exception $e) {
$this->logExceptionAndThrow($e, $log);
} finally {
$this->logEnd($log);
// It would not have set controls or switched servers if the cache was used...
if (isset($usedCache) && $usedCache === false) {
$this->resetLdapControls($operation);
$this->switchServerIfNeeded($this->connection->getServer(), $lastServer, $operation);
}
$this->dispatcher->dispatch(new LdapOperationEvent(Event::LDAP_OPERATION_EXECUTE_AFTER, $operation, $this->connection));
}
} | [
"protected",
"function",
"executeOperation",
"(",
"LdapOperationInterface",
"$",
"operation",
",",
"LogOperation",
"$",
"log",
"=",
"null",
")",
"{",
"$",
"lastServer",
"=",
"$",
"this",
"->",
"connection",
"->",
"getServer",
"(",
")",
";",
"try",
"{",
"$",
... | Execute a given operation with an operation handler.
@param LdapOperationInterface $operation
@param LogOperation|null $log
@return mixed
@throws \Throwable | [
"Execute",
"a",
"given",
"operation",
"with",
"an",
"operation",
"handler",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L76-L103 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.getLogObject | protected function getLogObject(LdapOperationInterface $operation)
{
if (!$this->logger) {
return null;
}
return (new LogOperation($operation))->setDomain($this->connection->getConfig()->getDomainName());
} | php | protected function getLogObject(LdapOperationInterface $operation)
{
if (!$this->logger) {
return null;
}
return (new LogOperation($operation))->setDomain($this->connection->getConfig()->getDomainName());
} | [
"protected",
"function",
"getLogObject",
"(",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"logger",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"new",
"LogOperation",
"(",
"$",
"operation",
")",
")",
... | Construct the LogOperation object for the operation.
@param LdapOperationInterface $operation
@return LogOperation|null | [
"Construct",
"the",
"LogOperation",
"object",
"for",
"the",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L111-L118 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.getOperationHandler | protected function getOperationHandler(LdapOperationInterface $operation)
{
foreach ($this->handler as $handler) {
if ($handler->supports($operation)) {
$handler->setConnection($this->connection);
$handler->setEventDispatcher($this->dispatcher);
return $handler;
}
}
throw new LdapConnectionException(sprintf(
'Operation "%s" with a class name "%s" does not have a supported operation handler.',
$operation->getName(),
get_class($operation)
));
} | php | protected function getOperationHandler(LdapOperationInterface $operation)
{
foreach ($this->handler as $handler) {
if ($handler->supports($operation)) {
$handler->setConnection($this->connection);
$handler->setEventDispatcher($this->dispatcher);
return $handler;
}
}
throw new LdapConnectionException(sprintf(
'Operation "%s" with a class name "%s" does not have a supported operation handler.',
$operation->getName(),
get_class($operation)
));
} | [
"protected",
"function",
"getOperationHandler",
"(",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handler",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"handler",
"->",
"supports",
"(",
"$",
"operation",
")",
... | Find and return a supported handler for the operation.
@param LdapOperationInterface $operation
@return \LdapTools\Operation\Handler\OperationHandlerInterface
@throws LdapConnectionException | [
"Find",
"and",
"return",
"a",
"supported",
"handler",
"for",
"the",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L127-L143 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.cacheResultIfNeeded | protected function cacheResultIfNeeded(LdapOperationInterface $operation, $result, $usedCache, $cacheKey)
{
if (!is_null($cacheKey) && !$usedCache) {
/** @var CacheableOperationInterface $operation */
$this->cache->set(new CacheItem($cacheKey, $result, $operation->getExpireCacheAt()));
}
return $result;
} | php | protected function cacheResultIfNeeded(LdapOperationInterface $operation, $result, $usedCache, $cacheKey)
{
if (!is_null($cacheKey) && !$usedCache) {
/** @var CacheableOperationInterface $operation */
$this->cache->set(new CacheItem($cacheKey, $result, $operation->getExpireCacheAt()));
}
return $result;
} | [
"protected",
"function",
"cacheResultIfNeeded",
"(",
"LdapOperationInterface",
"$",
"operation",
",",
"$",
"result",
",",
"$",
"usedCache",
",",
"$",
"cacheKey",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"cacheKey",
")",
"&&",
"!",
"$",
"usedCache",
"... | Cache the result of the operation if needed.
@param LdapOperationInterface $operation
@param mixed $result
@param bool $usedCache
@param string|null $cacheKey
@return mixed | [
"Cache",
"the",
"result",
"of",
"the",
"operation",
"if",
"needed",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L200-L208 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.switchServerIfNeeded | protected function switchServerIfNeeded($currentServer, $wantedServer, LdapOperationInterface $operation)
{
if ($operation instanceof AuthenticationOperation || MBString::strtolower($currentServer) == MBString::strtolower($wantedServer)) {
return;
}
if ($this->connection->isBound()) {
$this->connection->close();
}
$this->connection->connect(null, null, false, $wantedServer);
} | php | protected function switchServerIfNeeded($currentServer, $wantedServer, LdapOperationInterface $operation)
{
if ($operation instanceof AuthenticationOperation || MBString::strtolower($currentServer) == MBString::strtolower($wantedServer)) {
return;
}
if ($this->connection->isBound()) {
$this->connection->close();
}
$this->connection->connect(null, null, false, $wantedServer);
} | [
"protected",
"function",
"switchServerIfNeeded",
"(",
"$",
"currentServer",
",",
"$",
"wantedServer",
",",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"operation",
"instanceof",
"AuthenticationOperation",
"||",
"MBString",
"::",
"strtolower",... | Performs the logic for switching the LDAP server connection.
@param string|null $currentServer The server we are currently on.
@param string|null $wantedServer The server we want the connection to be on.
@param LdapOperationInterface $operation | [
"Performs",
"the",
"logic",
"for",
"switching",
"the",
"LDAP",
"server",
"connection",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L226-L235 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.idleReconnectIfNeeded | protected function idleReconnectIfNeeded(LdapOperationInterface $operation)
{
// An auth operation will force a reconnect anyways, so avoid extra work
if (!$this->connection->getConfig()->getIdleReconnect() || $operation instanceof AuthenticationOperation) {
return;
}
if ($this->connection->getIdleTime() >= $this->connection->getConfig()->getIdleReconnect()) {
$this->connection->close()->connect();
}
} | php | protected function idleReconnectIfNeeded(LdapOperationInterface $operation)
{
// An auth operation will force a reconnect anyways, so avoid extra work
if (!$this->connection->getConfig()->getIdleReconnect() || $operation instanceof AuthenticationOperation) {
return;
}
if ($this->connection->getIdleTime() >= $this->connection->getConfig()->getIdleReconnect()) {
$this->connection->close()->connect();
}
} | [
"protected",
"function",
"idleReconnectIfNeeded",
"(",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"// An auth operation will force a reconnect anyways, so avoid extra work",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
"->",
"getConfig",
"(",
")",
"->",
"ge... | If the connection has been open as long as, or longer than, the configured idle reconnect time, then close and
reconnect the LDAP connection.
@param LdapOperationInterface $operation | [
"If",
"the",
"connection",
"has",
"been",
"open",
"as",
"long",
"as",
"or",
"longer",
"than",
"the",
"configured",
"idle",
"reconnect",
"time",
"then",
"close",
"and",
"reconnect",
"the",
"LDAP",
"connection",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L243-L253 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.setLdapControls | protected function setLdapControls(LdapOperationInterface $operation)
{
foreach ($operation->getControls() as $control) {
$this->connection->setControl($control);
}
} | php | protected function setLdapControls(LdapOperationInterface $operation)
{
foreach ($operation->getControls() as $control) {
$this->connection->setControl($control);
}
} | [
"protected",
"function",
"setLdapControls",
"(",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"foreach",
"(",
"$",
"operation",
"->",
"getControls",
"(",
")",
"as",
"$",
"control",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"setControl",
"(",
... | Set any specific LDAP controls for this operation.
@param LdapOperationInterface $operation | [
"Set",
"any",
"specific",
"LDAP",
"controls",
"for",
"this",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L283-L288 | train |
ldaptools/ldaptools | src/LdapTools/Operation/Invoker/LdapOperationInvoker.php | LdapOperationInvoker.resetLdapControls | protected function resetLdapControls(LdapOperationInterface $operation)
{
foreach ($operation->getControls() as $control) {
$value = $control->getValue();
$control->setValue($control->getResetValue());
$this->connection->setControl($control);
$control->setValue($value);
}
} | php | protected function resetLdapControls(LdapOperationInterface $operation)
{
foreach ($operation->getControls() as $control) {
$value = $control->getValue();
$control->setValue($control->getResetValue());
$this->connection->setControl($control);
$control->setValue($value);
}
} | [
"protected",
"function",
"resetLdapControls",
"(",
"LdapOperationInterface",
"$",
"operation",
")",
"{",
"foreach",
"(",
"$",
"operation",
"->",
"getControls",
"(",
")",
"as",
"$",
"control",
")",
"{",
"$",
"value",
"=",
"$",
"control",
"->",
"getValue",
"("... | Reset any specific LDAP controls used with this operation. This is to make sure they are not accidentally used in
future operations when it is not expected.
@param LdapOperationInterface $operation | [
"Reset",
"any",
"specific",
"LDAP",
"controls",
"used",
"with",
"this",
"operation",
".",
"This",
"is",
"to",
"make",
"sure",
"they",
"are",
"not",
"accidentally",
"used",
"in",
"future",
"operations",
"when",
"it",
"is",
"not",
"expected",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Operation/Invoker/LdapOperationInvoker.php#L296-L304 | train |
ldaptools/ldaptools | src/LdapTools/Object/LdapObjectRepository.php | LdapObjectRepository.buildLdapQuery | public function buildLdapQuery()
{
$lqb = new LdapQueryBuilder($this->ldap);
if (!empty($this->attributes)) {
$lqb->select($this->attributes);
}
return $lqb->from($this->schema);
} | php | public function buildLdapQuery()
{
$lqb = new LdapQueryBuilder($this->ldap);
if (!empty($this->attributes)) {
$lqb->select($this->attributes);
}
return $lqb->from($this->schema);
} | [
"public",
"function",
"buildLdapQuery",
"(",
")",
"{",
"$",
"lqb",
"=",
"new",
"LdapQueryBuilder",
"(",
"$",
"this",
"->",
"ldap",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"attributes",
")",
")",
"{",
"$",
"lqb",
"->",
"select",
"... | Get the LdapQueryBuilder with the defaults for this repository type.
@return LdapQueryBuilder | [
"Get",
"the",
"LdapQueryBuilder",
"with",
"the",
"defaults",
"for",
"this",
"repository",
"type",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Object/LdapObjectRepository.php#L120-L129 | train |
ldaptools/ldaptools | src/LdapTools/Connection/LdapConnection.php | LdapConnection.initiateLdapConnection | protected function initiateLdapConnection($server = null)
{
list($ldapUrl, $server) = $this->getLdapUrl($server);
$this->connection = @ldap_connect($ldapUrl);
if (!$this->connection) {
throw new LdapConnectionException(
sprintf("Failed to initiate LDAP connection with URI: %s", $ldapUrl)
);
}
foreach ($this->config->getLdapOptions() as $option => $value) {
if (!ldap_set_option($this->connection, $option, $value)) {
throw new LdapConnectionException("Failed to set LDAP connection option.");
}
}
if ($this->config->getUseTls() && !@ldap_start_tls($this->connection)) {
throw new LdapConnectionException(
sprintf("Failed to start TLS: %s", $this->getLastError()),
$this->getExtendedErrorNumber()
);
}
$this->server = $server;
} | php | protected function initiateLdapConnection($server = null)
{
list($ldapUrl, $server) = $this->getLdapUrl($server);
$this->connection = @ldap_connect($ldapUrl);
if (!$this->connection) {
throw new LdapConnectionException(
sprintf("Failed to initiate LDAP connection with URI: %s", $ldapUrl)
);
}
foreach ($this->config->getLdapOptions() as $option => $value) {
if (!ldap_set_option($this->connection, $option, $value)) {
throw new LdapConnectionException("Failed to set LDAP connection option.");
}
}
if ($this->config->getUseTls() && !@ldap_start_tls($this->connection)) {
throw new LdapConnectionException(
sprintf("Failed to start TLS: %s", $this->getLastError()),
$this->getExtendedErrorNumber()
);
}
$this->server = $server;
} | [
"protected",
"function",
"initiateLdapConnection",
"(",
"$",
"server",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"ldapUrl",
",",
"$",
"server",
")",
"=",
"$",
"this",
"->",
"getLdapUrl",
"(",
"$",
"server",
")",
";",
"$",
"this",
"->",
"connection",
"="... | Makes the initial connection to LDAP, sets connection options, and starts TLS if specified.
@param null|string $server
@throws LdapConnectionException | [
"Makes",
"the",
"initial",
"connection",
"to",
"LDAP",
"sets",
"connection",
"options",
"and",
"starts",
"TLS",
"if",
"specified",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/LdapConnection.php#L270-L295 | train |
ldaptools/ldaptools | src/LdapTools/Connection/LdapConnection.php | LdapConnection.bind | protected function bind($username, $password, $anonymous = false)
{
if ($anonymous) {
$this->isBound = @ldap_bind($this->connection);
} else {
$this->isBound = @ldap_bind(
$this->connection,
LdapUtilities::encode($username, $this->config->getEncoding()),
LdapUtilities::encode($password, $this->config->getEncoding())
);
}
if (!$this->isBound) {
throw new LdapBindException(
sprintf('Unable to bind to LDAP: %s', $this->getLastError()),
$this->getExtendedErrorNumber()
);
}
} | php | protected function bind($username, $password, $anonymous = false)
{
if ($anonymous) {
$this->isBound = @ldap_bind($this->connection);
} else {
$this->isBound = @ldap_bind(
$this->connection,
LdapUtilities::encode($username, $this->config->getEncoding()),
LdapUtilities::encode($password, $this->config->getEncoding())
);
}
if (!$this->isBound) {
throw new LdapBindException(
sprintf('Unable to bind to LDAP: %s', $this->getLastError()),
$this->getExtendedErrorNumber()
);
}
} | [
"protected",
"function",
"bind",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"anonymous",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"anonymous",
")",
"{",
"$",
"this",
"->",
"isBound",
"=",
"@",
"ldap_bind",
"(",
"$",
"this",
"->",
"connectio... | Binds to LDAP with the supplied credentials or anonymously if specified.
@param string $username The username to bind with.
@param string $password The password to bind with.
@param bool $anonymous Whether this is an anonymous bind attempt.
@throws LdapBindException | [
"Binds",
"to",
"LDAP",
"with",
"the",
"supplied",
"credentials",
"or",
"anonymously",
"if",
"specified",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/LdapConnection.php#L305-L323 | train |
ldaptools/ldaptools | src/LdapTools/Connection/LdapConnection.php | LdapConnection.getLdapUrl | protected function getLdapUrl($server = null)
{
$server = $server ?: $this->serverPool->getServer();
$ldapUrl = ($this->config->getUseSsl() ? 'ldaps' : 'ldap').'://'.$server.':'.$this->config->getPort();
return [$ldapUrl, $server];
} | php | protected function getLdapUrl($server = null)
{
$server = $server ?: $this->serverPool->getServer();
$ldapUrl = ($this->config->getUseSsl() ? 'ldaps' : 'ldap').'://'.$server.':'.$this->config->getPort();
return [$ldapUrl, $server];
} | [
"protected",
"function",
"getLdapUrl",
"(",
"$",
"server",
"=",
"null",
")",
"{",
"$",
"server",
"=",
"$",
"server",
"?",
":",
"$",
"this",
"->",
"serverPool",
"->",
"getServer",
"(",
")",
";",
"$",
"ldapUrl",
"=",
"(",
"$",
"this",
"->",
"config",
... | Get the LDAP URL to connect to.
@param null|string $server
@return string[]
@throws LdapConnectionException | [
"Get",
"the",
"LDAP",
"URL",
"to",
"connect",
"to",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/LdapConnection.php#L332-L338 | train |
ldaptools/ldaptools | src/LdapTools/Connection/LdapConnection.php | LdapConnection.setupOperationInvoker | protected function setupOperationInvoker()
{
$this->config->getOperationInvoker()->setEventDispatcher($this->dispatcher);
$this->config->getOperationInvoker()->setConnection($this);
if ($this->logger) {
$this->config->getOperationInvoker()->setLogger($this->logger);
}
if ($this->cache) {
$this->config->getOperationInvoker()->setCache($this->cache);
}
} | php | protected function setupOperationInvoker()
{
$this->config->getOperationInvoker()->setEventDispatcher($this->dispatcher);
$this->config->getOperationInvoker()->setConnection($this);
if ($this->logger) {
$this->config->getOperationInvoker()->setLogger($this->logger);
}
if ($this->cache) {
$this->config->getOperationInvoker()->setCache($this->cache);
}
} | [
"protected",
"function",
"setupOperationInvoker",
"(",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"getOperationInvoker",
"(",
")",
"->",
"setEventDispatcher",
"(",
"$",
"this",
"->",
"dispatcher",
")",
";",
"$",
"this",
"->",
"config",
"->",
"getOperationInv... | Sets the needed objects on the operation invoker. | [
"Sets",
"the",
"needed",
"objects",
"on",
"the",
"operation",
"invoker",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Connection/LdapConnection.php#L343-L353 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.getInstance | public static function getInstance(LdapObjectSchema $schema = null, $values, $type)
{
$instance = AttributeValueResolver::class;
if ($values instanceof BatchCollection) {
$instance = BatchValueResolver::class;
} elseif ($values instanceof OperatorCollection) {
$instance = OperatorValueResolver::class;
}
return new $instance($schema, $values, $type);
} | php | public static function getInstance(LdapObjectSchema $schema = null, $values, $type)
{
$instance = AttributeValueResolver::class;
if ($values instanceof BatchCollection) {
$instance = BatchValueResolver::class;
} elseif ($values instanceof OperatorCollection) {
$instance = OperatorValueResolver::class;
}
return new $instance($schema, $values, $type);
} | [
"public",
"static",
"function",
"getInstance",
"(",
"LdapObjectSchema",
"$",
"schema",
"=",
"null",
",",
"$",
"values",
",",
"$",
"type",
")",
"{",
"$",
"instance",
"=",
"AttributeValueResolver",
"::",
"class",
";",
"if",
"(",
"$",
"values",
"instanceof",
... | Factory method for instantiation.
@param LdapObjectSchema|null $schema
@param BatchCollection|OperatorCollection|array $values
@param int $type
@return AttributeValueResolver|BatchValueResolver | [
"Factory",
"method",
"for",
"instantiation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L123-L134 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.getConvertedValues | protected function getConvertedValues($values, $attribute, $direction, AttributeConverterInterface $aggregate = null)
{
$values = is_array($values) ? $values : [$values];
$converter = $this->getConverterWithOptions($this->schema->getConverter($attribute), $attribute);
if (!$aggregate && $converter->getShouldAggregateValues() && $direction == 'toLdap') {
$values = $this->convertAggregateValues($attribute, $values);
} else {
$values = $this->doConvertValues($attribute, $values, $direction, $aggregate);
}
return $values;
} | php | protected function getConvertedValues($values, $attribute, $direction, AttributeConverterInterface $aggregate = null)
{
$values = is_array($values) ? $values : [$values];
$converter = $this->getConverterWithOptions($this->schema->getConverter($attribute), $attribute);
if (!$aggregate && $converter->getShouldAggregateValues() && $direction == 'toLdap') {
$values = $this->convertAggregateValues($attribute, $values);
} else {
$values = $this->doConvertValues($attribute, $values, $direction, $aggregate);
}
return $values;
} | [
"protected",
"function",
"getConvertedValues",
"(",
"$",
"values",
",",
"$",
"attribute",
",",
"$",
"direction",
",",
"AttributeConverterInterface",
"$",
"aggregate",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"is_array",
"(",
"$",
"values",
")",
"?",
"$",
... | Get the values for an attribute after applying any converters.
@param mixed $values
@param string $attribute
@param string $direction
@param AttributeConverterInterface|null $aggregate
@return array | [
"Get",
"the",
"values",
"for",
"an",
"attribute",
"after",
"applying",
"any",
"converters",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L145-L157 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.convertAggregateValues | protected function convertAggregateValues($attribute, array $values)
{
$this->aggregated[] = $attribute;
$converterName = $this->schema->getConverter($attribute);
$toAggregate = array_keys($this->schema->getConverterMap(), $converterName);
/**
* Only aggregate values going back the same LDAP attribute, as it's possible for the a converter to have many
* different attributes assigned to it.
*
* @todo Probably a better way to do this...
*/
$aggregateToLdap = $this->schema->getAttributeToLdap($attribute);
foreach ($toAggregate as $i => $aggregate) {
if ($this->schema->getAttributeToLdap($aggregate) !== $aggregateToLdap) {
unset($toAggregate[$i]);
}
}
$values = $this->iterateAggregates($toAggregate, $values, $converterName);
return is_array($values) ? $values : [$values];
} | php | protected function convertAggregateValues($attribute, array $values)
{
$this->aggregated[] = $attribute;
$converterName = $this->schema->getConverter($attribute);
$toAggregate = array_keys($this->schema->getConverterMap(), $converterName);
/**
* Only aggregate values going back the same LDAP attribute, as it's possible for the a converter to have many
* different attributes assigned to it.
*
* @todo Probably a better way to do this...
*/
$aggregateToLdap = $this->schema->getAttributeToLdap($attribute);
foreach ($toAggregate as $i => $aggregate) {
if ($this->schema->getAttributeToLdap($aggregate) !== $aggregateToLdap) {
unset($toAggregate[$i]);
}
}
$values = $this->iterateAggregates($toAggregate, $values, $converterName);
return is_array($values) ? $values : [$values];
} | [
"protected",
"function",
"convertAggregateValues",
"(",
"$",
"attribute",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"aggregated",
"[",
"]",
"=",
"$",
"attribute",
";",
"$",
"converterName",
"=",
"$",
"this",
"->",
"schema",
"->",
"getConver... | Loops through all the attributes that are to be aggregated into a single attribute for a specific converter.
@param string $attribute
@param array $values
@return array | [
"Loops",
"through",
"all",
"the",
"attributes",
"that",
"are",
"to",
"be",
"aggregated",
"into",
"a",
"single",
"attribute",
"for",
"a",
"specific",
"converter",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L166-L187 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.getConverterWithOptions | protected function getConverterWithOptions($converterName, $attribute)
{
$converter = AttributeConverterFactory::get($converterName);
$converter->setOptions(array_merge(
$this->schema->getConverterOptions($converterName, '_default'),
$this->schema->getConverterOptions($converterName, $attribute)
));
$converter->setOperationType($this->type);
$converter->setLdapConnection($this->connection);
$converter->setDn($this->dn);
if ($converter instanceof OperationGeneratorInterface) {
$converter->setOperation($this->operation);
}
return $converter;
} | php | protected function getConverterWithOptions($converterName, $attribute)
{
$converter = AttributeConverterFactory::get($converterName);
$converter->setOptions(array_merge(
$this->schema->getConverterOptions($converterName, '_default'),
$this->schema->getConverterOptions($converterName, $attribute)
));
$converter->setOperationType($this->type);
$converter->setLdapConnection($this->connection);
$converter->setDn($this->dn);
if ($converter instanceof OperationGeneratorInterface) {
$converter->setOperation($this->operation);
}
return $converter;
} | [
"protected",
"function",
"getConverterWithOptions",
"(",
"$",
"converterName",
",",
"$",
"attribute",
")",
"{",
"$",
"converter",
"=",
"AttributeConverterFactory",
"::",
"get",
"(",
"$",
"converterName",
")",
";",
"$",
"converter",
"->",
"setOptions",
"(",
"arra... | Get an instance of a converter with its options set.
@param string $converterName The name of the converter from the schema.
@param string $attribute The name of the attribute.
@return AttributeConverterInterface | [
"Get",
"an",
"instance",
"of",
"a",
"converter",
"with",
"its",
"options",
"set",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L196-L212 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.doConvertValues | protected function doConvertValues($attribute, array $values, $direction, AttributeConverterInterface $aggregate = null)
{
$converter = $aggregate ?: $this->getConverterWithOptions($this->schema->getConverter($attribute), $attribute);
$converter->setAttribute($attribute);
if ($converter->isMultiValuedConverter()) {
$values = $converter->$direction($values);
} else {
foreach ($values as $index => $value) {
$values[$index] = $converter->$direction($value);
}
}
if ($converter instanceof OperationGeneratorInterface && $converter->getRemoveOriginalValue() && !in_array($attribute, $this->remove)) {
$this->remove[] = $attribute;
}
return $values;
} | php | protected function doConvertValues($attribute, array $values, $direction, AttributeConverterInterface $aggregate = null)
{
$converter = $aggregate ?: $this->getConverterWithOptions($this->schema->getConverter($attribute), $attribute);
$converter->setAttribute($attribute);
if ($converter->isMultiValuedConverter()) {
$values = $converter->$direction($values);
} else {
foreach ($values as $index => $value) {
$values[$index] = $converter->$direction($value);
}
}
if ($converter instanceof OperationGeneratorInterface && $converter->getRemoveOriginalValue() && !in_array($attribute, $this->remove)) {
$this->remove[] = $attribute;
}
return $values;
} | [
"protected",
"function",
"doConvertValues",
"(",
"$",
"attribute",
",",
"array",
"$",
"values",
",",
"$",
"direction",
",",
"AttributeConverterInterface",
"$",
"aggregate",
"=",
"null",
")",
"{",
"$",
"converter",
"=",
"$",
"aggregate",
"?",
":",
"$",
"this"... | Convert a set of values for an attribute.
@param string $attribute
@param array $values
@param string $direction
@param AttributeConverterInterface|null $aggregate
@return mixed | [
"Convert",
"a",
"set",
"of",
"values",
"for",
"an",
"attribute",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L223-L240 | train |
ldaptools/ldaptools | src/LdapTools/Resolver/BaseValueResolver.php | BaseValueResolver.encodeValues | protected function encodeValues($values)
{
if (is_null($this->connection) || $this->type == AttributeConverterInterface::TYPE_SEARCH_FROM) {
return $values;
}
$encoded = is_array($values) ? $values : [$values];
foreach ($encoded as $index => $value) {
if (is_string($value)) {
$encoded[$index] = LdapUtilities::encode($value, $this->connection->getConfig()->getEncoding());
}
}
// This is to pass it back the same way it was received. ldap_modify_batch is picky about values being an array.
return is_array($values) ? $encoded : reset($encoded);
} | php | protected function encodeValues($values)
{
if (is_null($this->connection) || $this->type == AttributeConverterInterface::TYPE_SEARCH_FROM) {
return $values;
}
$encoded = is_array($values) ? $values : [$values];
foreach ($encoded as $index => $value) {
if (is_string($value)) {
$encoded[$index] = LdapUtilities::encode($value, $this->connection->getConfig()->getEncoding());
}
}
// This is to pass it back the same way it was received. ldap_modify_batch is picky about values being an array.
return is_array($values) ? $encoded : reset($encoded);
} | [
"protected",
"function",
"encodeValues",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"connection",
")",
"||",
"$",
"this",
"->",
"type",
"==",
"AttributeConverterInterface",
"::",
"TYPE_SEARCH_FROM",
")",
"{",
"return",
"$",
... | Encodes any values with the needed type for LDAP.
@param array|string $values
@return array | [
"Encodes",
"any",
"values",
"with",
"the",
"needed",
"type",
"for",
"LDAP",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Resolver/BaseValueResolver.php#L248-L263 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.escapeValue | public static function escapeValue($value, $ignore = null, $flags = null)
{
// If this is a hexadecimal escaped string, then do not escape it.
$value = preg_match('/^(\\\[0-9a-fA-F]{2})+$/', (string) $value) ? $value : ldap_escape($value, $ignore, $flags);
// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
if ((int)$flags & LDAP_ESCAPE_DN) {
if (!empty($value) && $value[0] === ' ') {
$value = '\\20' . substr($value, 1);
}
if (!empty($value) && $value[strlen($value) - 1] === ' ') {
$value = substr($value, 0, -1) . '\\20';
}
// Only carriage returns seem to be valid, not line feeds (per testing of AD anyway).
$value = str_replace("\r", '\0d', $value);
}
return $value;
} | php | public static function escapeValue($value, $ignore = null, $flags = null)
{
// If this is a hexadecimal escaped string, then do not escape it.
$value = preg_match('/^(\\\[0-9a-fA-F]{2})+$/', (string) $value) ? $value : ldap_escape($value, $ignore, $flags);
// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
if ((int)$flags & LDAP_ESCAPE_DN) {
if (!empty($value) && $value[0] === ' ') {
$value = '\\20' . substr($value, 1);
}
if (!empty($value) && $value[strlen($value) - 1] === ' ') {
$value = substr($value, 0, -1) . '\\20';
}
// Only carriage returns seem to be valid, not line feeds (per testing of AD anyway).
$value = str_replace("\r", '\0d', $value);
}
return $value;
} | [
"public",
"static",
"function",
"escapeValue",
"(",
"$",
"value",
",",
"$",
"ignore",
"=",
"null",
",",
"$",
"flags",
"=",
"null",
")",
"{",
"// If this is a hexadecimal escaped string, then do not escape it.",
"$",
"value",
"=",
"preg_match",
"(",
"'/^(\\\\\\[0-9a-... | Escape any special characters for LDAP to their hexadecimal representation.
@param mixed $value The value to escape.
@param null|string $ignore The characters to ignore.
@param null|int $flags The context for the escaped string. LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN.
@return string The escaped value. | [
"Escape",
"any",
"special",
"characters",
"for",
"LDAP",
"to",
"their",
"hexadecimal",
"representation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L79-L97 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.unescapeValue | public static function unescapeValue($value)
{
$callback = function ($matches) {
return chr(hexdec($matches[1]));
};
return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', $callback, $value);
} | php | public static function unescapeValue($value)
{
$callback = function ($matches) {
return chr(hexdec($matches[1]));
};
return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', $callback, $value);
} | [
"public",
"static",
"function",
"unescapeValue",
"(",
"$",
"value",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"chr",
"(",
"hexdec",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
";",
"}",
";",
"return",
"p... | Un-escapes a value from its hexadecimal form back to its string representation.
@param string $value
@return string | [
"Un",
"-",
"escapes",
"a",
"value",
"from",
"its",
"hexadecimal",
"form",
"back",
"to",
"its",
"string",
"representation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L105-L112 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.explodeDn | public static function explodeDn($dn, $withAttributes = 1)
{
$pieces = ldap_explode_dn($dn, $withAttributes);
if ($pieces === false || !isset($pieces['count']) || $pieces['count'] == 0) {
throw new InvalidArgumentException(sprintf('Unable to parse DN "%s".', $dn));
}
for ($i = 0; $i < $pieces['count']; $i++) {
$pieces[$i] = self::unescapeValue($pieces[$i]);
}
unset($pieces['count']);
return $pieces;
} | php | public static function explodeDn($dn, $withAttributes = 1)
{
$pieces = ldap_explode_dn($dn, $withAttributes);
if ($pieces === false || !isset($pieces['count']) || $pieces['count'] == 0) {
throw new InvalidArgumentException(sprintf('Unable to parse DN "%s".', $dn));
}
for ($i = 0; $i < $pieces['count']; $i++) {
$pieces[$i] = self::unescapeValue($pieces[$i]);
}
unset($pieces['count']);
return $pieces;
} | [
"public",
"static",
"function",
"explodeDn",
"(",
"$",
"dn",
",",
"$",
"withAttributes",
"=",
"1",
")",
"{",
"$",
"pieces",
"=",
"ldap_explode_dn",
"(",
"$",
"dn",
",",
"$",
"withAttributes",
")",
";",
"if",
"(",
"$",
"pieces",
"===",
"false",
"||",
... | Converts a string distinguished name into its separate pieces.
@param string $dn
@param int $withAttributes Set to 0 to get the attribute names along with the value.
@return array | [
"Converts",
"a",
"string",
"distinguished",
"name",
"into",
"its",
"separate",
"pieces",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L121-L134 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.explodeExchangeLegacyDn | public static function explodeExchangeLegacyDn($dn, $withAttributes = false)
{
preg_match(self::MATCH_LEGACY_DN, $dn, $matches);
if (!isset($matches[2])) {
throw new InvalidArgumentException(sprintf('Unable to parse legacy exchange dn "%s".', $dn));
}
$pieces = [];
for ($i = 3; $i < count($matches); $i += 3) {
$pieces[] = $withAttributes ? $matches[$i - 1].'='.$matches[$i] : $matches[$i];
}
return $pieces;
} | php | public static function explodeExchangeLegacyDn($dn, $withAttributes = false)
{
preg_match(self::MATCH_LEGACY_DN, $dn, $matches);
if (!isset($matches[2])) {
throw new InvalidArgumentException(sprintf('Unable to parse legacy exchange dn "%s".', $dn));
}
$pieces = [];
for ($i = 3; $i < count($matches); $i += 3) {
$pieces[] = $withAttributes ? $matches[$i - 1].'='.$matches[$i] : $matches[$i];
}
return $pieces;
} | [
"public",
"static",
"function",
"explodeExchangeLegacyDn",
"(",
"$",
"dn",
",",
"$",
"withAttributes",
"=",
"false",
")",
"{",
"preg_match",
"(",
"self",
"::",
"MATCH_LEGACY_DN",
",",
"$",
"dn",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"isset",
"("... | Converts an Exchange Legacy DN into its separate pieces.
@param string $dn
@param bool $withAttributes
@return array | [
"Converts",
"an",
"Exchange",
"Legacy",
"DN",
"into",
"its",
"separate",
"pieces",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L163-L176 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.encode | public static function encode($value, $toEncoding)
{
// If the encoding is already UTF-8, and that's what was requested, then just send the value back.
if ($toEncoding == 'UTF-8' && self::isBinary($value)) {
return $value;
}
if (function_exists('mb_detect_encoding')) {
$value = iconv(mb_detect_encoding($value, mb_detect_order(), true), $toEncoding, $value);
} else {
// How else to better handle if they don't have mb_* ? The below is definitely not an optimal solution.
$value = utf8_encode($value);
}
return $value;
} | php | public static function encode($value, $toEncoding)
{
// If the encoding is already UTF-8, and that's what was requested, then just send the value back.
if ($toEncoding == 'UTF-8' && self::isBinary($value)) {
return $value;
}
if (function_exists('mb_detect_encoding')) {
$value = iconv(mb_detect_encoding($value, mb_detect_order(), true), $toEncoding, $value);
} else {
// How else to better handle if they don't have mb_* ? The below is definitely not an optimal solution.
$value = utf8_encode($value);
}
return $value;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"value",
",",
"$",
"toEncoding",
")",
"{",
"// If the encoding is already UTF-8, and that's what was requested, then just send the value back.",
"if",
"(",
"$",
"toEncoding",
"==",
"'UTF-8'",
"&&",
"self",
"::",
"isBinar... | Encode a string for LDAP with a specific encoding type.
@param string $value The value to encode.
@param string $toEncoding The encoding type to use (ie. UTF-8)
@return string The encoded value. | [
"Encode",
"a",
"string",
"for",
"LDAP",
"with",
"a",
"specific",
"encoding",
"type",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L185-L200 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.isValidAttributeFormat | public static function isValidAttributeFormat($value)
{
return (preg_match(self::MATCH_DESCRIPTOR, $value) || preg_match(self::MATCH_OID, $value));
} | php | public static function isValidAttributeFormat($value)
{
return (preg_match(self::MATCH_DESCRIPTOR, $value) || preg_match(self::MATCH_OID, $value));
} | [
"public",
"static",
"function",
"isValidAttributeFormat",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"preg_match",
"(",
"self",
"::",
"MATCH_DESCRIPTOR",
",",
"$",
"value",
")",
"||",
"preg_match",
"(",
"self",
"::",
"MATCH_OID",
",",
"$",
"value",
")",
"... | Determine whether a value is a valid attribute name or OID. The name should meet the format described in RFC 2252.
However, the regex is fairly forgiving for each.
@param string $value
@return bool | [
"Determine",
"whether",
"a",
"value",
"is",
"a",
"valid",
"attribute",
"name",
"or",
"OID",
".",
"The",
"name",
"should",
"meet",
"the",
"format",
"described",
"in",
"RFC",
"2252",
".",
"However",
"the",
"regex",
"is",
"fairly",
"forgiving",
"for",
"each",... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L222-L225 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.getLdapServersForDomain | public static function getLdapServersForDomain($domain)
{
$hosts = (new Dns())->getRecord(self::SRV_PREFIX.$domain, DNS_SRV);
return is_array($hosts) ? array_column($hosts, 'target') : [];
} | php | public static function getLdapServersForDomain($domain)
{
$hosts = (new Dns())->getRecord(self::SRV_PREFIX.$domain, DNS_SRV);
return is_array($hosts) ? array_column($hosts, 'target') : [];
} | [
"public",
"static",
"function",
"getLdapServersForDomain",
"(",
"$",
"domain",
")",
"{",
"$",
"hosts",
"=",
"(",
"new",
"Dns",
"(",
")",
")",
"->",
"getRecord",
"(",
"self",
"::",
"SRV_PREFIX",
".",
"$",
"domain",
",",
"DNS_SRV",
")",
";",
"return",
"i... | Get an array of all the LDAP servers for a domain by querying DNS.
@param string $domain The domain name to query.
@return string[] | [
"Get",
"an",
"array",
"of",
"all",
"the",
"LDAP",
"servers",
"for",
"a",
"domain",
"by",
"querying",
"DNS",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L322-L327 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.getLdapSslCertificates | public static function getLdapSslCertificates($server, $port = 389)
{
// This is the hex encoded extendedRequest for the STARTTLS operation...
$startTls = hex2bin("301d02010177188016312e332e362e312e342e312e313436362e3230303337");
$certificates = [
'peer_certificate' => '',
'peer_certificate_chain' => [],
];
$tcpSocket = new TcpSocket([
'ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$tcpSocket->connect($server, $port, 5);
$tcpSocket->setOperationTimeout(2);
$tcpSocket->write($startTls);
$tcpSocket->read(10240);
$tcpSocket->enableEncryption(STREAM_CRYPTO_METHOD_TLS_CLIENT);
$info = $tcpSocket->getParams();
if (!$info) {
return $certificates;
}
openssl_x509_export($info['options']['ssl']['peer_certificate'], $certificates['peer_certificate']);
foreach ($info['options']['ssl']['peer_certificate_chain'] as $cert) {
$certChain = '';
openssl_x509_export($cert, $certChain);
$certificates['peer_certificate_chain'][] = $certChain;
}
$tcpSocket->close();
return $certificates;
} | php | public static function getLdapSslCertificates($server, $port = 389)
{
// This is the hex encoded extendedRequest for the STARTTLS operation...
$startTls = hex2bin("301d02010177188016312e332e362e312e342e312e313436362e3230303337");
$certificates = [
'peer_certificate' => '',
'peer_certificate_chain' => [],
];
$tcpSocket = new TcpSocket([
'ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$tcpSocket->connect($server, $port, 5);
$tcpSocket->setOperationTimeout(2);
$tcpSocket->write($startTls);
$tcpSocket->read(10240);
$tcpSocket->enableEncryption(STREAM_CRYPTO_METHOD_TLS_CLIENT);
$info = $tcpSocket->getParams();
if (!$info) {
return $certificates;
}
openssl_x509_export($info['options']['ssl']['peer_certificate'], $certificates['peer_certificate']);
foreach ($info['options']['ssl']['peer_certificate_chain'] as $cert) {
$certChain = '';
openssl_x509_export($cert, $certChain);
$certificates['peer_certificate_chain'][] = $certChain;
}
$tcpSocket->close();
return $certificates;
} | [
"public",
"static",
"function",
"getLdapSslCertificates",
"(",
"$",
"server",
",",
"$",
"port",
"=",
"389",
")",
"{",
"// This is the hex encoded extendedRequest for the STARTTLS operation...",
"$",
"startTls",
"=",
"hex2bin",
"(",
"\"301d02010177188016312e332e362e312e342e312... | Get an array containing the SSL certificates of the LDAP server. This runs over the standard LDAP port and
initiates a TlsStart operation.
@param string $server The server name to connect to
@param int $port The standard LDAP port
@return array In the form of ['peer_certificate' => '', 'peer_certificate_chain' => []] | [
"Get",
"an",
"array",
"containing",
"the",
"SSL",
"certificates",
"of",
"the",
"LDAP",
"server",
".",
"This",
"runs",
"over",
"the",
"standard",
"LDAP",
"port",
"and",
"initiates",
"a",
"TlsStart",
"operation",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L337-L375 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.getRdnFromDn | public static function getRdnFromDn($dn)
{
$rdn = self::explodeDn($dn, 0)[0];
$rdn = explode('=', $rdn, 2);
return $rdn[0].'='.self::escapeValue($rdn[1], null, LDAP_ESCAPE_DN);
} | php | public static function getRdnFromDn($dn)
{
$rdn = self::explodeDn($dn, 0)[0];
$rdn = explode('=', $rdn, 2);
return $rdn[0].'='.self::escapeValue($rdn[1], null, LDAP_ESCAPE_DN);
} | [
"public",
"static",
"function",
"getRdnFromDn",
"(",
"$",
"dn",
")",
"{",
"$",
"rdn",
"=",
"self",
"::",
"explodeDn",
"(",
"$",
"dn",
",",
"0",
")",
"[",
"0",
"]",
";",
"$",
"rdn",
"=",
"explode",
"(",
"'='",
",",
"$",
"rdn",
",",
"2",
")",
"... | Given a full escaped DN return the RDN in escaped form.
@param string $dn
@return string | [
"Given",
"a",
"full",
"escaped",
"DN",
"return",
"the",
"RDN",
"in",
"escaped",
"form",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L383-L389 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.getParentDn | public static function getParentDn($dn)
{
$parts = self::explodeDn($dn, 0);
if (count($parts) === 1) {
throw new InvalidArgumentException(sprintf('DN "%s" has no parent.', $dn));
}
array_shift($parts);
return self::implodeDn($parts);
} | php | public static function getParentDn($dn)
{
$parts = self::explodeDn($dn, 0);
if (count($parts) === 1) {
throw new InvalidArgumentException(sprintf('DN "%s" has no parent.', $dn));
}
array_shift($parts);
return self::implodeDn($parts);
} | [
"public",
"static",
"function",
"getParentDn",
"(",
"$",
"dn",
")",
"{",
"$",
"parts",
"=",
"self",
"::",
"explodeDn",
"(",
"$",
"dn",
",",
"0",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
"1",
")",
"{",
"throw",
"new",
"InvalidA... | Return the parent of a given DN.
@param string $dn
@return string | [
"Return",
"the",
"parent",
"of",
"a",
"given",
"DN",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L397-L406 | train |
ldaptools/ldaptools | src/LdapTools/Utilities/LdapUtilities.php | LdapUtilities.getAliasAndAttribute | public static function getAliasAndAttribute($attribute)
{
$alias = null;
if (strpos($attribute, '.') !== false) {
$pieces = explode('.', $attribute, 2);
$alias = $pieces[0];
$attribute = $pieces[1];
}
return [$alias, $attribute];
} | php | public static function getAliasAndAttribute($attribute)
{
$alias = null;
if (strpos($attribute, '.') !== false) {
$pieces = explode('.', $attribute, 2);
$alias = $pieces[0];
$attribute = $pieces[1];
}
return [$alias, $attribute];
} | [
"public",
"static",
"function",
"getAliasAndAttribute",
"(",
"$",
"attribute",
")",
"{",
"$",
"alias",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"attribute",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"'.'",
... | Given an attribute, split it between its alias and attribute. This will return an array where the first value
is the alias and the second is the attribute name. If there is no alias then the first value will be null.
ie. list($alias, $attribute) = LdapUtilities::getAliasAndAttribute($attribute);
@param string $attribute
@return array | [
"Given",
"an",
"attribute",
"split",
"it",
"between",
"its",
"alias",
"and",
"attribute",
".",
"This",
"will",
"return",
"an",
"array",
"where",
"the",
"first",
"value",
"is",
"the",
"alias",
"and",
"the",
"second",
"is",
"the",
"attribute",
"name",
".",
... | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Utilities/LdapUtilities.php#L427-L438 | train |
ldaptools/ldaptools | src/LdapTools/Security/Acl/Dacl.php | Dacl.orderAcesCanonically | protected function orderAcesCanonically()
{
$explicitDeny = [];
$explicitAllow = [];
$objectDeny = [];
$objectAllow = [];
$inherited = [];
foreach ($this->aces as $ace) {
$isDenied = $ace->isDenyAce();
$isObject = $ace->isObjectAce();
if ($ace->getFlags()->isInherited()) {
$inherited[] = $ace;
} elseif ($isDenied && $isObject) {
$objectDeny[] = $ace;
} elseif ($isDenied) {
$explicitDeny[] = $ace;
} elseif ($isObject) {
$objectAllow[] = $ace;
} else {
$explicitAllow[] = $ace;
}
}
return array_merge(
$objectDeny,
$explicitDeny,
$objectAllow,
$explicitAllow,
$inherited
);
} | php | protected function orderAcesCanonically()
{
$explicitDeny = [];
$explicitAllow = [];
$objectDeny = [];
$objectAllow = [];
$inherited = [];
foreach ($this->aces as $ace) {
$isDenied = $ace->isDenyAce();
$isObject = $ace->isObjectAce();
if ($ace->getFlags()->isInherited()) {
$inherited[] = $ace;
} elseif ($isDenied && $isObject) {
$objectDeny[] = $ace;
} elseif ($isDenied) {
$explicitDeny[] = $ace;
} elseif ($isObject) {
$objectAllow[] = $ace;
} else {
$explicitAllow[] = $ace;
}
}
return array_merge(
$objectDeny,
$explicitDeny,
$objectAllow,
$explicitAllow,
$inherited
);
} | [
"protected",
"function",
"orderAcesCanonically",
"(",
")",
"{",
"$",
"explicitDeny",
"=",
"[",
"]",
";",
"$",
"explicitAllow",
"=",
"[",
"]",
";",
"$",
"objectDeny",
"=",
"[",
"]",
";",
"$",
"objectAllow",
"=",
"[",
"]",
";",
"$",
"inherited",
"=",
"... | Returns all ACEs in canonical order as expected by AD.
@return Ace[] | [
"Returns",
"all",
"ACEs",
"in",
"canonical",
"order",
"as",
"expected",
"by",
"AD",
"."
] | b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7 | https://github.com/ldaptools/ldaptools/blob/b7a4f6df96ef83e82c7ed6238e4d0346c0f666f7/src/LdapTools/Security/Acl/Dacl.php#L105-L137 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.