Set the closure instance.

@param Shell    $psysh
@param \Closure $closure
764936
protected function setClosure(Shell $shell, \Closure $closure)
    {
        if (self::shouldBindClosure()) {
            $that = $shell->getBoundObject();
            if (\is_object($that)) {
                $closure = $closure->bindTo($that, \get_class($that));
            } else {
                $closure = $closure->bindTo(null, $shell->getBoundClass());
            }
        }

        $this->closure = $closure;
    }
392590
public function extend($abstract, Closure $closure)
    {
        $abstract = $this->getAlias($abstract);

        if (isset($this->instances[$abstract])) {
            $this->instances[$abstract] = $closure($this->instances[$abstract], $this);

            $this->rebound($abstract);
        } else {
            $this->extenders[$abstract][] = $closure;

            if ($this->resolved($abstract)) {
                $this->rebound($abstract);
            }
        }
    }
125228
protected function _set($name, $definition, $type)
    {
        if ($definition instanceof Closure) {
            $definition = $definition->bindTo($this, get_class($this));
        }
        $this->_definitions[$name] = compact('definition', 'type');
    }
1039355
public function extend($abstract, Closure $closure)
	{
		if ( ! isset($this->bindings[$abstract]))
		{
			throw new \InvalidArgumentException("Type {$abstract} is not bound.");
		}

		$extender = $this->getExtender($abstract, $closure);

		$this->bind($abstract, $extender, $this->isShared($abstract));
	}
580643
public function setCallback($callback)
    {
        if (!$callback instanceof Closure) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid parameter for callback: must be %s',
                Closure::class
            ));
        }

        return parent::setCallback($callback);
    }
607990
public function callWithDisabledAuth(Closure $closure)
    {
        if ($this->isDisabledAuth()) {
            return call_user_func($closure);
        }

        try {
            $this->disableAuth();

            return call_user_func($closure);
        } finally {
            $this->enableAuth();
        }
    }
365381
public static function lazyInit ( Closure $closure, $key = null, array $params = [ ] )
    {
        if ( $key === null ) {
            $key = static::createBacktraceKey();
        }

        return static::lazyInitStatic( $closure, $key, $params );
    }
1227381
public function inCurrentDir(\Closure $closure)
    {
        $old = getcwd();
        $this->_mkdir($this->currentDir());
        chdir($this->currentDir());
        $closure($this);
        chdir($old);
    }
803696
public function setShell(Shell $shell)
    {
        $this->shell = $shell;
        $this->doAddCommands();
        $this->doAddMatchers();
    }
491612
public function resolveClosure(Closure $closure, array $args = [])
    {
        $closureRef = new ReflectionFunction($closure);
        $dependencies = $this->getMethodDependencies($closureRef, $args);

        return $closureRef->invokeArgs($dependencies);
    }
466259
public function parallel(Closure $closure)
    {
        $processId = $this->fork();

        if ($processId) {
            $process = new Process($processId, $this->master);
            $this->master->addChild($process);

            return $process;
        }

        $process = new Process($this->posix->getpid(), $this->master);
        $this->master->addChild($process);
        if (false === is_null($closure)) {
            call_user_func($closure, $process);
        }
        $this->terminateProcess($process);

        return $this;
    }
896008
public function after(\Closure $closure)
    {
        $key = 'after';
        $after = new Hook($key, $closure, $this->current);
        $this->current->setHook($key, $after);
    }
1051145
public function reject(\Closure $closure): self
    {
        // init
        $filtered = [];

        foreach ($this->getGenerator() as $key => $value) {
            if (!$closure($value, $key)) {
                $filtered[$key] = $value;
            }
        }

        return static::create(
            $filtered,
            $this->iteratorClass,
            false
        );
    }
1110595
public function afterEach(\Closure $closure)
    {
        $key = 'afterEach';
        $afterEach = new Hook($key, $closure, $this->current);
        $this->current->setHook($key, $afterEach);
    }
723407
public function xit($title, \Closure $closure = null)
    {
        $spec = new Spec($title, $closure, $this->current);
        $spec->setPending();
        $this->current->addSpec($spec);
    }
307206
public function each(Closure $closure)
    {
        foreach ($this->stack as &$item) {
            $closure($item);
        }

        return $this;
    }
307905
public function setServiceList($serviceList = [])
    {
        if (!$serviceList) return;

        foreach ($serviceList as $key => $closure) {
            $this->set($key, $closure);
        }
    }