8000 [Ldap] Backport refactorings by derrabus · Pull Request #42931 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Ldap] Backport refactorings #42931

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
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class Query extends AbstractQuery
// As of PHP 7.2, we can use LDAP_CONTROL_PAGEDRESULTS instead of this
public const PAGINATION_OID = '1.2.840.113556.1.4.319';

/** @var Connection */
protected $connection;

/** @var resource[] */
private $results;

Expand Down Expand Up @@ -156,17 +153,13 @@ public function execute()
* Returns an LDAP search resource. If this query resulted in multiple searches, only the first
* page will be returned.
*
* @return resource
* @return resource|null
*
* @internal
*/
public function getResource(int $idx = 0)
{
if (null === $this->results || $idx >= \count($this->results)) {
return null;
}

return $this->results[$idx];
return $this->results[$idx] ?? null;
}

/**
Expand Down Expand Up @@ -259,9 +252,9 @@ private function controlPagedResultResponse($con, $result, string $cookie = ''):
*
* @param resource $con
*
* @return resource
* @return resource|false
*/
private function callSearchFunction($con, string $func, int $sizeLimit)
private function callSearchFunction($con, callable $func, int $sizeLimit)
{
if (\PHP_VERSION_ID < 70300) {
return @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UpdateOperation
private $values;
private $attribute;

private $validOperationTypes = [
private const VALID_OPERATION_TYPES = [
\LDAP_MODIFY_BATCH_ADD,
\LDAP_MODIFY_BATCH_REMOVE,
\LDAP_MODIFY_BATCH_REMOVE_ALL,
Expand All @@ -34,7 +34,7 @@ class UpdateOperation
*/
public function __construct(int $operationType, string $attribute, ?array $values)
{
if (!\in_array($operationType, $this->validOperationTypes, true)) {
if (!\in_array($operationType, self::VALID_OPERATION_TYPES, true)) {
throw new UpdateOperationException(sprintf('"%s" is not a valid modification type.', $operationType));
}
if (\LDAP_MODIFY_BATCH_REMOVE_ALL === $operationType && null !== $values) {
Expand Down
17 changes: 13 additions & 4 deletions src/Symfony/Component/Ldap/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@
class Entry
{
private $dn;
private $attributes;
private $lowerMap;

/**
* @var array<string, array>
*/
private $attributes = [];

/**
* @var array<string, string>
*/
private $lowerMap = [];

/**
* @param array<string, array> $attributes
*/
public function __construct(string $dn, array $attributes = [])
{
$this->dn = $dn;
$this->attributes = [];
$this->lowerMap = [];

foreach ($attributes as $key => $attribute) {
$this->setAttribute($key, $attribute);
Expand Down
0