示例#1
0
 /**
  * @param Request $request
  * @param array $params
  * @return Reply
  */
 public function Delete(Request $request, $params = [])
 {
     // $request is unused in this implementation
     $request = null;
     if (empty($params)) {
         // cannot delete if we don't have an id
         return new Reply(422, ['error' => 'ID is required for DELETE operation.']);
     } else {
         if ($this->authUserFilter && !isset($this->authUser)) {
             return new Reply(403, ['error' => 'Must be logged in to access this resource.']);
         }
         $id = $params[0];
         $delete = $this->mapper->GetOneById($id);
         if ($this->authUserFilter) {
             if ($delete->{$this->authUserIDProperty} !== $this->authUser->GetID()) {
                 $delete = null;
             }
         }
         if (!isset($delete)) {
             return new Reply(403, ['error' => 'Must be logged in to access this resource.']);
         } else {
             $this->mapper->Delete($delete);
             return new Reply(204, ['success' => 'The item was deleted.']);
         }
     }
 }
示例#2
0
 public function __construct(MapperFactory $mapperFactory, Connection $reader, Connection $writer = null)
 {
     parent::__construct($mapperFactory, $reader, $writer);
     if (!$this->model instanceof User) {
         throw new ModelException(sprintf('The model %s must be an instance of a class extended from Fluxoft\\Rebar\\Auth\\User', $this->modelClass));
     }
     $this->userModel = $this->model;
 }