POST: Create a new thread.

@param  Request  $request
@return JsonResponse|Response
777051
public function store(Request $request)
    {
        $this->validate($request, [
            'author_id' => ['required', 'integer'],
            'title'     => ['required'],
            'content'   => ['required']
        ]);

        $category = Category::find($request->input('category_id'));

        $this->authorize('createThreads', $category);

        if (!$category->threadsEnabled) {
            return $this->buildFailedValidationResponse($request, trans('forum::validation.category_threads_enabled'));
        }

        $thread = $this->model()->create($request->only(['category_id', 'author_id', 'title']));
        Post::create(['thread_id' => $thread->id] + $request->only('author_id', 'content'));

        return $this->response($thread, 201);
    }
451944
public function createAction(Request $request)
    {
        $filterId = $request->get('filter');
        $handler = $request->get('handler');

        $subscriptionManager = $this->get('phlexible_message.subscription_manager');
        $filterManager = $this->get('phlexible_message.filter_manager');

        $filter = $filterManager->find($filterId);

        $subscription = $subscriptionManager->create()
            ->setUserId($this->getUser()->getId())
            ->setFilter($filter)
            ->setHandler($handler);

        $subscriptionManager->updateSubscription($subscription);

        return new ResultResponse(true, 'Subscription created.');
    }
757728
public function newAction(Request $request)
    {
        $handler = $this->get('lexik_translation.form.handler.trans_unit');

        $form = $this->createForm(TransUnitType::class, $handler->createFormData(), $handler->getFormOptions());

        if ($handler->process($form, $request)) {
            $message = $this->get('translator')->trans('translations.successfully_added', array(), 'LexikTranslationBundle');

            $this->get('session')->getFlashBag()->add('success', $message);

            $redirectUrl = $form->get('save_add')->isClicked() ? 'lexik_translation_new' : 'lexik_translation_grid';

            return $this->redirect($this->generateUrl($redirectUrl));
        }

        return $this->render('@LexikTranslation/Translation/new.html.twig', array(
            'layout' => $this->container->getParameter('lexik_translation.base_layout'),
            'form'   => $form->createView(),
        ));
    }
102930
public function createAction(Request $request): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'create'));
        $form = $this->formFactory->createRole();
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RoleCreateData $data) {
                $roleCreateStruct = $this->roleCreateMapper->reverseMap($data);
                $roleDraft = $this->roleService->createRole($roleCreateStruct);
                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Role '%role%' created.") */
                        'role.create.success',
                        ['%role%' => $roleDraft->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $roleDraft->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/role/add.html.twig', [
            'form' => $form->createView(),
        ]);
    }
349455
public function create(Request $request)
    {
        if ($request->wantsJson()) {
            return $this->validNotFoundJsonResponse();
        }

        $model = new $this->repository->model;

        $view = $this->getViewLocation(__FUNCTION__);
        $this->checkViewExists($view);

        return response()->view($view, compact('model'));
    }
14473
public static function factory(Request $request)
    {
        /** @var Action[] $actions */
        $actions = self::getAllActions($request);

        foreach ($actions as $actionType) {
            if (empty($action)) {
                $action = $actionType;
                continue;
            }

            $posPrevious = self::getPriority($action);
            $posCurrent  = self::getPriority($actionType);

            if ($posCurrent > $posPrevious) {
                $action = $actionType;
            }
        }

        if (!empty($action)) {
            return $action;
        }

        return new ActionPageview($request);
    }
793504
public function createAction(Request $request)
    {
        $inventory = new Inventory();
        $inventory->setStatus(Inventory::STATUS_DRAFT);
        $form = $this->createForm(new InventoryType(), $inventory);
        if ($form->handleRequest($request)->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $this->get('flower.stock.service.inventory')->fillInventory($inventory);
            $em->persist($inventory);
            $em->flush();


            return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
        }

        return array(
            'inventory' => $inventory,
            'form' => $form->createView(),
        );
    }
1191412
public function createBlockAction(Request $request)
    {
        $row = $this->findRowByRequest($request);
        $type = $request->request->get('type', null);

        try {
            $block = $this->getEditor()->createDefaultBlock($type, [], $row);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($row);
        $this->persist($row);

        $viewBuilder = $this->getViewBuilder();

        $data = [
            'created' => $viewBuilder->buildBlock($block)->getAttributes()->getId(),
            'rows'    => [$viewBuilder->buildRow($row)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
416424
public function postAction(Request $request)
    {
        $action = $request->get('action');
        $document = $this->getDocumentManager()->create(self::DOCUMENT_TYPE);
        $locale = $this->getRequestParameter($request, 'locale', true);
        $data = $request->request->all();

        $this->persistDocument($data, $document, $locale);
        $this->handleActionParameter($action, $document, $locale);
        $this->getDocumentManager()->flush();

        return $this->handleView(
            $this->view($document)->setSerializationContext(
                SerializationContext::create()
                    ->setSerializeNull(true)
                    ->setGroups(['defaultPage', 'defaultArticle', 'smallArticlePage'])
            )
        );
    }
787257
public function statusAction(Request $request)
    {
        $taskManager = $this->get('phlexible_task.task_manager');

        $states = $taskManager->getStates();

        return new JsonResponse(['states' => $states]);
    }
481099
public function send(Request $request)
    {
        $ch = curl_init($request->getUrl());
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod());
        curl_setopt($ch, CURLOPT_HTTPHEADER, HttpUtil::formatHeadersForCurl($request->getHeaders()));
        if (!is_null($request->getBody())) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
        }

        curl_setopt_array($ch, $request->getCurlOptions());

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FAILONERROR, false);
        curl_setopt($ch, CURLOPT_HEADER, true);

        list($status, $headers, $body) = HttpUtil::parseResponse(curl_exec($ch));

        return new Response(
            HttpUtil::parseStatus($status),
            HttpUtil::parseHeaders($headers),
            $body,
            curl_getinfo($ch)
        );
    }
79180
public function update(Request $request)
    {
        $action = $request->input('action');

        $thread = $this->api("thread.{$action}", $request->route('thread'))->parameters($request->all())->patch();

        Forum::alert('success', 'threads.updated', 1);

        return redirect(Forum::route('thread.show', $thread));
    }
879579
public function execute(Request $request) : Response
    {
        $host = $request->getHost();
        $socket = new ClientSocket($host, 80);
        $socket->connect();
        $communicator = $socket->getCommunicator();
        $communicator->write($request);
        $communicator->writeLine('');$communicator->writeLine('');
        
        $headers = new Headers();
        $body = ''; 
        
        $headerLine = true;

        $statusLine = $communicator->read(1024, PHP_NORMAL_READ);
        while($line = $communicator->read(5000, PHP_NORMAL_READ)){

            if ($headerLine && $line === PHP_EOL) {
                continue;
            }

            if ($headerLine && ($line === "\r" || $line === PHP_EOL)) {
                $headerLine = false;
                continue;
            }

            if ($headerLine) {
                $headers->add(Header::createFromString($line));
            }else{
                $body .= $line;
            }

        }

        return new Response($body, 200, $headers);
    }
393964
public function show(Request $request)
    {
        $thread = $this->api('thread.fetch', $request->route('thread'))
                       ->parameters(['include_deleted' => auth()->check()])
                       ->get();

        event(new UserViewingThread($thread));

        $category = $thread->category;

        $categories = [];
        if (Gate::allows('moveThreadsFrom', $category)) {
            $categories = $this->api('category.index')->parameters(['where' => ['category_id' => 0]], ['where' => ['enable_threads' => 1]])->get();
        }

        $posts = $thread->postsPaginated;

        return view('forum::thread.show', compact('categories', 'category', 'thread', 'posts'));
    }
1369548
public function sendRequest(Request $request)
    {

        $result = $this->responseFactory->create();
        $client = $this->httpClientFactory->create();

        $apiData = $request->getApiData();
        $apiUrl = $request->getApiUrl();
        $apiKey = $request->getApiKey();
        $requestMethod = $request->getRequestMethod();

        $requestData = $requestMethod !== "GET" ? json_encode($apiData, JSON_UNESCAPED_SLASHES) : null;

        $client->setUri($apiUrl);

        $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);

        $headers =  [
            'User-Agent'            => 'BoltPay/Magento-'.$this->configHelper->getStoreVersion() . '/' . $this->configHelper->getModuleVersion(),
            'X-Bolt-Plugin-Version' => $this->configHelper->getModuleVersion(),
            'Content-Type'          => 'application/json',
            'Content-Length'        => $requestData ? strlen($requestData) : null,
            'X-Api-Key'             => $apiKey,
            'X-Nonce'               => rand(100000000000, 999999999999)
        ] + (array)$request->getHeaders();

        $request->setHeaders($headers);

        $this->bugsnag->registerCallback(function ($report) use ($request) {
            $report->setMetaData([
                'BOLT API REQUEST' => $request->getData()
            ]);
        });

        $client->setHeaders($headers);

        $responseBody = null;

        try {
            $response     = $client->setRawData($requestData, 'application/json')->request($requestMethod);
            $responseBody = $response->getBody();

            $this->bugsnag->registerCallback(function ($report) use ($response) {
                $report->setMetaData([
                    'BOLT API RESPONSE' => [
                        'headers' => $response->getHeaders(),
                        'body'    => $response->getBody(),
                    ]
                ]);
            });

            $this->bugsnag->registerCallback(function ($report) use ($response) {
                $headers = $response->getHeaders();
                $report->setMetaData([
                    'META DATA' => [
                        'bolt_trace_id' => @$headers[ConfigHelper::BOLT_TRACE_ID_HEADER],
                    ]
                ]);
            });
        } catch (\Exception $e) {
            throw new LocalizedException($this->wrapGatewayError($e->getMessage()));
        }

        if ($request->getStatusOnly() && $response) {
            return $response->getStatus();
        }

        if ($responseBody) {
            $resultFromJSON = json_decode($responseBody);
            $jsonError  = $this->handleJsonParseError();
            if ($jsonError != null) {
                $message = __("JSON Parse Error: " . $jsonError);
                throw new LocalizedException($message);
            }

            if ($this->isResponseError($resultFromJSON)) {
                $message = isset($resultFromJSON->errors[0]->message) ? __($resultFromJSON->errors[0]->message) :  __("Bolt API Error Response");
                throw new LocalizedException($message);
            }

            $result->setResponse($resultFromJSON);
        } else {
            throw new LocalizedException(
                __('Something went wrong in the payment gateway.')
            );
        }
        return $result;
    }
1294799
public function newAction(Request $request)
    {
        $role = new Role();
        $form = $this->createForm('CoreBundle\Form\RoleType', $role);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($role);
            $em->flush($role);

            //if come from popup
            if ($request->isXMLHttpRequest()) {         
                return new JsonResponse(array(
                            'id' => $role->getId(), 
                        ));
            }
            $this->get('session')->getFlashBag()->add('success', 'role.created');
            
            return $this->redirectToRoute('core_role_show', array('id' => $role->getId()));
        }

        return array(
            'role' => $role,
            'form' => $form->createView(),
        );
    }
979264
public function post(Request $request)
    {
        // Validate user
        $email = Arr::get($this->getContentAsArray($request), 'email');
        $user  = $this->userService->findByEmail($email);

        if (! $user) {
            return $this->createNotFoundResponse();
        }

        // If a token exists that won't expire in the next 5 minutes, send it
        $token = $this->userService->findTokenBy([
            'user_id'       => $user->getId(),
            'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD,
            ['expires', '>', time() + 5*60],
        ]);

        // Otherwise create a new token
        if (! $token) {
            $token = $this->userService->createUserToken([
                'user_id'       => $user->getId(),
                'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD,
                'expires'       => strtotime('+1 day', time()),
            ]);
        }

        $this->resetPasswordView->setUserToken($token);

        $email = $this->emailService->createFromArray([
            'recipient_email' => $user->getEmail(),
            'subject'         => 'Reset Your Password',
            'message'         => (string) $this->resetPasswordView,
        ]);

        $this->emailService->enqueueSendEmailJob($email);

        return $this->create204Response(204, '');
    }