Skip to content
Snippets Groups Projects
Select Git revision
  • bcc2a822e530ca794054b233a32ed6c865a71b6e
  • master default protected
  • bugfix/wordpress-review
  • fix/duplicate
  • bugfix/get_current_screen_fail
  • feature/dismiss-nonce
  • replace-dodgy-path
  • bugfix/notice-not-show
  • devel
  • 3.3.0
  • 3.2.5
  • 3.2.4
  • 3.2.3
  • 3.2.2
  • 3.2.1
  • 3.2.0
  • 3.2.0-beta7
  • 3.2.0-beta6
  • 3.2.0-beta5
  • 3.2.0-beta4
  • 3.2.0-beta3
  • 3.2.0-beta2
  • 3.2.0-beta1
  • 3.1.4
  • 3.1.4-beta1
  • 3.1.3
  • 3.1.1
  • 3.1
  • 3.0
29 results

AjaxHandler.php

Blame
  • StoppableBinder.php 1.12 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace WPDesk\Init\Binding\Binder;
    
    use Psr\Container\ContainerInterface;
    use WPDesk\Init\Binding\Binder;
    use WPDesk\Init\Binding\StoppableBinder as Stop;
    use WPDesk\Init\Binding\Definition;
    use WPDesk\Init\Binding\Definition\HookableDefinition;
    
    class StoppableBinder implements Binder {
    
    	/** @var ContainerInterface */
    	private $container;
    
    	/** @var Binder */
    	private $binder;
    
    	private $should_stop = false;
    
    	public function __construct( Binder $b, ContainerInterface $c ) {
    		$this->binder    = $b;
    		$this->container = $c;
    	}
    
    	public function can_bind( Definition $def ): bool {
    		return $this->binder->can_bind( $def );
    	}
    
    	public function bind( Definition $def ): void {
    		if ( $this->should_stop === true ) {
    			return;
    		}
    
    		$this->binder->bind( $def );
    
    		if ( $this->can_be_stoppable( $def ) ) {
    			$binding = $this->container->get( $def->value() );
    			if ( $binding instanceof Stop && $binding->should_stop() ) {
    				$this->should_stop = true;
    			}
    		}
    	}
    
    	private function can_be_stoppable( Definition $def ): bool {
    		return is_string( $def->value() ) && class_exists( $def->value() );
    	}
    
    }