Skip to content
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
30 changes: 3 additions & 27 deletions src/FreeDSx/Sasl/Sasl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author Chad Sikorra <Chad.Sikorra@gmail.com>
*/
final class Sasl
final class Sasl implements SaslInterface
{
/**
* @var array<string, MechanismInterface> keyed by MechanismName->value
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -102,9 +81,6 @@ public function select(
->select($choices, $options);
}

/**
* @return array<string, MechanismInterface>
*/
public function mechanisms(): array
{
return $this->mechanisms;
Expand Down
67 changes: 67 additions & 0 deletions src/FreeDSx/Sasl/SaslInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

/**
* This file is part of the FreeDSx SASL package.
*
* (c) Chad Sikorra <Chad.Sikorra@gmail.com>
*
* 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 <Chad.Sikorra@gmail.com>
*/
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<string, MechanismInterface>
*/
public function mechanisms(): array;
}
Loading