private function switchContext(Context $context, bool $keepCurrentInStack = false): void
    {
        $command = new BuildContextConfig($this, $context, $this->config);
        $this->messageBus->dispatch($command::NAME, $command);

        if ($command->getConfig()) {
            $this->config = $command->getConfig();
        }

        if ($keepCurrentInStack && $this->context) {
            $this->contextStack[] = $this->context;
        }

        $this->context = $context;

        $event = new ContextEntered($this, $context);
        $this->messageBus->dispatch($event::NAME, $event);
    }
private function switchContext(Context $context, bool $keepCurrentInStack = false): void
    {
        $command = new BuildContextConfig($this, $context, $this->config);
        $this->messageBus->dispatch($command::NAME, $command);

        if ($command->getConfig()) {
            $this->config = $command->getConfig();
        }

        if ($keepCurrentInStack && $this->context) {
            $this->contextStack[] = $this->context;
        }

        $this->context = $context;

        $event = new ContextEntered($this, $context);
        $this->messageBus->dispatch($event::NAME, $event);
    }
private function switchContext ( Context $ context , bool $ keepCurrentInStack = false ) : void { $ command = new BuildContextConfig ( $ this , $ context , $ this -> config ) ; $ this -> messageBus -> dispatch ( $ command :: NAME , $ command ) ; if ( $ command -> getConfig ( ) ) { $ this -> config = $ command -> getConfig ( ) ; } if ( $ keepCurrentInStack && $ this -> context ) { $ this -> contextStack [ ] = $ this -> context ; } $ this -> context = $ context ; $ event = new ContextEntered ( $ this , $ context ) ; $ this -> messageBus -> dispatch ( $ event :: NAME , $ event ) ; }
Switch to another context.

@param Context $context            New context.
@param bool    $keepCurrentInStack If true current context is added to the stack.

@return void
Switch to another context .