Changeset 1570 for trunk/src/main/php/net
- Timestamp:
- 05/15/08 13:22:25 (2 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPConnection.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPEntry.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPSearchResult.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPURL.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPConnection.php
r1559 r1570 24 24 * @var stubLDAPURL 25 25 */ 26 p ublic$ldap;26 protected $ldap; 27 27 /** 28 28 * ldap connection identifier … … 30 30 * @var resource 31 31 */ 32 p ublic$handle;32 protected $handle; 33 33 34 34 /** … … 94 94 public function unbind() 95 95 { 96 ldap_unbind($this->handle); 96 if(gettype($this->handle) !== 'unknown type' ) { 97 ldap_unbind($this->handle); 98 } 97 99 } 98 100 101 /** 102 * Changes the originally used base dn (distinguished name). 103 * 104 * @param string $newBaseDn 105 */ 106 public function setBaseDn($newBaseDn) 107 { 108 $this->ldap->setBaseDn($newBaseDn); 109 } 110 99 111 /** 100 112 * Retrieves the LDAP entries. … … 129 141 } 130 142 143 // TODO isParamValid() nötig? 131 144 switch($scope) { 132 145 case 'base': trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPEntry.php
r1559 r1570 18 18 * attributes 19 19 * 20 * @var array (attrName => array(v[, v ...])20 * @var array<string,array<string>> 21 21 */ 22 22 protected $attributes; … … 24 24 * objectClass attribute 25 25 * 26 * @var array (v[, v ...])26 * @var array<string> 27 27 */ 28 28 protected $objectClass; … … 70 70 71 71 /** 72 * Gets the objectClass values. 73 * 74 * @return array<string> 75 */ 76 public function getObjectClassValues() 77 { 78 return $this->objectClass; 79 } 80 81 /** 72 82 * Gets the attributes. 73 83 * 74 * @return array (k,v)84 * @return array<string,array<string>> 75 85 */ 76 86 public function getAttributes() … … 87 97 public function getAttributeValuesByName($name) 88 98 { 89 $name = strtolower($name);90 return $this->attributes[$name];99 // new ArrayAccessor 100 return (isset($this->attributes[$name]) !== false) ? $this->attributes[$name] : null; 91 101 } 92 102 … … 94 104 * Gets the attribute names. 95 105 * 96 * @return array (string)106 * @return array<string> 97 107 */ 98 108 public function getAttributeNames() trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPSearchResult.php
r1559 r1570 14 14 * @subpackage peer_ldap 15 15 */ 16 class stubLDAPSearchResult extends stubBaseObject 16 class stubLDAPSearchResult extends stubBaseObject implements Iterator 17 17 { 18 18 /** 19 * entries19 * ldap connection identifier 20 20 * 21 * @var array(stubLDAPEntry)21 * @var resource 22 22 */ 23 protected $ entries;23 protected $handle; 24 24 /** 25 * entries amount25 * ldap result identifier 26 26 * 27 * @var int27 * @var resource 28 28 */ 29 protected $entriesCount; 29 protected $result; 30 /** 31 * current ldap entryId 32 * 33 * @var ressource 34 */ 35 protected $current; 30 36 31 37 /** 32 38 * constructor (creates stubLDAPEntry objects) 39 * 40 * Unset calls remove the count value for better looping 41 * and because this value is ascertainable later. 33 42 * 34 43 * @param resource $handle ldap connection identifier … … 37 46 public function __construct($handle, $result) 38 47 { 39 $info = ldap_get_entries($handle, $result); 40 $this->entriesCount = $info['count']; 41 unset($info['count']); 42 43 foreach ($info as $numKey => $attributes) { 44 45 $entryAttr = array(); 46 foreach ($attributes as $name => $values) { 47 if($name === 'objectclass' 48 || $name === 'count' 49 || $name === 'dn' 50 || is_int($name)) { 51 continue; 52 } 53 54 unset($values['count']); 55 $entryAttr[$name] = $values; 56 } 57 58 $ldapEntry = new stubLDAPEntry( 59 $attributes['dn'], 60 $attributes['objectclass'], 61 $entryAttr, 62 $attributes['count'] 63 ); 64 65 $this->entries[$attributes['dn']] = $ldapEntry; 66 } 48 $this->handle = $handle; 49 $this->result = $result; 50 $entry = ldap_first_entry($handle, $result); 51 $this->current = ($entry !== false) ? $entry : null; 67 52 } 68 53 69 54 /** 70 * Gets an entry by dn (distinguished name).55 * Provides a stubLDAPEntry. 71 56 * 72 * @param string $dn57 * @param int $entryId ldap entry identifier 73 58 * @return stubLDAPEntry 74 59 */ 75 p ublic function getEntryByDn($dn)60 protected function provideLDAPEntry($entryId) 76 61 { 77 return $this->entries[$dn]; 62 $attributes = ldap_get_attributes($this->handle, $entryId); 63 64 $entryAttr = array(); 65 $objectClass = array(); 66 foreach ($attributes as $name => $values) { 67 // reject special attributes 68 if($name === 'count' || is_int($name)) { 69 continue; 70 } 71 72 // get rid of amount 73 if(isset($values['count'])) { 74 unset($values['count']); 75 } 76 77 // get objec class values 78 if($name === 'objectClass') { 79 $objectClass = $values; 80 continue; 81 } 82 83 // save 'normal' attributes 84 $entryAttr[$name] = $values; 85 } 86 87 $dn = ldap_get_dn($this->handle, $entryId); 88 if(empty($objectClass)) { 89 $objectClass = ldap_read($this->handle, $dn, 'objectClass=*', array('objectclass')); 90 } 91 92 $ldapEntry = new stubLDAPEntry( 93 $dn, 94 $objectClass, 95 $entryAttr, 96 $attributes['count'] 97 ); 98 99 return $ldapEntry; 78 100 } 79 101 80 102 /** 81 * Gets all entries.103 * Gets the current entry. 82 104 * 83 * @return array(stubLDAPEntry)105 * @return stubLDAPEntry 84 106 */ 85 public function getEntr ies()107 public function getEntry() 86 108 { 87 return $this->entries;109 return ($this->current !== null ? $this->provideLDAPEntry($this->current()) : null); 88 110 } 89 111 90 112 /** 91 * Gets entries amount.113 * Returns the current entry identifier. 92 114 * 93 * @return int115 * @return ressource 94 116 */ 95 public function getEntriesCount()117 public function current() 96 118 { 97 return $this->entriesCount; 119 return $this->current; 120 } 121 122 /** 123 * Returns the key of the current element. 124 * 125 * @return ressource 126 */ 127 public function key() 128 { 129 return $this->current(); 130 } 131 132 /** 133 * Moves forward to next element. 134 */ 135 public function next() 136 { 137 $this->current = ($result = ldap_next_entry($this->handle, $this->current())) ? $result : null; 138 } 139 140 /** 141 * Rewinds the Iterator to the first element. 142 */ 143 public function rewind() 144 { 145 $this->current = ldap_first_entry($this->handle, $this->result); 146 } 147 148 /** 149 * Checks if there is a current element after calls to rewind() or next(). 150 * 151 * @return boolean 152 */ 153 public function valid() 154 { 155 return ($this->current() !== null) ? true : false; 98 156 } 99 157 } trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPURL.php
r1559 r1570 10 10 * @see RFC 4514 LDAP: String Representation of Distinguished Names http://tools.ietf.org/html/rfc4514 11 11 */ 12 stubClassLoader::load('net::stubbles::peer::stubURL'); 12 stubClassLoader::load('net::stubbles::peer::stubURL', 13 'net::stubbles::peer::ldap::stubLDAPConnection' 14 ); 13 15 /** 14 16 * Entrace point for LDAP usage (via stubLDAPURL::fromString(urlString)).
