Ejemplo n.º 1
0
 /**
  * @param AbstractModel $model
  */
 protected function internalSave(AbstractModel $model)
 {
     $pKey = $this->getPrimaryKey();
     if (isset($model->id)) {
         $this->tableGateway->update($model->toArray(), [$pKey => $model->{$pKey}]);
     } else {
         $this->tableGateway->insert($model->toArray());
         $id = $this->tableGateway->getLastInsertValue();
         $model->{$pKey} = $id;
     }
 }
 private function getUrl($method)
 {
     $parts = explode('\\', get_class($this->testedObject));
     $classname = lcfirst(end($parts));
     // Convert camel case to dash
     $classname = strtolower(preg_replace('/([A-Z])/', '-$1', $classname));
     $id = $this->testedObject->getId();
     switch ($method) {
         case 'getList':
         case Request::METHOD_POST:
             $route = "/api/{$classname}";
             break;
         case Request::METHOD_GET:
         case Request::METHOD_PATCH:
         case Request::METHOD_PUT:
         case Request::METHOD_DELETE:
             $route = "/api/{$classname}/{$id}";
             break;
         default:
             throw new \Exception("Unsupported route '{$method}' for {$classname}");
     }
     return $route;
 }