Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #27069 [LDAP] Add "applyOperations" method to EntryManager (m…
…ablae) This PR was merged into the 4.2-dev branch. Discussion ---------- [LDAP] Add "applyOperations" method to EntryManager | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27039 | License | MIT | Doc PR | symfony/symfony-docs#9715 This PR adds a new method called `applyOperations` to the LDAP `EntryManager` class. Internally it is mapping the new `UpdateOperation` object to the `ldap_modify_batch` method. Tests green against openldap. Thanks for any feedback. Todo: * [x] Add Docs PR Commits ------- 8fc09c7 Add applyOperations batch method to EntryManager
- Loading branch information
Showing
4 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Ldap\Adapter\ExtLdap; | ||
|
||
use Symfony\Component\Ldap\Exception\UpdateOperationException; | ||
|
||
class UpdateOperation | ||
{ | ||
private $operationType; | ||
private $values; | ||
private $attribute; | ||
|
||
private $validOperationTypes = array( | ||
LDAP_MODIFY_BATCH_ADD, | ||
LDAP_MODIFY_BATCH_REMOVE, | ||
LDAP_MODIFY_BATCH_REMOVE_ALL, | ||
LDAP_MODIFY_BATCH_REPLACE, | ||
); | ||
|
||
/** | ||
* @param int $operationType An LDAP_MODIFY_BATCH_* constant | ||
* @param string $attribute The attribute to batch modify on | ||
* | ||
* @throws UpdateOperationException on consistency errors during construction | ||
*/ | ||
public function __construct(int $operationType, string $attribute, ?array $values) | ||
{ | ||
$this->assertValidOperationType($operationType); | ||
$this->assertNullValuesOnRemoveAll($operationType, $values); | ||
|
||
$this->operationType = $operationType; | ||
$this->attribute = $attribute; | ||
$this->values = $values; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array( | ||
'attrib' => $this->attribute, | ||
'modtype' => $this->operationType, | ||
'values' => $this->values, | ||
); | ||
} | ||
|
||
/** | ||
* @param int $operationType | ||
*/ | ||
private function assertValidOperationType(int $operationType): void | ||
{ | ||
if (!in_array($operationType, $this->validOperationTypes, true)) { | ||
throw new UpdateOperationException(sprintf('"%s" is not a valid modification type.', $operationType)); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $operationType | ||
* @param array|null $values | ||
* | ||
* @throws \Symfony\Component\Ldap\Exception\UpdateOperationException | ||
*/ | ||
private function assertNullValuesOnRemoveAll(int $operationType, ?array $values): void | ||
{ | ||
if (LDAP_MODIFY_BATCH_REMOVE_ALL === $operationType && null !== $values) { | ||
throw new UpdateOperationException(sprintf('$values must be null for LDAP_MODIFY_BATCH_REMOVE_ALL operation, "%s" given.', gettype($values))); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Symfony/Component/Ldap/Exception/UpdateOperationException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Ldap\Exception; | ||
|
||
class UpdateOperationException extends LdapException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters