Skip to content
Snippets Groups Projects
Select Git revision
  • a2549f07ea5d65726bb65f443ad55d8261dc1caf
  • main default protected
  • devel
  • 1.1.0
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
9 results

grumphp

Blame
  • ObservableBinder.php 842 B
    <?php
    
    declare(strict_types=1);
    
    namespace WPDesk\Init\Binding\Binder;
    
    use WPDesk\Init\Binding\Binder;
    use WPDesk\Init\Binding\ComposableBinder;
    use WPDesk\Init\Binding\Definition;
    
    /**
     * Binder decorator, specifically built for testing purposes. Can naively investigate other binders.
     */
    final class ObservableBinder implements ComposableBinder {
    
    	/** @var Binder */
    	private $binder;
    
    	private $binds_count = 0;
    
    	public function __construct( Binder $b ) {
    		$this->binder = $b;
    	}
    
    	public function bind( Definition $def ): void {
    		$this->binder->bind( $def );
    		$this->binds_count++;
    	}
    
    	public function can_bind( Definition $def ): bool {
    		if ( $this->binder instanceof ComposableBinder ) {
    			return $this->binder->can_bind( $def );
    		}
    
    		return true;
    	}
    
    	public function binds_count(): int {
    		return $this->binds_count;
    	}
    }