11
11
12
12
namespace Symfony \Component \Ldap \Adapter \ExtLdap ;
13
13
14
+ use LDAP \Connection as LDAPConnection ;
14
15
use Symfony \Component \Ldap \Adapter \EntryManagerInterface ;
15
16
use Symfony \Component \Ldap \Entry ;
16
17
use Symfony \Component \Ldap \Exception \LdapException ;
@@ -30,6 +31,9 @@ public function __construct(Connection $connection)
30
31
$ this ->connection = $ connection ;
31
32
}
32
33
34
+ /**
35
+ * @return $this
36
+ */
33
37
public function add (Entry $ entry )
34
38
{
35
39
$ con = $ this ->getConnectionResource ();
@@ -41,27 +45,39 @@ public function add(Entry $entry)
41
45
return $ this ;
42
46
}
43
47
48
+ /**
49
+ * @return $this
50
+ */
44
51
public function update (Entry $ entry )
45
52
{
46
53
$ con = $ this ->getConnectionResource ();
47
54
48
55
if (!@ldap_modify ($ con , $ entry ->getDn (), $ entry ->getAttributes ())) {
49
56
throw new LdapException (sprintf ('Could not update entry "%s": ' , $ entry ->getDn ()).ldap_error ($ con ), ldap_errno ($ con ));
50
57
}
58
+
59
+ return $ this ;
51
60
}
52
61
62
+ /**
63
+ * @return $this
64
+ */
53
65
public function remove (Entry $ entry )
54
66
{
55
67
$ con = $ this ->getConnectionResource ();
56
68
57
69
if (!@ldap_delete ($ con , $ entry ->getDn ())) {
58
70
throw new LdapException (sprintf ('Could not remove entry "%s": ' , $ entry ->getDn ()).ldap_error ($ con ), ldap_errno ($ con ));
59
71
}
72
+
73
+ return $ this ;
60
74
}
61
75
62
76
/**
63
77
* Adds values to an entry's multi-valued attribute from the LDAP server.
64
78
*
79
+ * @return $this
80
+ *
65
81
* @throws NotBoundException
66
82
* @throws LdapException
67
83
*/
@@ -72,11 +88,15 @@ public function addAttributeValues(Entry $entry, string $attribute, array $value
72
88
if (!@ldap_mod_add ($ con , $ entry ->getDn (), [$ attribute => $ values ])) {
73
89
throw new LdapException (sprintf ('Could not add values to entry "%s", attribute "%s": ' , $ entry ->getDn (), $ attribute ).ldap_error ($ con ), ldap_errno ($ con ));
74
90
}
91
+
92
+ return $ this ;
75
93
}
76
94
77
95
/**
78
96
* Removes values from an entry's multi-valued attribute from the LDAP server.
79
97
*
98
+ * @return $this
99
+ *
80
100
* @throws NotBoundException
81
101
* @throws LdapException
82
102
*/
@@ -87,6 +107,8 @@ public function removeAttributeValues(Entry $entry, string $attribute, array $va
87
107
if (!@ldap_mod_del ($ con , $ entry ->getDn (), [$ attribute => $ values ])) {
88
108
throw new LdapException (sprintf ('Could not remove values from entry "%s", attribute "%s": ' , $ entry ->getDn (), $ attribute ).ldap_error ($ con ), ldap_errno ($ con ));
89
109
}
110
+
111
+ return $ this ;
90
112
}
91
113
92
114
public function rename (Entry $ entry , string $ newRdn , bool $ removeOldRdn = true )
@@ -96,11 +118,15 @@ public function rename(Entry $entry, string $newRdn, bool $removeOldRdn = true)
96
118
if (!@ldap_rename ($ con , $ entry ->getDn (), $ newRdn , '' , $ removeOldRdn )) {
97
119
throw new LdapException (sprintf ('Could not rename entry "%s" to "%s": ' , $ entry ->getDn (), $ newRdn ).ldap_error ($ con ), ldap_errno ($ con ));
98
120
}
121
+
122
+ return $ this ;
99
123
}
100
124
101
125
/**
102
126
* Moves an entry on the Ldap server.
103
127
*
128
+ * @return $this
129
+ *
104
130
* @throws NotBoundException if the connection has not been previously bound
105
131
* @throws LdapException if an error is thrown during the rename operation
106
132
*/
@@ -112,10 +138,14 @@ public function move(Entry $entry, string $newParent)
112
138
if (!@ldap_rename ($ con , $ entry ->getDn (), $ rdn , $ newParent , true )) {
113
139
throw new LdapException (sprintf ('Could not move entry "%s" to "%s": ' , $ entry ->getDn (), $ newParent ).ldap_error ($ con ), ldap_errno ($ con ));
114
140
}
141
+
142
+ return $ this ;
115
143
}
116
144
117
145
/**
118
146
* Get the connection resource, but first check if the connection is bound.
147
+ *
148
+ * @return resource|LDAPConnection
119
149
*/
120
150
private function getConnectionResource ()
121
151
{
@@ -130,9 +160,11 @@ private function getConnectionResource()
130
160
/**
131
161
* @param iterable<int, UpdateOperation> $operations An array or iterable of UpdateOperation instances
132
162
*
163
+ * @return $this
164
+ *
133
165
* @throws UpdateOperationException in case of an error
134
166
*/
135
- public function applyOperations (string $ dn , iterable $ operations ): void
167
+ public function applyOperations (string $ dn , iterable $ operations )
136
168
{
137
169
$ operationsMapped = [];
138
170
foreach ($ operations as $ modification ) {
@@ -143,6 +175,8 @@ public function applyOperations(string $dn, iterable $operations): void
143
175
if (!@ldap_modify_batch ($ con , $ dn , $ operationsMapped )) {
144
176
throw new UpdateOperationException (sprintf ('Error executing UpdateOperation on "%s": ' , $ dn ).ldap_error ($ con ), ldap_errno ($ con ));
145
177
}
178
+
179
+ return $ this ;
146
180
}
147
181
148
182
private function parseRdnFromEntry (Entry $ entry ): string
0 commit comments