From 94ded3b97affe0d5ade20356326ec11b07c57d09 Mon Sep 17 00:00:00 2001 From: Daniel Burger <48986191+danielburger1337@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:17:10 +0100 Subject: [PATCH] Simplify flattening of "ip_whitelist" config option --- .../DependencyInjection/Configuration.php | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/bundle/DependencyInjection/Configuration.php b/src/bundle/DependencyInjection/Configuration.php index 8c4f1172..0a43b63b 100644 --- a/src/bundle/DependencyInjection/Configuration.php +++ b/src/bundle/DependencyInjection/Configuration.php @@ -4,6 +4,8 @@ namespace Scheb\TwoFactorBundle\DependencyInjection; +use RecursiveArrayIterator; +use RecursiveIteratorIterator; use Scheb\TwoFactorBundle\Model\BackupCodeInterface; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EMailTwoFactorInterface; use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface; @@ -15,7 +17,7 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken; use function interface_exists; -use function is_iterable; +use function iterator_to_array; /** * @final @@ -45,13 +47,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayNode('ip_whitelist') ->beforeNormalization() ->ifArray() - ->then(static function (mixed $value): array { - $values = []; - foreach (self::flatten($value) as $v) { - $values[] = $v; - } - - return $values; + ->then(static function (array $value): array { + return iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($value)), false); }) ->end() ->defaultValue([]) @@ -224,24 +221,4 @@ private function addGoogleAuthenticatorConfiguration(ArrayNodeDefinition $rootNo ->end() ->end(); } - - /** - * @param iterable $iterableValue - * - * @return iterable - */ - private static function flatten(iterable $iterableValue): iterable - { - foreach ($iterableValue as $value) { - if (is_iterable($value)) { - foreach (self::flatten($value) as $x) { - yield $x; - } - - continue; - } - - yield $value; - } - } }