public static function create($data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         /** @var Robots $robot */
         $robot = new Robots();
         $robot->setAttributes($data);
         $response->data = $robot->create();
         $response->status = $response::STATUS_CREATED;
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
Example #2
0
 public static function create($data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         /** @var Products $products */
         $category = new Categories();
         $category->setAttributes($data);
         $response->data = $category->create();
         $response->status = $response::STATUS_CREATED;
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
Example #3
0
 /**
  * @param Exception $e
  * @return void
  * @throws Exception
  */
 public function handleException(Exception $e)
 {
     // don't render runtime exceptions
     if ($e instanceof RuntimeException) {
         throw $e;
     }
     $response = new Response();
     $response->setException($e);
     $this->setResponse($response);
     try {
         $this->dispatch('Error', 'error');
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #4
0
 public static function create($data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         $category = Categories::findFirst($data->categoryId);
         if ($category !== FALSE) {
             /** @var Products $products */
             $product = new Products();
             $product->setAttributes($data);
             $response->data = $product->create();
             $response->status = $response::STATUS_CREATED;
         } else {
             $response->status = $response::STATUS_BAD_REQUEST;
             $response->addError('CATEGORIES_NOT_FOUND');
         }
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }