Skip to content
Snippets Groups Projects
Verified Commit 1fa23e66 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

refactor: treat binding collection as iterable

parent 079af378
No related branches found
No related tags found
2 merge requests!5feat: remove compilation command,!4feat: remove compilation command
...@@ -22,6 +22,13 @@ final class CompositeBinder implements Binder { ...@@ -22,6 +22,13 @@ final class CompositeBinder implements Binder {
} }
public function bind( Definition $def ): void { public function bind( Definition $def ): void {
if ( is_iterable( $def ) ) {
foreach ( $def as $d ) {
$this->bind( $d );
}
return;
}
foreach ( $this->binders as $binder ) { foreach ( $this->binders as $binder ) {
if ( $binder->can_bind( $def ) ) { if ( $binder->can_bind( $def ) ) {
$binder->bind( $def ); $binder->bind( $def );
......
...@@ -4,16 +4,20 @@ declare(strict_types=1); ...@@ -4,16 +4,20 @@ declare(strict_types=1);
namespace WPDesk\Init\Binding\Definition; namespace WPDesk\Init\Binding\Definition;
use IteratorAggregate;
use Traversable;
use WPDesk\Init\Binding\Definition; 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 ?string $hook;
private $hook;
/** @var Definition[] */ /** @var Definition[] */
private $defs; private array $defs;
/** @var array<string, mixed> */ /** @var array<string, mixed> */
private array $options; private array $options;
...@@ -41,4 +45,8 @@ class DefinitionCollection implements Definition { ...@@ -41,4 +45,8 @@ class DefinitionCollection implements Definition {
public function option( string $name ) { public function option( string $name ) {
return $this->options[ $name ] ?? null; return $this->options[ $name ] ?? null;
} }
public function getIterator(): Traversable {
yield from $this->defs;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment