/** * @param Request $request * @Rest\Post("/create") * * @return mixed */ public function createAction(Request $request) { $account = $this->getAccount(); $application = new Application(); $application->setUsername($request->request->get('name')); $application->setEnabled(true); $application->setAccount($account); /** @var ApplicationManager $manager */ $manager = $this->get('cowtent.account.application.manager'); $manager->updateCanonicalFields($application); $manager->generateApiKey($application); try { $em = $this->getDoctrine()->getManager(); $em->persist($application); $em->flush(); } catch (\Exception $e) { return array(get_class($e), $e->getCode(), $e->getMessage()); } return $application; }