コード例 #1
0
ファイル: Model.php プロジェクト: Archcry/PhalconApiBase
 public function save($data = null, $whiteList = null)
 {
     $response = array();
     if (parent::save($data, $whiteList) == false) {
         foreach (parent::getMessages() as $message) {
             $response['errors'][] = (string) $message;
         }
     } else {
         foreach (parent::toArray() as $key => $value) {
             $response[$key] = $value;
         }
         $response['msg'] = 'ok';
     }
     return $response;
 }
コード例 #2
0
 public function toArray($columns = null)
 {
     if (is_null($columns) && is_array($this->visible)) {
         // Only show the visible columns
         $columns = $this->visible;
     }
     $attributes = parent::toArray($columns);
     if (is_null($columns) && is_array($this->hidden) && count($attributes)) {
         // Only show columns which have not been hidden
         foreach ($attributes as $key => $value) {
             if (in_array($key, $this->hidden)) {
                 unset($attributes[$key]);
             }
         }
     }
     return $attributes;
 }
コード例 #3
0
 protected function onRemoveFailed(Model $item)
 {
     throw new Exception(ErrorCodes::DATA_FAILED, 'Unable to remove item', ['messages' => $this->_getMessages($item->getMessages()), 'item' => $item->toArray()]);
 }
コード例 #4
0
 /**
  * @return \Diff\DiffOp\DiffOp[]
  */
 protected function getDiff()
 {
     $oldModel = $this->oldModel ? $this->oldModel->toArray() : array();
     $newModel = $this->newModel ? $this->newModel->toArray() : array();
     return $this->differ->doDiff($oldModel, $newModel);
 }
コード例 #5
0
ファイル: RESTController.php プロジェクト: phrest/api
 /**
  * Respond with a single model, pass function name
  */
 protected function respondWithModel(Model $model, $functionName = null)
 {
     // Return a partial response
     if ($functionName && isset($this->partialFields)) {
         // Validate that there are fields set for this method
         if (!isset($this->allowedPartialFields[$functionName])) {
             throw new Exception('Partial fields not specified for ' . $functionName);
         }
         // Determines if fields is a strict subset of allowed fields
         if (array_diff($this->partialFields, $this->allowedPartialFields[$functionName])) {
             // todo rework exception
             throw new HTTPException("The fields you asked for cannot be returned.", 401, array('dev' => 'You requested to return fields that are not available to be returned in partial responses.', 'internalCode' => 'P1000', 'more' => ''));
         }
         $this->response->data = $model->toArray($this->partialFields);
     } else {
         $this->response->data = (object) $model->toArray();
         $this->response->getMeta()->count = count($this->response->data);
     }
     // Expand related models
     if ($this->isExpand) {
         // todo allow for parsed related fields, model.field
         foreach ($this->expandFields as $modelField) {
             //$this->response[$modelField] = $model->getRelated($modelField)->toArray();
         }
     }
     return $this->response;
 }