-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[LDAP] Check whether an entry attribute exists #18492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixed bool/boolean coding standard
ping @csarrazi |
*/ | ||
public function hasAttribute($name) | ||
{ | ||
return isset($this->attributes[$name]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but we may need to check whether the value is actually null or not.
Could you try running real-world tests with some empty LDAP attributes, to see whether this behaves correctly or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a real world (though fake data) LDAP octet stream of length zero, internally the entry contains a value which is an empty PHP string. As far as I can find any non-existing attributes do not return in the entry, and null values get converted to empty strings.
Output:
// var_dump($entry)
object(Symfony\Component\Ldap\Entry)#23 (2) {
["dn":"Symfony\Component\Ldap\Entry":private]=>
string(34) "uid=john2,ou=People,dc=localdomain"
["attributes":"Symfony\Component\Ldap\Entry":private]=>
array(21) {
["objectClass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(13) "inetOrgPerson"
[1]=>
string(12) "posixAccount"
[2]=>
string(13) "shadowAccount"
}
[0]=>
string(11) "objectClass"
["uid"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "john2"
}
...
[6]=>
string(9) "gidNumber"
["gecos"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(0) ""
}
[7]=>
string(5) "gecos"
["loginShell"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "/bin/bash"
}
[8]=>
string(10) "loginShell"
["homeDirectory"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(10) "/home/john"
}
[9]=>
string(13) "homeDirectory"
["count"]=>
int(10)
}
}
// var_dump($entry->hasAttibute('gecos'))
bool(true)
// var_dump($entry->getAttribute('gecos'))
array(2) {
["count"]=>
int(1)
[0]=>
string(0) ""
}
So there should be no problem, because empty strings return an isset of true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @hiddewie. |
This PR was merged into the 3.1-dev branch. Discussion ---------- [LDAP] Check whether an entry attribute exists | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Currently a method exists for getting the value of an attribute. It would make the Entry class more complete to be able to simply test if an attribute exists in the entry. Commits ------- 56ef8a0 [LDAP] Check whether an entry attribute exists
Currently a method exists for getting the value of an attribute. It would make the Entry class more complete to be able to simply test if an attribute exists in the entry.