public function setContent($content) { if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) { throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content))); } $this->content = (string) $content; return $this; }
/** * @Route("/edit/{user}",name="registration_admin_edit") */ public function editAction(Request $request, $user) { $response = new Response(); $em = $this->getDoctrine()->getManager(); $form = $this->createForm(EditType::class); $form->handleRequest($request); $user = $em->getRepository(RegUser::class)->findOneByUsername($user); if ($form->isValid()) { $data = $form->getData(); if ($data['action'] === true) { $password = new Password(); $password->setHash($user->getPasswordHash()); $password->setId('default'); $password->setEncoder(CryptEncoder::class); $userLdap = $this->get('cloud.ldap.util.usermanipulator')->createUserObject($user->getUsername(), $password); $userLdap->setAltEmail($user->getAltEmail()); $userLdap->setGpgPublicKey($user->getGpgPublicKey()); $this->get('cloud.ldap.util.usermanipulator')->create($userLdap); $em->remove($user); } elseif ($data['action'] === false) { $em->remove($user); } else { $response->setStatusCode(400); return $response; } $em->flush(); } else { $response->setContent(json_encode(['successfully' => false, 'error' => $form->getErrors(true)->__toString()])); return $response; } $response->setContent(json_encode(['successfully' => true])); return $response; }