コード例 #1
0
 /**
  * Constructor for this ApiWriteOperation.
  * 
  * @param \sfAltumoPlugin\Api\ApiRequest $request
  * @param \sfAltumoPlugin\Api\ApiResponse $response
  * @param \ModelCriteria $query              // Base query to use in order to retrieve objects that will be deleted.
  * @param function $delete_object           // the function to call in order to perform the delete operation.
  * 
  * @return \sfAltumoPlugin\Api\ApiGetQuery
  */
 public function __construct($request, $response, $query, $delete_object = null)
 {
     if (is_null($delete_object)) {
         $delete_object = function (&$object) {
             return $object->delete();
         };
     }
     $response_body = new \sfAltumoPlugin\Api\ApiResponseBody(array(), $body_name, $pager);
     $response->setResponseBody($response_body);
     $this->setRequest($request);
     $this->setResponse($response);
     $this->setQuery($query);
     $this->setDeleteObject($delete_object);
 }
コード例 #2
0
ファイル: ApiGetQuery.php プロジェクト: homer6/sfAltumoPlugin
 /**
  * Constructor for this ApiGetQuery.
  * 
  * @param \sfAltumoPlugin\Api\ApiRequest $request
  * @param \sfAltumoPlugin\Api\ApiResponse $response
  * @param \ModelCriteria $query
  * @param string $body_name
  * @param function $modify_result
  * 
  * @return \sfAltumoPlugin\Api\ApiGetQuery
  */
 public function __construct($request, $response, $query, $body_name, $modify_result = null)
 {
     if (is_null($modify_result)) {
         $modify_result = function (&$model, &$result) {
         };
     }
     $pager = new \sfAltumoPlugin\Api\ApiPager(true, $request);
     $response_body = new \sfAltumoPlugin\Api\ApiResponseBody(array(), $body_name, $pager);
     $response->setResponseBody($response_body);
     $this->setRequest($request);
     $this->setResponse($response);
     $this->setQuery($query);
     $this->setPager($pager);
     $this->setModifyResult($modify_result);
 }
コード例 #3
0
 /**
  * This method calls the setters on the provided $model with the values from 
  * $request_object, according to the $field_maps.
  * 
  * @param boolean $update
  *   //PUT (update) request if true, POST (create) if false
  * 
  * @param \sfAltumoPlugin\Api\ApiResponse $response
  *   //the response that will contain the errors
  * 
  * @param \BaseObject $model
  *   //the model the is having its accessors called
  * 
  * @param array $field_maps
  *   //the field maps from $request_object array keys to $model accessors
  * 
  * @param mixed $request_object
  *   //the array that contains the fields the will be placed into the model
  * 
  * @param integer $remote_id
  *   //the remote_id of the record being referenced. If this is null, the
  *     $request_object must contain it
  * 
  * @throws \Exception
  *   //if the accessor method doesn't exist
  * 
  * @throws \Exception                    
  *   //if the accessor method doesn't exist
  * 
  * @throws \Exception                    
  *   //if the field is required and couldn't be found in $request_object
  * 
  * @throws \Exception
  *   //if $remote_id is not an integer
  * 
  * @return array 
  *   //an array of $type objects (models)
  */
 public static function callObjectSetters($update, $response, $model, &$field_maps, &$request_object, $remote_id = null)
 {
     foreach ($field_maps as $field_map) {
         //validate the accessor
         $accessor_suffix = $field_map->getModelAccessor();
         $setter_method = 'set' . $accessor_suffix;
         $getter_method = 'get' . $accessor_suffix;
         if (!method_exists($model, $setter_method)) {
             continue;
             //skip it if method doesn't exist
             throw new \Exception('Accessor method does not exist: ' . $setter_method);
         }
         //validate the remote_id
         if (is_null($remote_id)) {
             if (!array_key_exists('remote_id', $request_object)) {
                 throw new \Exception('The request_object must have a remote_id');
             } else {
                 $remote_id = $request_object['remote_id'];
             }
         } else {
             $remote_id = \Altumo\Validation\Numerics::assertPositiveInteger($remote_id);
         }
         //validate that the field exists in the request
         //don't worry about the field not being there if this is an update
         $field_key = $field_map->getRequestField();
         if (!array_key_exists($field_key, $request_object)) {
             if (!$update) {
                 if ($field_map->isRequired()) {
                     $response->addError('Field does not exist: ' . $field_map->getDescription(), $remote_id, $field_map);
                 }
             }
             continue;
         }
         //invoke the setter and attach error, if there is one
         try {
             call_user_func_array(array($model, $setter_method), array($request_object[$field_key]));
         } catch (\Exception $e) {
             $response->addError($e->getMessage(), $remote_id, $field_map);
         }
     }
 }