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

refactor: split binder interface


Possibility to check, if binder is available is not necessary for
outside usage besides `CompositeBinder` class, so this interface can be
split and implemented only by specific classes.

Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent c90f560d
No related branches found
No related tags found
2 merge requests!3improve into wp-hook and some additional unfinished things,!21.x
...@@ -6,7 +6,5 @@ namespace WPDesk\Init\Binding; ...@@ -6,7 +6,5 @@ namespace WPDesk\Init\Binding;
interface Binder { interface Binder {
public function can_bind( Definition $def ): bool;
public function bind( Definition $def ): void; public function bind( Definition $def ): void;
} }
...@@ -5,11 +5,11 @@ declare(strict_types=1); ...@@ -5,11 +5,11 @@ declare(strict_types=1);
namespace WPDesk\Init\Binding\Binder; namespace WPDesk\Init\Binding\Binder;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use WPDesk\Init\Binding\Binder; use WPDesk\Init\Binding\ComposableBinder;
use WPDesk\Init\Binding\Definition; use WPDesk\Init\Binding\Definition;
use WPDesk\Init\Binding\Definition\CallableDefinition; use WPDesk\Init\Binding\Definition\CallableDefinition;
class CallableBinder implements Binder { class CallableBinder implements ComposableBinder {
/** @var ContainerInterface */ /** @var ContainerInterface */
private $container; private $container;
...@@ -23,7 +23,6 @@ class CallableBinder implements Binder { ...@@ -23,7 +23,6 @@ class CallableBinder implements Binder {
} }
public function bind( Definition $def ): void { public function bind( Definition $def ): void {
if ( $def instanceof CallableDefinition ) {
$ref = new \ReflectionFunction( $def->value() ); $ref = new \ReflectionFunction( $def->value() );
$parameters = []; $parameters = [];
foreach ( $ref->getParameters() as $ref_param ) { foreach ( $ref->getParameters() as $ref_param ) {
...@@ -32,4 +31,3 @@ class CallableBinder implements Binder { ...@@ -32,4 +31,3 @@ class CallableBinder implements Binder {
$ref->invokeArgs( $parameters ); $ref->invokeArgs( $parameters );
} }
} }
}
...@@ -21,16 +21,6 @@ final class CompositeBinder implements Binder { ...@@ -21,16 +21,6 @@ final class CompositeBinder implements Binder {
$this->binders[] = $binder; $this->binders[] = $binder;
} }
public function can_bind( Definition $def ): bool {
foreach ( $this->binders as $binder ) {
if ( $binder->can_bind( $def ) ) {
return true;
}
}
return false;
}
public function bind( Definition $def ): void { public function bind( Definition $def ): void {
foreach ( $this->binders as $binder ) { foreach ( $this->binders as $binder ) {
if ( $binder->can_bind( $def ) ) { if ( $binder->can_bind( $def ) ) {
......
...@@ -5,11 +5,11 @@ declare(strict_types=1); ...@@ -5,11 +5,11 @@ declare(strict_types=1);
namespace WPDesk\Init\Binding\Binder; namespace WPDesk\Init\Binding\Binder;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use WPDesk\Init\Binding\Binder; use WPDesk\Init\Binding\ComposableBinder;
use WPDesk\Init\Binding\Definition; use WPDesk\Init\Binding\Definition;
use WPDesk\Init\Binding\Definition\HookableDefinition; use WPDesk\Init\Binding\Definition\HookableDefinition;
class HookableBinder implements Binder { class HookableBinder implements ComposableBinder {
/** @var ContainerInterface */ /** @var ContainerInterface */
private $container; private $container;
...@@ -23,8 +23,6 @@ class HookableBinder implements Binder { ...@@ -23,8 +23,6 @@ class HookableBinder implements Binder {
} }
public function bind( Definition $def ): void { public function bind( Definition $def ): void {
if ( $def instanceof HookableDefinition ) {
$this->container->get( $def->value() )->hooks(); $this->container->get( $def->value() )->hooks();
} }
} }
}
...@@ -5,12 +5,12 @@ declare(strict_types=1); ...@@ -5,12 +5,12 @@ declare(strict_types=1);
namespace WPDesk\Init\Binding\Binder; namespace WPDesk\Init\Binding\Binder;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use WPDesk\Init\Binding\Binder; use WPDesk\Init\Binding\ComposableBinder;
use WPDesk\Init\Binding\StoppableBinder as Stop; use WPDesk\Init\Binding\StoppableBinder as Stop;
use WPDesk\Init\Binding\Definition; use WPDesk\Init\Binding\Definition;
use WPDesk\Init\Binding\Definition\HookableDefinition; use WPDesk\Init\Binding\Definition\HookableDefinition;
class StoppableBinder implements Binder { class StoppableBinder implements ComposableBinder {
/** @var ContainerInterface */ /** @var ContainerInterface */
private $container; private $container;
......
<?php
declare(strict_types=1);
namespace WPDesk\Init\Binding;
/**
* Can be composed with other binders within {@see CompositeBinder} class.
*/
interface ComposableBinder extends Binder {
public function can_bind( Definition $def ): bool;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment