diff --git a/src/Binding/Binder/CompositeBinder.php b/src/Binding/Binder/CompositeBinder.php index 8b88634687b2fbb7b07c99b710db520398b33c2f..4df27e4ac720cb0fddcb6b80c091900e288e2e81 100644 --- a/src/Binding/Binder/CompositeBinder.php +++ b/src/Binding/Binder/CompositeBinder.php @@ -22,6 +22,13 @@ final class CompositeBinder implements Binder { } public function bind( Definition $def ): void { + if ( is_iterable( $def ) ) { + foreach ( $def as $d ) { + $this->bind( $d ); + } + return; + } + foreach ( $this->binders as $binder ) { if ( $binder->can_bind( $def ) ) { $binder->bind( $def ); diff --git a/src/Binding/Definition/DefinitionCollection.php b/src/Binding/Definition/DefinitionCollection.php index ed67b92d4f5daf1c51d58687077d76c6c3703154..99b82ba501b9e7e51a3098319a8ff65cae819297 100644 --- a/src/Binding/Definition/DefinitionCollection.php +++ b/src/Binding/Definition/DefinitionCollection.php @@ -4,16 +4,20 @@ declare(strict_types=1); namespace WPDesk\Init\Binding\Definition; +use IteratorAggregate; +use Traversable; use WPDesk\Init\Binding\Definition; -/** @implements Definition<mixed> */ -class DefinitionCollection implements Definition { +/** + * @implements Definition<mixed> + * @implements IteratorAggregate<mixed,Definition<mixed>> + */ +class DefinitionCollection implements Definition, \IteratorAggregate { - /** @var ?string */ - private $hook; + private ?string $hook; /** @var Definition[] */ - private $defs; + private array $defs; /** @var array<string, mixed> */ private array $options; @@ -41,4 +45,8 @@ class DefinitionCollection implements Definition { public function option( string $name ) { return $this->options[ $name ] ?? null; } + + public function getIterator(): Traversable { + yield from $this->defs; + } }