Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Apr 28, 2016
Merged

[LDAP] Check whether an entry attribute exists #18492

merged 1 commit into from
Apr 28, 2016

Conversation

hiddewie
Copy link
Contributor

@hiddewie hiddewie commented Apr 9, 2016

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.

Fixed bool/boolean coding standard
@fabpot
Copy link
Member

fabpot commented Apr 11, 2016

ping @csarrazi

*/
public function hasAttribute($name)
{
return isset($this->attributes[$name]);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fabpot
Copy link
Member

fabpot commented Apr 28, 2016

Thank you @hiddewie.

@fabpot fabpot merged commit 56ef8a0 into symfony:master Apr 28, 2016
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
@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants