Пример #1
0
 /**
  *
  * @SWG\Api(
  *   path="/admin/users",
  *   description="User related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="POST",
  *       summary="Create new user",
  *       notes="Returns a user based on ID",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="user json",
  *           description="User info",
  *           paramType="body",
  *           required=true,
  *           type="string"
  *         )
  *       )
  *     )
  *   )
  * )
  * @operationName("创建用户")
  * @operationDescription("创建用户")
  */
 public function postAction()
 {
     $data = $this->request->getRawBody();
     if (!$data) {
         throw new Exception\InvalidArgumentException('No data input');
     }
     if (!($data = json_decode($data, true))) {
         throw new Exception\InvalidArgumentException('Data not able to decode as JSON');
     }
     $form = new Forms\UserForm();
     $user = new Models\UserManager();
     $form->setModel($user);
     $form->addForm('profile', 'Eva\\EvaUser\\Forms\\ProfileForm');
     if (!$form->isFullValid($data)) {
         return $this->showInvalidMessagesAsJson($form);
     }
     try {
         $form->save('createUser');
         $data = $user->dump(Models\UserManager::$defaultDump);
         return $this->response->setJsonContent($data);
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $form->getModel()->getMessages());
     }
 }
Пример #2
0
 public function initialize($entity = null, $options = null)
 {
     parent::initialize($entity, $options);
 }