diff --git a/src/FreeDSx/Sasl/Sasl.php b/src/FreeDSx/Sasl/Sasl.php index 167f7cd..bbf07ae 100644 --- a/src/FreeDSx/Sasl/Sasl.php +++ b/src/FreeDSx/Sasl/Sasl.php @@ -29,7 +29,7 @@ * * @author Chad Sikorra */ -final class Sasl +final class Sasl implements SaslInterface { /** * @var array keyed by MechanismName->value @@ -41,11 +41,6 @@ public function __construct(private readonly SaslOptions $options = new SaslOpti $this->initMechs(); } - /** - * Get a mechanism object by its name. - * - * @throws SaslException - */ public function get(MechanismName $mechanism): MechanismInterface { $mech = $this->mechanisms[$mechanism->value] ?? null; @@ -59,41 +54,25 @@ public function get(MechanismName $mechanism): MechanismInterface return $mech; } - /** - * Whether or not the mechanism is supported. - */ public function supports(MechanismName $mechanism): bool { return isset($this->mechanisms[$mechanism->value]); } - /** - * Add a mechanism object. - */ - public function add(MechanismInterface $mechanism): self + public function add(MechanismInterface $mechanism): static { $this->mechanisms[$mechanism->getName()->value] = $mechanism; return $this; } - /** - * Remove a mechanism by its name. - */ - public function remove(MechanismName $mechanism): self + public function remove(MechanismName $mechanism): static { unset($this->mechanisms[$mechanism->value]); return $this; } - /** - * Given an array of mechanism names, and optional selection options, select the best supported mechanism available. - * - * @param MechanismName[] $choices array of mechanisms by their name - * - * @throws SaslException - */ public function select( array $choices = [], ?SelectOptions $options = null, @@ -102,9 +81,6 @@ public function select( ->select($choices, $options); } - /** - * @return array - */ public function mechanisms(): array { return $this->mechanisms; diff --git a/src/FreeDSx/Sasl/SaslInterface.php b/src/FreeDSx/Sasl/SaslInterface.php new file mode 100644 index 0000000..ca58571 --- /dev/null +++ b/src/FreeDSx/Sasl/SaslInterface.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FreeDSx\Sasl; + +use FreeDSx\Sasl\Exception\SaslException; +use FreeDSx\Sasl\Mechanism\MechanismInterface; +use FreeDSx\Sasl\Mechanism\MechanismName; +use FreeDSx\Sasl\Options\SelectOptions; + +/** + * The SASL interface. + * + * @author Chad Sikorra + */ +interface SaslInterface +{ + /** + * Get a mechanism by its name. + * + * @throws SaslException + */ + public function get(MechanismName $mechanism): MechanismInterface; + + /** + * Whether the mechanism is supported. + */ + public function supports(MechanismName $mechanism): bool; + + /** + * Add a mechanism. + */ + public function add(MechanismInterface $mechanism): static; + + /** + * Remove a mechanism by name. + */ + public function remove(MechanismName $mechanism): static; + + /** + * Select the best available mechanism from the given choices. + * + * @param MechanismName[] $choices + * @throws SaslException + */ + public function select( + array $choices = [], + ?SelectOptions $options = null, + ): MechanismInterface; + + /** + * All registered mechanisms, keyed by MechanismName value. + * + * @return array + */ + public function mechanisms(): array; +}