Create a class based binding using the IoC container.

@param  string    $binding
@return \Closure
763124
public function createClassBinding($binding)
    {
        return function ($value, $route) use ($binding) {
            // If the binding has an @ sign, we will assume it's being used to delimit
            // the class name from the bind method name. This allows for bindings
            // to run multiple bind methods in a single class for convenience.
            $segments = explode('@', $binding);
            $method = count($segments) == 2 ? $segments[1] : 'bind';
            $callable = [$this->container->make($segments[0]), $method];
            
            return call_user_func($callable, $value, $route);
        };
    }
383705
private function cleanup($bind)
    {
        if (!is_array($bind)) {
            if (!empty($bind))
                $bind = array($bind);
            else
                $bind = array();
        }
        return $bind;
    }
558105
public function getRelated($binding = null) {
        if (is_null($binding)) {
            return $this->_related;
        }
        return $this->_related[$binding];
    }
1262491
protected function share($binding, $class, $params = [], $alias = false)
    {
        if (is_string($class)) {
            $closure = function ($app) use ($class, $params) {
                return $app->build($class, $params);
            };
        } else {
            $closure = $class;
        }
        $this->app[ $binding ] = $this->app->share($closure);
        if ($alias) {
            $this->app->alias($binding, $class);
        }
    }
427611
protected function build(string $classname, string $entry) : Closure
    {
        if (isset($this->dependencies[$entry])) {
            return $this->dependencies[$entry];
        }

        return function () use ($classname) {
            return $this->make($classname);
        };
    }
1054717
public function make($abstract, $parameters = [])
    {
        if ($alias = $this->getAlias($abstract)) {
            $abstract = $alias;
        }

        if (isset($this->instances[$abstract])) {
            return $this->instances[$abstract];
        }

        if (!isset($this->binds[$abstract])) {
            throw new \InvalidArgumentException(Lang::get('_CONTAINER_MAKE_PARAMS_ERROR_', $abstract));
        }

        if ($this->binds[$abstract]['concrete'] instanceof \Closure) {
            array_unshift($parameters, $this);
            $instance = call_user_func_array($this->binds[$abstract]['concrete'], (array)$parameters);
        } else {
            $concrete = $this->binds[$abstract]['concrete'];
            $instance = new $concrete($parameters);
        }
        $this->binds[$abstract]['singleton'] && $this->instances[$abstract] = $instance;

        return $instance;
    }
1095223
public function make($contract)
    {
        if (empty($this->bindings[$contract])) {
            throw new \LogicException('Not found contract:' . $contract);
        }

        $class = $this->bindings[$contract];
        if ($class['type'] == 'closure') {
            return call_user_func($class['closure'], $class['class'], $class['args']);
        } else if ($class['type'] == 'singleton') {
            return $class['instance'];
        }

        throw new \LogicException('Not found contract:' . $contract);
    }
116834
public function get($class, $mapping)
    {
        if (is_object($class)) {
            $class = get_class($class);
        }
        if (array_key_exists($class, $this->handlers)) {
            $handler = $this->handlers[$class];

            $field = call_user_func($handler, $mapping, $this->em);
        } else {
            $field = new $class($mapping, $this->em);
        }

        if ($field instanceof SanitiserAwareInterface) {
            $field->setSanitiser($this->sanitiser);
        }

        return $field;
    }
812458
public function setBindings(array $bindings)
    {
        foreach ($bindings as $key => $binding) {
            if (!$binding instanceof BoundArgument) {
                $bindings[$key] = new BoundArgument($binding);
            }
        }

        $this->bindings = $bindings;

        return $this;
    }
1116329
private static function getCallableReflectionMethod($input)
    {
        if (is_array($input)) {
            $dependentClass  = is_string($input[0]) ? $input[0] : get_class($input[0]);
            $dependentMethod = $input[1] ?? '__construct';

            return new ReflectionMethod($dependentClass, $dependentMethod);
        } elseif ($input instanceof Closure) {

            return new ReflectionFunction($input);
        } elseif (is_callable($input)) {

            return new ReflectionMethod(get_class($input), '__invoke');
        } else {
            throw new InvalidArgumentException('$input needs to be a callable');
        }
    }
313160
protected function compileSetterInjector(Binding $binding, $wrapClosure = true)
	{
		$setters = $binding->getMarkers(SetterInjection::class);
		
		if(empty($setters))
		{
			return 'NULL';
		}
		
		$setterTypeName = $binding->isImplementationBinding() ? $binding->getTarget() : $binding->getTypeName();
		
		$code = $wrapClosure ? 'function($obj) { ' : '';
		$ref = new \ReflectionClass($setterTypeName);
		
		foreach($setters as $setter)
		{
			foreach($this->collectSetterMethods($ref, $setter) as $method)
			{
				$params = $method->getParameters();
					
				if(empty($params))
				{
					continue;
				}
				
				$injector = '$obj->' . $method->getName() . '(';
					
				foreach($params as $i => $param)
				{
					if(NULL === ($paramTypeName = $param->getClass()))
					{
						continue 2;
					}
						
					if($i != 0)
					{
						$injector .= ', ';
					}
					
					$nullable = $param->isOptional() ? 'Nullable' : '';
				
					$injector .= '$this->get' . $nullable . '(' . var_export($paramTypeName->name, true) . ', new InjectionPoint(';
					$injector .= 'get_class($obj), ' . var_export($method->getName(), true) . '))';
				}
					
				$code .= $injector . '); ';
			}
		}
		
		return $wrapClosure ? ($code . '}') : $code;
	}
87271
public function custom($sql, $bind = array())
    {
        // Prepare query
        $query = ConnectionManager::getConnection()->prepare($sql);

        // Bind when needed
        if (count($bind) > 0) {
            $numericBinding = true;

            // Check if we are going to use the numeric binding
            foreach($bind as $key => $value) {
                if (is_int($key)) {
                    continue;
                }else{
                    $numericBinding = false; // @codeCoverageIgnore
                    if (substr($key, 0, 1) !== ':') { // @codeCoverageIgnore
                        throw new QueryException("When binding, you should use numeric keys or keys with : before each key to identify the binding place in the query!"); // @codeCoverageIgnore
                    } // @codeCoverageIgnore
                }
            }

            // Bind it!
            $idx = 1;
            foreach($bind as $key => $value) {
                if ($numericBinding) {
                    if (is_int($value)) {
                        $type = \PDO::PARAM_INT; // @codeCoverageIgnore
                    } elseif(is_bool($value)) {
                        $type = \PDO::PARAM_BOOL; // @codeCoverageIgnore
                    } else {
                        $type = \PDO::PARAM_STR;
                    }
                    $query->bindValue($idx, $value, $type);
                } else {
                    $query->bindValue($key, $value);
                }
            }
        }

        // Set fetch mode
        $query->setFetchMode(\PDO::FETCH_CLASS, $this->class);

        // Execute
        $query->execute();

        // Fetch and return
        return $this->injectState($query->fetchAll());
    }
825896
public function extend($abstract, \Closure $closure)
        {
            if (!Arrays::exists($abstract, $this->bindings)) {
                throw new \InvalidArgumentException("Type {$abstract} is not bound.");
            }
            // To "extend" a binding, we will grab the old "resolver" Closure and pass it
            // into a new one. The old resolver will be called first and the result is
            // handed off to the "new" resolver, along with this container instance.
            $resolver = $this->bindings[$abstract]['concrete'];
            $this->bind($abstract, function($container) use ($resolver, $closure) {
                return $closure($resolver($container), $container);
            }, $this->isShared($abstract));
        }
390426
public function acceptsBinding($binding)
    {
        return $binding instanceof $this->acceptedBindingClass
            || $binding === $this->acceptedBindingClass
            || is_subclass_of($binding, $this->acceptedBindingClass);
    }
830735
public function channel($bind = []): Observable
    {
        $this->bunny = $this->bunny ?? new BaseAsynchClient($this->loop, $this->configuration);

        if (!\is_array($bind)) {
            $bind = \func_get_args();
        }

        return Observable::fromPromise(
            $this->bunny
                ->connect()
                ->then(function (BaseAsynchClient $client) {
                    return $client->channel();
                })
                ->then(function (Channel $channel) use ($bind) {
                    foreach ($bind as $obj) {
                        $obj->setChannel($channel);
                    }

                    return $channel;
                })
        );
    }
419625
private function inferType($binding)
	{
		if (is_bool($binding))
		{
			$type = \PDO::PARAM_BOOL;
		}
		elseif (is_null($binding))
		{
			$type = \PDO::PARAM_NULL;
		}
		elseif (is_int($binding))
		{
			$type = \PDO::PARAM_INT;
		}
		else
		{
			$type = \PDO::PARAM_STR;
		}

		return $type;
	}
766419
public function bind($contract, $class, $args = [])
    {
        $closure = function($class, $args) {
            $reflect = new \ReflectionClass($class);
            return $reflect->newInstanceArgs($args);
        };

        $this->bindings[$contract] = [
            'type' => 'closure',
            'closure' => $closure,
            'class' => $class,
            'args' => $args
        ];

        if (!class_exists($contract, false)) {
            eval("class {$contract} extends \Hades\Container\Facade {} ");
        }
    }