[LDAP] Check whether an entry attribute exists#18492
Merged
Merged
Conversation
Fixed bool/boolean coding standard
Member
|
ping @csarrazi |
| * @return bool | ||
| */ | ||
| public function hasAttribute($name) | ||
| { |
Contributor
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
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.
Member
|
Thank you @hiddewie. |
fabpot
added a commit
that referenced
this pull request
Apr 28, 2016
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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.