@param FormTypeInterface $type
@param Request $request

@throws NotFoundHttpException

@return Response
551713
private function handleRequest(FormTypeInterface $type, Request $request)
    {
        $image = new Image();

        $form = $this->createForm($type, $image, [
            'method' => 'POST',
        ]);

        $form->handleRequest($request);

        if (!$form->isValid()) {
            throw $this->createNotFoundException('Invalid request' . $form->getErrorsAsString());
        }

        $em = $this->getDoctrine()->getManager();
        $em->persist($image);
        $em->flush();

        return new Response($this->get('serializer')->serialize(['image' => $image], $request->attributes->get('_format')));
    }
275607
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $router = $this->container['internal.route_collection'];
        foreach ($this->container['routes'] as $route) {
            $this->buildRoute($router, $route);
        }

        /** @var RequestContext $requestContext */
        $requestContext = $this->container['internal.request_context'];
        $requestContext->fromRequest($request);

        /** @var ControllerResolver $controllerResolver */
        $controllerResolver = $this->container['internal.controller_resolver'];
        $request->attributes->add($controllerResolver->resolve($request));

        $controller = $request->attributes->get('_controller');
        try {
            $controller = $this->container[$controller];
        } catch (\Exception $exception) {
            $controller = new $controller();
        }

        $request->attributes->set('_controller', $controller);

        return $this->app->handle($request, $type, $catch);
    }
612172
public function createAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $refFolder = $this->findFolderById($request->attributes->get('id'));
        $repo = $this->getFolderRepository();

        $newFolder = $repo->createNew();
        $newFolder->setName('New folder');

        $mode = strtolower($request->request->get('mode'));
        if (!in_array($mode, array('child', 'after'))) {
            $response = new Response(json_encode(array(
                'error'   => true,
                'message' => 'Unexpected creation mode.',
            ), JSON_FORCE_OBJECT));
        } else {
            if ($mode === 'after') {
                $repo->persistAsNextSiblingOf($newFolder, $refFolder);
            } else {
                $repo->persistAsFirstChildOf($newFolder, $refFolder);
            }

            if (true !== $message = $this->validateFolder($newFolder)) {
                $response = new Response(json_encode(array(
                    'error'   => true,
                    'message' => $message,
                ), JSON_FORCE_OBJECT));
            } else {
                $this->getEntityManager()->flush();
                $data = $this->get('jms_serializer')->serialize(
                    $newFolder,
                    'json',
                    SerializationContext::create()->setGroups(array('Manager'))
                );
                $response = new Response(sprintf('{"node":%s}', $data));
            }
        }

        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
1281885
private function handlePostLogin(Request $request, FormInterface $form)
    {
        $event = new AccessControlEvent($request);
        $username = $form->get('username')->getData();
        $password = $form->get('password')->getData();

        if (!$this->login()->login($username, $password, $event)) {
            return null;
        }

        // Authentication data is cached in the session and if we can't get it
        // now, everyone is going to have a bad day. Make that obvious.
        if (!$token = $this->session()->get('authentication')) {
            $this->flashes()->error(Trans::__('general.phrase.error-session-data-login'));

            return null;
        }

        // Log in, if credentials are correct.
        $this->app['logger.system']->info('Logged in: ' . $username, ['event' => 'authentication']);

        $retreat = $this->session()->get('retreat', ['route' => 'dashboard', 'params' => []]);
        $response = $this->setAuthenticationCookie($request, $this->redirectToRoute($retreat['route'], $retreat['params']), (string) $token);

        return $response;
    }
540743
public function process(Request $request, FormInterface $form)
    {
        if ($request->isMethod('POST')) {
            $form->submit($request);
            if ($form->isValid()) {
                /** @var TextInterface $text */
                $text = $form->getData();
                foreach ($text->getTranslations() as $translation) {
                    $translation->setText($text);
                }
                $this->textManager->add($form->getData());

                return true;
            }
        }

        return false;
    }
576536
public function createAction(Request $request)
    {
        $formManager = $this->get('opifer.form.form_manager');

        $form = $formManager->create();

        $formType = $this->createForm(FormType::class, $form);
        $formType->handleRequest($request);

        if ($formType->isSubmitted() && $formType->isValid()) {
            foreach ($formType->getData()->getSchema()->getAttributes() as $attribute) {
                $attribute->setSchema($form->getSchema());

                foreach ($attribute->getOptions() as $option) {
                    $option->setAttribute($attribute);
                }
            }

            $formManager->save($form);

            $this->addFlash('success', 'Form has been created successfully');

            return $this->redirectToRoute('opifer_form_form_edit', ['id' => $form->getId()]);
        }

        return $this->render($this->getParameter('opifer_form.form_create_view'), [
            'form' => $form,
            'form_form' => $formType->createView(),
        ]);
    }
1301187
protected function filterResponse($request, $type="text/*", $callback)
	{
		$response = $this->controller->execute($request);
		$array = call_user_func_array($callback, array(
			$response->getStatus(),
			$response->getHeaders(),
			$response->getBody()
			));

		return new Http\Response($array[0], $array[1], $array[2]);
	}
886079
public function editAction($id, Request $request)
    {
        $template = $this->container->get('synapse.template.orm_loader')
            ->retrieveOne(array(
                'id' => $id,
                'scope' => TemplateInterface::GLOBAL_SCOPE
            ))
        ;
        if (!$template) {
            throw new NotFoundHttpException(sprintf('No global template found for id "%s"', $id));
        }

        $form = $this->container->get('form.factory')->createNamed(
            'template',
            TemplateType::class,
            $template,
            array(
                'theme' => $request->attributes->get(
                    'synapse_theme',
                    $this->container->get('synapse')
                        ->enableDefaultTheme()
                        ->getCurrentTheme()
                ),
                'content_type' => $template->getContentType(),
                'template_type' => $template->getTemplateType(),
                'action' => $formUrl = $this->container->get('router')->generate(
                    'synapse_admin_template_edition',
                    array('id' => $template->getId())
                ),
                'method' => 'POST',
                'csrf_protection' => false,
            )
        );
        if ($request->request->has('template')) {
            $form->handleRequest($request);
            if ($form->isValid()) {
                return $this->redirect(
                    $this->container->get('router')->generate(
                        'synapse_admin_template_edition',
                        array('id' => $template->getId())
                    )
                );
            }
        }

        return $this->render('SynapseAdminBundle:Template:edit.html.twig', array(
            'template' => $template,
            'form' => $form->createView(),
        ));
    }
1148767
public function create($type, Request $request)
    {
        if ($type && $product = $this->productManager->findByNamespace($type)) {
            $categories = $this->category->all()->nest()->listsFlattened('name');
            $shops = $this->shop->all();
            $optionTypes = $this->optionManager->all();

            return view('product::admin.products.create', compact('product', 'categories', 'shops', 'optionTypes'));
        }

        // If type is not exists, default type will be set
        $first = $this->productManager->first();

        return redirect()->route($request->route()->getName(), ['type' => $first->getEntityNamespace()]);
    }
457499
protected function submitForm(FormInterface $form, Request $request)
    {
        $bag = $request->isMethod('GET') || $form->getConfig()->getMethod() === 'GET'
            ? $request->query
            : $request->request;

        if ($this->getParameterResolver()->resolveApi()) {
            $data = array_merge($bag->all(), $request->files->all());
        } else {
            $data = array_merge($bag->get($form->getName(), []), $request->files->get($form->getName(), []));
        }

        array_walk_recursive($data, function (&$value) {
            if ($value === false) {
                $value = 'false';
            }
        });

        return $form->submit($data, !$request->isMethod('PATCH'));
    }
287565
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $templateEngine = $this->container['internal.template'];
        if ($templateEngine instanceof \Twig_Environment) {
            $templateEngine->addExtension(new TwigFilterExtension());
        }

        return $this->app->handle($request, $type, $catch);
    }
1360905
public function changeTypeAction(Request $request)
    {
        $container = $this->findContainerByRequest($request);

        $type = $request->request->get('type', null);

        $data = [];

        if ($type != $container->getType()) {
            try {
                $removed = $this->getEditor()->getContainerManager()->changeType($container, $type);
            } catch (EditorExceptionInterface $e) {
                return $this->handleException($e);
            }

            if (!empty($removed)) {
                $data['removed'] = $removed;
            }

            $this->validate($container);
            $this->persist($container);
        }

        $data['containers'] = [$this->getViewBuilder()->buildContainer($container)];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
198989
public function submitAction(Request $request, $id)
    {
        $form = $this->get('opifer.form.form_manager')->getRepository()->find($id);

        if (!$form) {
            throw $this->createNotFoundException('The form could not be found');
        }

        $post = $this->get('opifer.eav.eav_manager')->initializeEntity($form->getSchema());
        $post->setForm($form);

        $postForm = $this->createForm(PostType::class, $post, ['form_id' => $id]);
        $postForm->handleRequest($request);

        if ($postForm->isSubmitted() && $postForm->isValid()) {
            $this->get('opifer.form.post_manager')->save($post);

            $event = new FormSubmitEvent($post);
            $this->get('event_dispatcher')->dispatch(Events::POST_FORM_SUBMIT, $event);
            
            if ($form->getRedirectUrl()) {
                return $this->redirect($form->getRedirectUrl());
            }
        }

        return $this->redirect($request->headers->get('referer'));
    }
591038
public function listAction(Request $request, $type = null)
    {
        $this->type = $type;

        return parent::listAction($request);
    }
851959
public function handle(Request $request, $type = self::MASTER_REQUEST)
    {
        try {
            $response = $this->handleRequest($request, $type);
        } catch (\Exception $e) {
            $response = $this->handleException($e, $request, $type);
        }

        return $response;
    }
746079
private function checkType(Request $request)
    {
        $type = 'view';
        if ($request->is('*/create')) {
            $type = 'create';
        } elseif ($request->is('*/edit/*') || $request->is('*/update/*')) {
            $type = 'update';
        } elseif ($request->is('*/delete/*')) {
            $type = 'delete';
        } elseif ($request->is('*/store') && $request->isMethod('post')) {
            if ($request->has('id')) {
                $type = 'update';
            } else {
                $type = 'create';
            }
        }
        
        return $type;
    }
225344
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
    {
        if ($type == HttpKernelInterface::SUB_REQUEST) {
            $request->query->add(
                array_merge(
                    $_POST,
                    $_GET,
                    $request->query->all()
                )
            );
        } else {
            $this->container['request'] = $request;
        }

        return parent::handle($request, $type, $catch);
    }