当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpFoundation\Request类代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postAction

 public function postAction(Request $request)
 {
     $repo = $this->get('tekstove.user.repository');
     /* @var $repo \Tekstove\ApiBundle\Model\User\UserRepository */
     $recaptchaSecret = $this->container->getParameter('tekstove_api.recaptcha.secret');
     $requestData = \json_decode($request->getContent(), true);
     $userData = $requestData['user'];
     $recaptchaData = $requestData['recaptcha'];
     $user = new User();
     try {
         $recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret);
         $recaptchaResponse = $recaptcha->verify($recaptchaData['g-recaptcha-response']);
         if (!$recaptchaResponse->isSuccess()) {
             $recaptchaException = new UserHumanReadableException("Recaptcha validation failed");
             $recaptchaException->addError("recaptcha", "Validation failed");
             throw $recaptchaException;
         }
         $user->setUsername($userData['username']);
         $user->setMail($userData['mail']);
         $user->setPassword($this->hashPassword($userData['password']));
         $user->setapiKey(sha1(str_shuffle(uniqid())));
         $repo->save($user);
     } catch (UserHumanReadableException $e) {
         $view = $this->handleData($request, $e->getErrors());
         $view->setStatusCode(400);
         return $view;
     }
 }
开发者ID:Tekstove,项目名称:Tekstove-api,代码行数:28,代码来源:RegisterController.php

示例2: process

 /**
  * @param FormInterface $form
  * @param Request $request
  * @return AccountUser|bool
  */
 public function process(FormInterface $form, Request $request)
 {
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $email = $form->get('email')->getData();
             /** @var AccountUser $user */
             $user = $this->userManager->findUserByUsernameOrEmail($email);
             if ($this->validateUser($form, $email, $user)) {
                 if (null === $user->getConfirmationToken()) {
                     $user->setConfirmationToken($user->generateToken());
                 }
                 try {
                     $this->userManager->sendResetPasswordEmail($user);
                     $user->setPasswordRequestedAt(new \DateTime('now', new \DateTimeZone('UTC')));
                     $this->userManager->updateUser($user);
                     return $user;
                 } catch (\Exception $e) {
                     $this->addFormError($form, 'oro.email.handler.unable_to_send_email');
                 }
             }
         }
     }
     return false;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:30,代码来源:AccountUserPasswordRequestHandler.php

示例3: indexAction

 /**
  * @Route("/{applicationId}")
  * @Method({"GET", "POST"})
  * @Template()
  * @param Request $request
  * @param $applicationId
  * @return array
  */
 public function indexAction(Request $request, $applicationId)
 {
     // Validate the $applicationId, throws Exception if invalid.
     $application = $this->getApplication($this->irisEntityManager, $applicationId);
     // Get the Case for this Tenant and put in the session, as it's needed throughout
     $case = $this->getCase($this->irisEntityManager, $application->getCaseId());
     $request->getSession()->set('submitted-case', serialize($case));
     // Create an empty ReferencingGuarantor object.
     $guarantor = new ReferencingGuarantor();
     $guarantor->setCaseId($application->getCaseId());
     // Build the form.
     $form = $this->createForm($this->formType, $guarantor, array('guarantor_decorator' => $this->referencingGuarantorDecoratorBridgeSubscriber->getGuarantorDecorator(), 'attr' => array('id' => 'generic_step_form', 'class' => 'referencing branded individual-guarantor-form', 'novalidate' => 'novalidate')));
     // Process a client round trip, if necessary
     if ($request->isXmlHttpRequest()) {
         $form->submit($request);
         return $this->render('BarbonHostedApiLandlordReferenceBundle:NewReference/Guarantor/Validate:index.html.twig', array('form' => $form->createView()));
     }
     // Submit the form.
     $form->handleRequest($request);
     if ($form->isValid()) {
         $case = $this->getCase($this->irisEntityManager, $application->getCaseId());
         // Dispatch the new guarantor reference event.
         $this->eventDispatcher->dispatch(NewReferenceEvents::GUARANTOR_REFERENCE_CREATED, new NewGuarantorReferenceEvent($case, $application, $guarantor));
         // Send the user to the success page.
         return $this->redirectToRoute('barbon_hostedapi_landlord_reference_newreference_guarantor_confirmation_index', array('applicationId' => $applicationId));
     }
     return array('form' => $form->createView());
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:36,代码来源:NewController.php

示例4: action

 /**
  * Perform an action on a Contenttype record.
  *
  * The action part of the POST request should take the form:
  * [
  *     contenttype => [
  *         id => [
  *             action => [field => value]
  *         ]
  *     ]
  * ]
  *
  * For example:
  * [
  *     'pages'   => [
  *         3 => ['modify' => ['status' => 'held']],
  *         5 => null,
  *         4 => ['modify' => ['status' => 'draft']],
  *         1 => ['delete' => null],
  *         2 => ['modify' => ['status' => 'published']],
  *     ],
  *     'entries' => [
  *         4 => ['modify' => ['status' => 'published']],
  *         1 => null,
  *         5 => ['delete' => null],
  *         2 => null,
  *         3 => ['modify' => ['title' => 'Drop Bear Attacks']],
  *     ]
  * ]
  *
  * @param Request $request Symfony Request
  *
  * @return Response
  */
 public function action(Request $request)
 {
     //         if (!$this->checkAntiCSRFToken($request->get('bolt_csrf_token'))) {
     //             $this->app->abort(Response::HTTP_BAD_REQUEST, Trans::__('Something went wrong'));
     //         }
     $contentType = $request->get('contenttype');
     $actionData = $request->get('actions');
     if ($actionData === null) {
         throw new \UnexpectedValueException('No content action data provided in the request.');
     }
     foreach ($actionData as $contentTypeSlug => $recordIds) {
         if (!$this->getContentType($contentTypeSlug)) {
             // sprintf('Attempt to modify invalid ContentType: %s', $contentTypeSlug);
             continue;
         } else {
             $this->app['storage.request.modify']->action($contentTypeSlug, $recordIds);
         }
     }
     $referer = Request::create($request->server->get('HTTP_REFERER'));
     $taxonomy = null;
     foreach (array_keys($this->getOption('taxonomy', [])) as $taxonomyKey) {
         if ($referer->query->get('taxonomy-' . $taxonomyKey)) {
             $taxonomy[$taxonomyKey] = $referer->query->get('taxonomy-' . $taxonomyKey);
         }
     }
     $options = (new ListingOptions())->setOrder($referer->query->get('order'))->setPage($referer->query->get('page_' . $contentType))->setFilter($referer->query->get('filter'))->setTaxonomies($taxonomy);
     $context = ['contenttype' => $this->getContentType($contentType), 'multiplecontent' => $this->app['storage.request.listing']->action($contentType, $options), 'filter' => array_merge((array) $taxonomy, (array) $options->getFilter()), 'permissions' => $this->getContentTypeUserPermissions($contentType, $this->users()->getCurrentUser())];
     return $this->render('@bolt/async/record_list.twig', ['context' => $context]);
 }
开发者ID:Twiebie,项目名称:bolt,代码行数:63,代码来源:Records.php

示例5: postAction

 /**
  * Writes a new Entry to the database
  *
  * @param Request $request Current http request
  *
  * @return \Symfony\Component\HttpFoundation\Response $response Result of action with data (if successful)
  */
 public function postAction(Request $request)
 {
     $response = $this->getResponse();
     $entityClass = $this->getModel()->getEntityClass();
     $record = new $entityClass();
     // Insert the new record
     $record = $this->getModel()->insertRecord($record);
     // store id of new record so we dont need to reparse body later when needed
     $request->attributes->set('id', $record->getId());
     $file = $this->saveFile($record->getId(), $request->getContent());
     // update record with file metadata
     $meta = new FileMetadata();
     $meta->setSize((int) $file->getSize())->setMime($request->headers->get('Content-Type'))->setCreatedate(new \DateTime());
     $record->setMetadata($meta);
     $record = $this->getModel()->updateRecord($record->getId(), $record);
     // Set status code and content
     $response->setStatusCode(Response::HTTP_CREATED);
     $routeName = $request->get('_route');
     $routeParts = explode('.', $routeName);
     $routeType = end($routeParts);
     if ($routeType == 'post') {
         $routeName = substr($routeName, 0, -4) . 'get';
     }
     $response->headers->set('Location', $this->getRouter()->generate($routeName, array('id' => $record->getId())));
     return $response;
 }
开发者ID:smoskalenko,项目名称:graviton,代码行数:33,代码来源:FileController.php

示例6: indexAction

 /**
  * Reference purchase summary
  *
  * @Route()
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $previouslyPostedData = null;
     // if we are not posting new data, and a request for $this->formType is stored in the session, prepopulate the form with the stored request
     $storedRequest = unserialize($request->getSession()->get($this->formType->getName()));
     if ($request->isMethod('GET') && $storedRequest instanceof Request) {
         $previouslyPostedData = $this->createForm($this->formType)->handleRequest($storedRequest)->getData();
     }
     $form = $this->createForm($this->formType, $previouslyPostedData);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             // Persist the case to IRIS
             /** @var ReferencingCase $case */
             $case = $form->getData()['case'];
             $this->irisEntityManager->persist($case);
             /** @var ReferencingApplication $application */
             foreach ($case->getApplications() as $application) {
                 // Always default
                 $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION);
                 $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId()));
                 // Persist each guarantor of the application
                 if (null !== $application->getGuarantors()) {
                     foreach ($application->getGuarantors() as $guarantor) {
                         $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId()));
                     }
                 }
             }
             $request->getSession()->set('submitted-case', serialize($case));
             // Send the user to the success page
             return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_newreference_tenancyagreement_index'), 301);
         }
     }
     return array('form' => $form->createView());
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:45,代码来源:NewController.php

示例7: addAction

 /**
  *@Security("has_role('ROLE_USER')")
  */
 public function addAction(Request $request, Intervention $intervention)
 {
     $em = $this->getDoctrine()->getManager();
     $intervention = $em->getRepository('MdyGstBundle:Intervention')->find($intervention->getId());
     if ($intervention == null) {
         throw new NotFoundHttpException("La demande [" . $id . "] n'a pas été trouvée.");
     }
     $remarque = new Remarque();
     $remarque->setIntervention($intervention);
     $user = $this->container->get('security.context')->getToken()->getUser();
     $remarque->setAuteur($user);
     $form = $this->get('form.factory')->create(new RemarqueType(), $remarque);
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             $this->get('session')->getFlashBag()->add('confirm', 'La remarque a été ajoutée avec succès !');
             $em->persist($remarque);
             $em->flush();
             return $this->redirect($this->generateUrl('mdy_gst_listIntervention'));
         } else {
             $request->getSession()->getFlashBag()->add('info', 'Le formulaire n\'est pas valide !');
         }
     }
     return $this->render('MdyGstBundle:Gst:Remarque/add.html.twig', array('form' => $form->createView()));
 }
开发者ID:rthreis,项目名称:GST,代码行数:28,代码来源:RemarqueController.php

示例8: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // The Content-type header does not make sense on GET requests, because GET
     // requests do not carry any content. Nothing to filter in this case.
     if ($request->isMethod('GET')) {
         return $collection;
     }
     $format = $request->getContentType();
     foreach ($collection as $name => $route) {
         $supported_formats = array_filter(explode('|', $route->getRequirement('_content_type_format')));
         if (empty($supported_formats)) {
             // No restriction on the route, so we move the route to the end of the
             // collection by re-adding it. That way generic routes sink down in the
             // list and exact matching routes stay on top.
             $collection->add($name, $route);
         } elseif (!in_array($format, $supported_formats)) {
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     // We do not throw a
     // \Symfony\Component\Routing\Exception\ResourceNotFoundException here
     // because we don't want to return a 404 status code, but rather a 415.
     throw new UnsupportedMediaTypeHttpException('No route found that matches "Content-Type: ' . $request->headers->get('Content-Type') . '"');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:ContentTypeHeaderMatcher.php

示例9: newarticleAction

 public function newarticleAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $article = new Article();
     $form = $this->createForm(new ArticleType($em), $article);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         $thumbnail = $article->getThumbnail();
         $thumbnailName = md5(uniqid()) . '.' . $thumbnail->guessExtension();
         $thumbnailDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/thumbnail';
         $thumbnail->move($thumbnailDir, $thumbnailName);
         $article->setThumbnail('uploads/thumbnail/' . $thumbnailName);
         $banner = $article->getBanner();
         $bannerName = md5(uniqid()) . '.' . $banner->guessExtension();
         $bannerDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/banner';
         $banner->move($bannerDir, $bannerName);
         $article->setBanner('uploads/banner/' . $bannerName);
         $article->setDate(new \DateTime("now"));
         $article->setUser($this->get('security.token_storage')->getToken()->getUser());
         if (!$form->isValid()) {
             return $this->redirectToRoute('aved_new_article');
         }
         $em->persist($article);
         $em->flush();
         return $this->redirectToRoute('aved_new_article');
     }
     return $this->render('AvedBlogBundle:Default:new_article.html.twig', array('form' => $form->createView()));
 }
开发者ID:Association-Vie-Etudiante-Descartes,项目名称:site-aved-prod,代码行数:28,代码来源:DefaultController.php

示例10: add

 public function add(Application $app, Request $request)
 {
     $productClassId = $request->get('product_class_id');
     $quantity = $request->request->has('quantity') ? $request->get('quantity') : 1;
     $app['eccube.service.cart']->addProduct($productClassId, $quantity)->save();
     return $app->redirect($app->url('cart'));
 }
开发者ID:noadless,项目名称:ec-cube,代码行数:7,代码来源:CartController.php

示例11: loginAction

 /**
  * @Route("/login", name="plusbelle_login")
  * @Template()
  */
 public function loginAction(Request $request)
 {
     $session = $request->getSession();
     if (class_exists('\\Symfony\\Component\\Security\\Core\\Security')) {
         $authErrorKey = Security::AUTHENTICATION_ERROR;
         $lastUsernameKey = Security::LAST_USERNAME;
     } else {
         // BC for SF < 2.6
         $authErrorKey = SecurityContextInterface::AUTHENTICATION_ERROR;
         $lastUsernameKey = SecurityContextInterface::LAST_USERNAME;
     }
     // get the error if any (works with forward and redirect -- see below)
     if ($request->attributes->has($authErrorKey)) {
         $error = $request->attributes->get($authErrorKey);
     } elseif (null !== $session && $session->has($authErrorKey)) {
         $error = $session->get($authErrorKey);
         $session->remove($authErrorKey);
     } else {
         $error = null;
     }
     if (!$error instanceof AuthenticationException) {
         $error = null;
         // The value does not come from the security component.
     }
     // last username entered by the user
     $lastUsername = null === $session ? '' : $session->get($lastUsernameKey);
     //ladybug_dump($error);
     return array('last_username' => $lastUsername, 'error' => $error);
     /*ladybug_dump($error);
       return array(
           'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
           'errors'         => $error,
       );*/
 }
开发者ID:samrodriguez,项目名称:plusbella,代码行数:38,代码来源:SecuredController.php

示例12: indexAction

 /**
  * @Route("/report", name="report", methods={"GET", "POST"} )
  */
 public function indexAction(Request $request)
 {
     $fromDate = $request->get('fromDate') ?: '1 month ago';
     $toDate = $request->get('toDate') ?: 'now';
     $parameters = array('timeEntriesGroupedByDate' => $this->getDoctrine()->getRepository('AppBundle:TimeEntry')->getTimeEntriesGroupedByDayForDates($fromDate, $toDate), 'fromDate' => new \DateTime($fromDate), 'toDate' => new \DateTime($toDate));
     return $this->render('::report.html.twig', $parameters);
 }
开发者ID:avanthay,项目名称:timekipr,代码行数:10,代码来源:ReportControllerController.php

示例13: editAction

 /**
  * @param $id
  * @param Request     $request
  * @param Application $app
  *
  * @return Response
  */
 public function editAction($id, Request $request, Application $app)
 {
     if (!$app['security']->isGranted('ROLE_POSTS_EDITOR') && !$app['security']->isGranted('ROLE_ADMIN')) {
         $app->abort(403);
     }
     $post = $app['orm.em']->find('Application\\Entity\\PostEntity', $id);
     if (!$post) {
         $app->abort(404);
     }
     $form = $app['form.factory']->create(new PostType(), $post);
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $postEntity = $form->getData();
             if ($postEntity->getRemoveImage()) {
                 $postEntity->setImageUrl(null);
             }
             /*** Image ***/
             $postEntity->setImageUploadPath($app['baseUrl'] . '/assets/uploads/')->setImageUploadDir(WEB_DIR . '/assets/uploads/')->imageUpload();
             $app['orm.em']->persist($postEntity);
             $app['orm.em']->flush();
             $app['flashbag']->add('success', $app['translator']->trans('The post was successfully edited!'));
             return $app->redirect($app['url_generator']->generate('members-area.posts.edit', array('id' => $postEntity->getId())));
         }
     }
     return new Response($app['twig']->render('contents/members-area/posts/edit.html.twig', array('form' => $form->createView(), 'post' => $post)));
 }
开发者ID:bobalazek,项目名称:web-application-starter-kit,代码行数:34,代码来源:PostsController.php

示例14: indexAction

 /**
  * Render the provided content.
  *
  * When using the publish workflow, enable the publish_workflow.request_listener
  * of the core bundle to have the contentDocument as well as the route
  * checked for being published.
  * We don't need an explicit check in this method.
  *
  * @param Request $request
  * @param object  $contentDocument
  * @param string  $contentTemplate Symfony path of the template to render
  *                                 the content document. If omitted, the
  *                                 default template is used.
  *
  * @return Response
  */
 public function indexAction(Request $request, $contentDocument, $contentTemplate = null)
 {
     $contentTemplate = $contentTemplate ?: $this->defaultTemplate;
     $contentTemplate = str_replace(array('{_format}', '{_locale}'), array($request->getRequestFormat(), $request->getLocale()), $contentTemplate);
     $params = $this->getParams($request, $contentDocument);
     return $this->renderResponse($contentTemplate, $params);
 }
开发者ID:kea,项目名称:PUGXCmfPageBundle,代码行数:23,代码来源:GenericController.php

示例15: mobileSelectAction

 public function mobileSelectAction(Request $request)
 {
     $operationMobile = $this->getSettingService()->get('operation_mobile', array());
     $courseGrids = $this->getSettingService()->get('operation_course_grids', array());
     $settingMobile = $this->getSettingService()->get('mobile', array());
     $default = array('courseIds' => '');
     $mobile = array_merge($default, $courseGrids);
     if ($request->getMethod() == 'POST') {
         $courseGrids = $request->request->all();
         $mobile = array_merge($operationMobile, $settingMobile, $courseGrids);
         $this->getSettingService()->set('operation_mobile', $operationMobile);
         $this->getSettingService()->set('operation_course_grids', $courseGrids);
         $this->getSettingService()->set('mobile', $mobile);
         $this->getLogService()->info('system', 'update_settings', "更新移动客户端设置", $mobile);
         $this->setFlashMessage('success', '移动客户端设置已保存!');
     }
     $courseIds = explode(",", $mobile['courseIds']);
     $courses = $this->getCourseService()->findCoursesByIds($courseIds);
     $courses = ArrayToolkit::index($courses, 'id');
     $sortedCourses = array();
     foreach ($courseIds as $value) {
         if (!empty($value)) {
             $sortedCourses[] = $courses[$value];
         }
     }
     return $this->render('TopxiaAdminBundle:System:course-select.html.twig', array('mobile' => $mobile, 'courses' => $sortedCourses));
 }
开发者ID:ZHONG-GUO,项目名称:EduSoho,代码行数:27,代码来源:MobileController.php


注:本文中的Symfony\Component\HttpFoundation\Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。