private function finalizeCurrentCommand()
    {

        if ($this->batch instanceof BatchCommand && $this->currentCommand !== null) {

            if (isset($this->params['update']) && $this->params['update'] === true) {
                $this->currentCommand->action('post')->suffix('_update');


                if ($this->params['doc'] !== null) {
                    $data["doc"] = $this->params['doc'];
                }

                if ($this->params['updateScript'] !== null) {
                    $data["script"] = $this->params['updateScript'];
                }

                if ($this->params['updateParams'] !== null) {
                    $data["params"] = $this->params['updateParams'];
                }

                if ($this->params['updateUpsert'] !== null) {
                    $data["upsert"] = $this->params['updateUpsert'];
                }

                $this->currentCommand->data($data);

            } else {
                $this->currentCommand->data($this->params['doc']);
            }

            $this->batch->addCommand($this->currentCommand);

            $this->params['update'] = false;
        }

        $this->currentCommand = new Command();
    }
private function finalizeCurrentCommand()
    {

        if ($this->batch instanceof BatchCommand && $this->currentCommand !== null) {

            if (isset($this->params['update']) && $this->params['update'] === true) {
                $this->currentCommand->action('post')->suffix('_update');


                if ($this->params['doc'] !== null) {
                    $data["doc"] = $this->params['doc'];
                }

                if ($this->params['updateScript'] !== null) {
                    $data["script"] = $this->params['updateScript'];
                }

                if ($this->params['updateParams'] !== null) {
                    $data["params"] = $this->params['updateParams'];
                }

                if ($this->params['updateUpsert'] !== null) {
                    $data["upsert"] = $this->params['updateUpsert'];
                }

                $this->currentCommand->data($data);

            } else {
                $this->currentCommand->data($this->params['doc']);
            }

            $this->batch->addCommand($this->currentCommand);

            $this->params['update'] = false;
        }

        $this->currentCommand = new Command();
    }
private function finalizeCurrentCommand ( ) { if ( $ this -> batch instanceof BatchCommand && $ this -> currentCommand !== null ) { if ( isset ( $ this -> params [ 'update' ] ) && $ this -> params [ 'update' ] === true ) { $ this -> currentCommand -> action ( 'post' ) -> suffix ( '_update' ) ; if ( $ this -> params [ 'doc' ] !== null ) { $ data [ "doc" ] = $ this -> params [ 'doc' ] ; } if ( $ this -> params [ 'updateScript' ] !== null ) { $ data [ "script" ] = $ this -> params [ 'updateScript' ] ; } if ( $ this -> params [ 'updateParams' ] !== null ) { $ data [ "params" ] = $ this -> params [ 'updateParams' ] ; } if ( $ this -> params [ 'updateUpsert' ] !== null ) { $ data [ "upsert" ] = $ this -> params [ 'updateUpsert' ] ; } $ this -> currentCommand -> data ( $ data ) ; } else { $ this -> currentCommand -> data ( $ this -> params [ 'doc' ] ) ; } $ this -> batch -> addCommand ( $ this -> currentCommand ) ; $ this -> params [ 'update' ] = false ; } $ this -> currentCommand = new Command ( ) ; }
This is all horribly terible and will be ripped out as soon as possible.

Basically, This class stores an intermediate Command that maintains state across
chained requests, which allows updates (scripts, params, etc) to affect it.

The command is finalized when a new document is added, or the request is executed.
Finalization means collapsing the doc field data into a param, as well as updating
the action/suffix as necessary.
This is all horribly terible and will be ripped out as soon as possible .