Skip to content

Commit d15d42e

Browse files
Merge branch '6.4' into 7.0
* 6.4: fix typo Add types to private and internal properties [Workflow] Cleaning code [Scheduler] Fix NPE in debug:scheduler command
2 parents 7b0970d + c937fd5 commit d15d42e

File tree

4 files changed

+14
-51
lines changed

4 files changed

+14
-51
lines changed

Adapter/ExtLdap/Connection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class Connection extends AbstractConnection
3737
];
3838

3939
private bool $bound = false;
40-
41-
/** @var resource|LDAPConnection */
42-
private $connection;
40+
private ?LDAPConnection $connection = null;
4341

4442
public function __sleep(): array
4543
{
@@ -87,11 +85,9 @@ public function bind(string $dn = null, #[\SensitiveParameter] string $password
8785
}
8886

8987
/**
90-
* @return resource|LDAPConnection
91-
*
9288
* @internal
9389
*/
94-
public function getResource()
90+
public function getResource(): ?LDAPConnection
9591
{
9692
return $this->connection;
9793
}

Adapter/ExtLdap/EntryManager.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
class EntryManager implements EntryManagerInterface
2626
{
27-
private Connection $connection;
28-
29-
public function __construct(Connection $connection)
30-
{
31-
$this->connection = $connection;
27+
public function __construct(
28+
private Connection $connection,
29+
) {
3230
}
3331

3432
/**
@@ -135,8 +133,8 @@ public function rename(Entry $entry, string $newRdn, bool $removeOldRdn = true):
135133
*/
136134
public function move(Entry $entry, string $newParent): static
137135
{
138-
$con = $this->getConnectionResource();
139136
$rdn = $this->parseRdnFromEntry($entry);
137+
$con = $this->getConnectionResource();
140138
// deleteOldRdn does not matter here, since the Rdn will not be changing in the move.
141139
if (!@ldap_rename($con, $entry->getDn(), $rdn, $newParent, true)) {
142140
throw new LdapException(sprintf('Could not move entry "%s" to "%s": ', $entry->getDn(), $newParent).ldap_error($con), ldap_errno($con));
@@ -147,10 +145,8 @@ public function move(Entry $entry, string $newParent): static
147145

148146
/**
149147
* Get the connection resource, but first check if the connection is bound.
150-
*
151-
* @return resource|LDAPConnection
152148
*/
153-
private function getConnectionResource()
149+
private function getConnectionResource(): LDAPConnection
154150
{
155151
// If the connection is not bound, throw an exception. Users should use an explicit bind call first.
156152
if (!$this->connection->isBound()) {

Adapter/ExtLdap/Query.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Ldap\Adapter\ExtLdap;
1313

14-
use LDAP\Connection as LDAPConnection;
1514
use LDAP\Result;
1615
use Symfony\Component\Ldap\Adapter\AbstractQuery;
1716
use Symfony\Component\Ldap\Adapter\CollectionInterface;
@@ -26,7 +25,7 @@ class Query extends AbstractQuery
2625
{
2726
public const PAGINATION_OID = \LDAP_CONTROL_PAGEDRESULTS;
2827

29-
/** @var resource[]|Result[] */
28+
/** @var Result[] */
3029
private array $results;
3130

3231
private array $serverctrls = [];
@@ -99,7 +98,7 @@ public function execute(): CollectionInterface
9998
if ($pageSize > 0 && $sizeLimit >= $pageSize) {
10099
$sizeLimit = 0;
101100
}
102-
$search = $this->callSearchFunction($con, $func, $sizeLimit);
101+
$search = @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref'], $this->serverctrls);
103102

104103
if (false === $search) {
105104
$ldapError = '';
@@ -120,7 +119,9 @@ public function execute(): CollectionInterface
120119
break;
121120
}
122121
if ($pageControl) {
123-
$cookie = $this->controlPagedResultResponse($con, $search);
122+
ldap_parse_result($con, $search, $errcode, $matcheddn, $errmsg, $referrals, $controls);
123+
124+
$cookie = $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
124125
}
125126
} while (null !== $cookie && '' !== $cookie);
126127

@@ -136,19 +137,17 @@ public function execute(): CollectionInterface
136137
* Returns an LDAP search resource. If this query resulted in multiple searches, only the first
137138
* page will be returned.
138139
*
139-
* @return resource|Result|null
140-
*
141140
* @internal
142141
*/
143-
public function getResource(int $idx = 0)
142+
public function getResource(int $idx = 0): ?Result
144143
{
145144
return $this->results[$idx] ?? null;
146145
}
147146

148147
/**
149148
* Returns all LDAP search resources.
150149
*
151-
* @return resource[]|Result[]
150+
* @return Result[]
152151
*
153152
* @internal
154153
*/
@@ -206,29 +205,4 @@ private function controlPagedResult(int $pageSize, bool $critical, string $cooki
206205

207206
return true;
208207
}
209-
210-
/**
211-
* Retrieve LDAP pagination cookie.
212-
*
213-
* @param resource|LDAPConnection $con
214-
* @param resource|Result $result
215-
*/
216-
private function controlPagedResultResponse($con, $result): string
217-
{
218-
ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls);
219-
220-
return $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
221-
}
222-
223-
/**
224-
* Calls actual LDAP search function with the prepared options and parameters.
225-
*
226-
* @param resource|LDAPConnection $con
227-
*
228-
* @return resource|Result|false
229-
*/
230-
private function callSearchFunction($con, callable $func, int $sizeLimit)
231-
{
232-
return @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref'], $this->serverctrls);
233-
}
234208
}

Tests/Adapter/ExtLdap/EntryManagerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public function testMove()
2525
$this->expectException(LdapException::class);
2626
$this->expectExceptionMessage('Entry "$$$$$$" malformed, could not parse RDN.');
2727
$connection = $this->createMock(Connection::class);
28-
$connection
29-
->expects($this->once())
30-
->method('isBound')->willReturn(true);
3128

3229
$entry = new Entry('$$$$$$');
3330
$entryManager = new EntryManager($connection);

0 commit comments

Comments
 (0)