src/Graviton/RestBundle/Controller/RestController.php
public function patchAction($id, Request $request)
    {
        $response = $this->getResponse();
        $model = $this->getModel();

        // Validate received data. On failure release the lock.
        try {
            // Check JSON Patch request
            $this->restUtils->checkJsonRequest($request, $response, $model);
            $this->restUtils->checkJsonPatchRequest(json_decode($request->getContent(), 1));

            // Find record && apply $ref converter
            $jsonDocument = $model->getSerialised($id, null);

            try {
                // Check if valid
                $this->jsonPatchValidator->validate($jsonDocument, $request->getContent());
                // Apply JSON patches
                $patch = new Patch($jsonDocument, $request->getContent());
                $patchedDocument = $patch->apply();
            } catch (\Exception $e) {
                throw new InvalidJsonPatchException($e->getMessage());
            }
        } catch (\Exception $e) {
            throw $e;
        }

        // if document hasn't changed, pass HTTP_NOT_MODIFIED and exit
        if ($jsonDocument == $patchedDocument) {
            $response->setStatusCode(Response::HTTP_NOT_MODIFIED);
            return $response;
        }

        // Validate result object
        $record = $this->restUtils->validateRequest($patchedDocument, $model);

        // Update object
        $this->getModel()->updateRecord($id, $record);

        // Set status response code
        $response->setStatusCode(Response::HTTP_OK);
        $response->headers->set(
            'Content-Location',
            $this->getRouter()->generate($this->restUtils->getRouteName($request), array('id' => $record->getId()))
        );

        return $response;
    }
public function patchAction($id, Request $request)
    {
        $response = $this->getResponse();
        $model = $this->getModel();

        // Validate received data. On failure release the lock.
        try {
            // Check JSON Patch request
            $this->restUtils->checkJsonRequest($request, $response, $model);
            $this->restUtils->checkJsonPatchRequest(json_decode($request->getContent(), 1));

            // Find record && apply $ref converter
            $jsonDocument = $model->getSerialised($id, null);

            try {
                // Check if valid
                $this->jsonPatchValidator->validate($jsonDocument, $request->getContent());
                // Apply JSON patches
                $patch = new Patch($jsonDocument, $request->getContent());
                $patchedDocument = $patch->apply();
            } catch (\Exception $e) {
                throw new InvalidJsonPatchException($e->getMessage());
            }
        } catch (\Exception $e) {
            throw $e;
        }

        // if document hasn't changed, pass HTTP_NOT_MODIFIED and exit
        if ($jsonDocument == $patchedDocument) {
            $response->setStatusCode(Response::HTTP_NOT_MODIFIED);
            return $response;
        }

        // Validate result object
        $record = $this->restUtils->validateRequest($patchedDocument, $model);

        // Update object
        $this->getModel()->updateRecord($id, $record);

        // Set status response code
        $response->setStatusCode(Response::HTTP_OK);
        $response->headers->set(
            'Content-Location',
            $this->getRouter()->generate($this->restUtils->getRouteName($request), array('id' => $record->getId()))
        );

        return $response;
    }
public function patchAction ( $ id , Request $ request ) { $ response = $ this -> getResponse ( ) ; $ model = $ this -> getModel ( ) ; // Validate received data. On failure release the lock. try { // Check JSON Patch request $ this -> restUtils -> checkJsonRequest ( $ request , $ response , $ model ) ; $ this -> restUtils -> checkJsonPatchRequest ( json_decode ( $ request -> getContent ( ) , 1 ) ) ; // Find record && apply $ref converter $ jsonDocument = $ model -> getSerialised ( $ id , null ) ; try { // Check if valid $ this -> jsonPatchValidator -> validate ( $ jsonDocument , $ request -> getContent ( ) ) ; // Apply JSON patches $ patch = new Patch ( $ jsonDocument , $ request -> getContent ( ) ) ; $ patchedDocument = $ patch -> apply ( ) ; } catch ( \ Exception $ e ) { throw new InvalidJsonPatchException ( $ e -> getMessage ( ) ) ; } } catch ( \ Exception $ e ) { throw $ e ; } // if document hasn't changed, pass HTTP_NOT_MODIFIED and exit if ( $ jsonDocument == $ patchedDocument ) { $ response -> setStatusCode ( Response :: HTTP_NOT_MODIFIED ) ; return $ response ; } // Validate result object $ record = $ this -> restUtils -> validateRequest ( $ patchedDocument , $ model ) ; // Update object $ this -> getModel ( ) -> updateRecord ( $ id , $ record ) ; // Set status response code $ response -> setStatusCode ( Response :: HTTP_OK ) ; $ response -> headers -> set ( 'Content-Location' , $ this -> getRouter ( ) -> generate ( $ this -> restUtils -> getRouteName ( $ request ) , array ( 'id' => $ record -> getId ( ) ) ) ) ; return $ response ; }
Patch a record

@param Number  $id      ID of record
@param Request $request Current http request

@throws MalformedInputException

@return Response $response Result of action with data (if successful)
Patch a record