vendor/pimcore/customer-management-framework-bundle/src/Controller/Rest/CrudHandlerController.php line 24

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace CustomerManagementFrameworkBundle\Controller\Rest;
  15. use CustomerManagementFrameworkBundle\RESTApi\CrudHandlerInterface;
  16. use CustomerManagementFrameworkBundle\RESTApi\Exception\ExceptionInterface;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. abstract class CrudHandlerController extends RestHandlerController
  21. {
  22.     /**
  23.      * @return CrudHandlerInterface
  24.      */
  25.     abstract protected function getHandler();
  26.     /**
  27.      * @param Request $request
  28.      * @Route("")
  29.      * @Method({"GET"})
  30.      */
  31.     public function listRecords(Request $request)
  32.     {
  33.         $handler $this->getHandler();
  34.         $response null;
  35.         try {
  36.             $response $handler->listRecords($request);
  37.         } catch (ExceptionInterface $e) {
  38.             $response $this->createErrorResponse(
  39.                 $e->getMessage(),
  40.                 $e->getResponseCode() > $e->getResponseCode() : 400
  41.             );
  42.         }
  43.         return $response;
  44.     }
  45.     /**
  46.      * @param Request $request
  47.      * @Route("/{id}")
  48.      * @Method({"GET"})
  49.      */
  50.     public function readRecord(Request $request)
  51.     {
  52.         $handler $this->getHandler();
  53.         $response null;
  54.         try {
  55.             $response $handler->readRecord($request);
  56.         } catch (ExceptionInterface $e) {
  57.             $response $this->createErrorResponse(
  58.                 $e->getMessage(),
  59.                 $e->getResponseCode() > $e->getResponseCode() : 400
  60.             );
  61.         }
  62.         return $response;
  63.     }
  64.     /**
  65.      * @param Request $request
  66.      * @Route("/{id}")
  67.      * @Method({"DELETE"})
  68.      */
  69.     public function deleteRecord(Request $request)
  70.     {
  71.         $handler $this->getHandler();
  72.         $response null;
  73.         try {
  74.             $response $handler->deleteRecord($request);
  75.         } catch (ExceptionInterface $e) {
  76.             $response $this->createErrorResponse(
  77.                 $e->getMessage(),
  78.                 $e->getResponseCode() > $e->getResponseCode() : 400
  79.             );
  80.         }
  81.         return $response;
  82.     }
  83.     /**
  84.      * @param Request $request
  85.      * @Route("/{id}")
  86.      * @Method({"PUT", "POST"})
  87.      */
  88.     public function updateRecord(Request $request)
  89.     {
  90.         $handler $this->getHandler();
  91.         $response null;
  92.         try {
  93.             $response $handler->updateRecord($request);
  94.         } catch (ExceptionInterface $e) {
  95.             $response $this->createErrorResponse(
  96.                 $e->getMessage(),
  97.                 $e->getResponseCode() > $e->getResponseCode() : 400
  98.             );
  99.         }
  100.         return $response;
  101.     }
  102.     /**
  103.      * @param Request $request
  104.      * @Route("")
  105.      * @Method({"PUT", "POST"})
  106.      */
  107.     public function createRecord(Request $request)
  108.     {
  109.         $handler $this->getHandler();
  110.         $response null;
  111.         try {
  112.             $response $handler->createRecord($request);
  113.         } catch (ExceptionInterface $e) {
  114.             $response $this->createErrorResponse(
  115.                 $e->getMessage(),
  116.                 $e->getResponseCode() > $e->getResponseCode() : 400
  117.             );
  118.         }
  119.         return $response;
  120.     }
  121. }