src/State/FluentState.php
public function withState(callable $callback)
    {
        $newState = clone $this;
        try {
            Injector::inst()->registerService($newState);
            return $callback($newState);
        } finally {
            Injector::inst()->registerService($this);
        }
    }
public function withState(callable $callback)
    {
        $newState = clone $this;
        try {
            Injector::inst()->registerService($newState);
            return $callback($newState);
        } finally {
            Injector::inst()->registerService($this);
        }
    }
public function withState ( callable $ callback ) { $ newState = clone $ this ; try { Injector :: inst ( ) -> registerService ( $ newState ) ; return $ callback ( $ newState ) ; } finally { Injector :: inst ( ) -> registerService ( $ this ) ; } }
Perform the given operation in an isolated state.
On return, the state will be restored, so any modifications are temporary.

@param callable $callback Callback to run. Will be passed the nested state as a parameter
@return mixed Result of callback
Perform the given operation in an isolated state . On return the state will be restored so any modifications are temporary .