Skip to content
Snippets Groups Projects
Select Git revision
  • dba7a0e1a6761916877fa9c2e64d7d9874b19e41
  • main default protected
  • v0.10
  • 0.10.6
  • 0.10.5
  • 0.10.4
  • 0.10.3
  • 0.10.2
  • 0.10.1
  • 0.10.0
  • 0.9.1
  • 0.9.0
12 results

ObservableBinder.php

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;
    	}
    }