/**
  * Creates a new WebHook entity.
  *
  * @Route("/new", name="webhook_new")
  * @Method({"GET", "POST"})
  *
  * @param Request $request
  *
  * @return RedirectResponse|Response
  */
 public function newAction(Request $request)
 {
     $webHook = new WebHook();
     $form = $this->createForm('AppBundle\\Form\\Type\\WebHookType', $webHook);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $webHook->setUser($this->getUser());
         $em->persist($webHook);
         $em->flush();
         // Create channel in Socket
         $this->socketAdminClient = $this->get('socket_admin_client');
         $this->socketAdminClient->start(function () use($webHook) {
             $this->socketAdminClient->executeAddWebHook($webHook, function () {
                 $this->socketAdminClient->stop();
             }, function ($msg) {
                 $this->socketAdminClient->stop();
                 throw new Exception('Socket error: ' . json_encode($msg));
             });
         });
         return $this->redirectToRoute('webhook_show', ['id' => $webHook->getId()]);
     }
     return $this->render('webhook/new.html.twig', ['webHook' => $webHook, 'form' => $form->createView()]);
 }