Skip to content
Snippets Groups Projects

feat: remove compilation command

Open Bartek Jaskulski requested to merge v0.10 into main
2 files
+ 12
3
Compare changes
  • Side-by-side
  • Inline

Files

@@ -10,11 +10,9 @@ use WPDesk\Init\Plugin\Plugin;
class ArrayDefinitions implements BindingDefinitions {
/** @var array */
private $bindings;
private array $bindings;
/** @var DefinitionFactory */
private $factory;
private DefinitionFactory $factory;
public function __construct( array $bindings, ?DefinitionFactory $factory = null ) {
$this->bindings = $bindings;
@@ -25,12 +23,27 @@ class ArrayDefinitions implements BindingDefinitions {
yield from $this->normalize( $this->bindings );
}
/**
* @param iterable<string,array> $bindings
*
* @return iterable<Definition>
*/
private function normalize( iterable $bindings ): iterable {
foreach ( $bindings as $key => $value ) {
if ( is_array( $value ) ) {
if ( isset( $value['handler'] ) ) {
// Single item with handler.
yield $this->create( $value['handler'], $key, $value );
} else {
// Multiple items.
foreach ( $value as $unit ) {
if ( is_array( $unit ) && isset( $unit['handler'] ) ) {
yield $this->create( $unit['handler'], $key, $unit );
} else {
yield $this->create( $unit, $key );
}
}
}
} else {
yield $this->create( $value, $key );
}
@@ -41,7 +54,7 @@ class ArrayDefinitions implements BindingDefinitions {
* @param mixed $value
* @param int|string $hook
*/
private function create( $value, $hook ): Definition {
return $this->factory->create( $value, is_int( $hook ) ? null : $hook );
private function create( $value, $hook, array $options = [] ): Definition {
return $this->factory->create( $value, is_int( $hook ) ? null : $hook, $options );
}
}
Loading