public function patch($selection, $operations = null)
    {
        $isPatch = $selection instanceof Patch;
        $patch = $isPatch ? $selection : null;

        if ($isPatch) {
            $this->operations[] = ['patch' => $patch->serialize()];
            return $this;
        }

        if (!is_array($operations)) {
            throw new InvalidArgumentException(
                '`patch` requires either an instantiated patch or an array of patch operations'
            );
        }

        $sel = (new Selection($selection))->serialize();
        $this->operations[] = ['patch' => array_merge($sel, $operations)];
        return $this;
    }
public function patch($selection, $operations = null)
    {
        $isPatch = $selection instanceof Patch;
        $patch = $isPatch ? $selection : null;

        if ($isPatch) {
            $this->operations[] = ['patch' => $patch->serialize()];
            return $this;
        }

        if (!is_array($operations)) {
            throw new InvalidArgumentException(
                '`patch` requires either an instantiated patch or an array of patch operations'
            );
        }

        $sel = (new Selection($selection))->serialize();
        $this->operations[] = ['patch' => array_merge($sel, $operations)];
        return $this;
    }
public function patch ( $ selection , $ operations = null ) { $ isPatch = $ selection instanceof Patch ; $ patch = $ isPatch ? $ selection : null ; if ( $ isPatch ) { $ this -> operations [ ] = [ 'patch' => $ patch -> serialize ( ) ] ; return $ this ; } if ( ! is_array ( $ operations ) ) { throw new InvalidArgumentException ( '`patch` requires either an instantiated patch or an array of patch operations' ) ; } $ sel = ( new Selection ( $ selection ) ) -> serialize ( ) ; $ this -> operations [ ] = [ 'patch' => array_merge ( $ sel , $ operations ) ] ; return $ this ; }
Patch the given document or selection

If a patch is passed as the first argument, it will be used directly.

@param string|array|Selection|Patch $selection Document ID, selection or a patch to apply
@param array $operations Optional array of initial patches
@return Sanity\Patch
Patch the given document or selection