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


PHP Request::getMethod方法代码示例

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


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

示例1: indexAction

 public function indexAction(Request $request)
 {
     $debug = "DEBUG: indexAction()";
     $response = null;
     // $request  = $this->getRequest(); Symfony2
     $form = $this->createFormBuilder()->add('url', TextType::class, array('attr' => array('placeholder' => 'ef0bdd815d2a39741c4c30842b7f9488', 'class' => 'input-lg')))->getForm();
     $debug .= " ; " . print_r($request->getMethod(), true);
     if ($request->getMethod() == 'POST') {
         $debug .= " ; POST OK";
         dump("OK");
         $form->handleRequest($request);
         if ($form->isValid()) {
             $debug .= " ; FormIsValid";
             $params = array('apikey' => 'xoxo', 'url' => $form->get('url')->getData());
             // Call internal api
             $url = $this->generateUrl('tweet_count_api_url', array(), true);
             $url .= '?' . http_build_query($params);
             dump($url);
             $curl = curl_init($url);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($curl);
             curl_close($curl);
             $debug .= " ; URL:{$url}";
             if ($response !== null) {
                 $response = json_decode($response);
             }
         }
     }
     return $this->render('TweetCountWebsiteBundle:Default:index.html.twig', array('form' => $form->createView(), 'response' => $response, 'debug' => $debug));
 }
开发者ID:Headoo,项目名称:Tweetcount,代码行数:30,代码来源:DefaultController.php

示例2: process

 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:EmailTemplateHandler.php

示例3: process

 /**
  * @param LineItem $lineItem
  *
  * @return bool
  */
 public function process(LineItem $lineItem)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /** @var LineItemRepository $lineItemRepository */
             $lineItemRepository = $this->manager->getRepository('OroB2BShoppingListBundle:LineItem');
             $existingLineItem = $lineItemRepository->findDuplicate($lineItem);
             if ($existingLineItem) {
                 $existingLineItem->setQuantity($lineItem->getQuantity() + $existingLineItem->getQuantity());
                 $existingLineItemNote = $existingLineItem->getNotes();
                 $newNotes = $lineItem->getNotes();
                 $notes = trim(implode(' ', [$existingLineItemNote, $newNotes]));
                 if ($notes) {
                     $existingLineItem->setNotes($notes);
                 }
                 $this->savedId = $existingLineItem->getId();
             } else {
                 $this->manager->persist($lineItem);
             }
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:31,代码来源:LineItemHandler.php

示例4: attemptAuthentication

 /**
  * {@inheritdoc}
  */
 protected function attemptAuthentication(Request $request)
 {
     if ($this->options['post_only'] && 'post' !== strtolower($request->getMethod())) {
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Authentication method not supported: %s.', $request->getMethod()));
         }
         return null;
     }
     if (null !== $this->csrfProvider) {
         $csrfToken = $request->get($this->options['csrf_parameter'], null, true);
         if (false === $this->csrfProvider->isCsrfTokenValid($this->options['intention'], $csrfToken)) {
             throw new InvalidCsrfTokenException('Invalid CSRF token.');
         }
     }
     if (null !== $this->recaptcha && false === $this->recaptchaDisabled) {
         try {
             if (true !== $this->recaptcha->checkAnswer($request->server->get('REMOTE_ADDR'), $request->get($this->recaptcha->getChallengeField()), $request->get($this->recaptcha->getResponseField()))) {
                 throw new InvalidRecaptchaException('Invalid captcha.');
             }
         } catch (Exception $e) {
             throw new AuthenticationException('Invalid captcha.', null, null, $e);
         }
     }
     $username = trim($request->get($this->options['username_parameter'], null, true));
     $password = $request->get($this->options['password_parameter'], null, true);
     $request->getSession()->set(SecurityContextInterface::LAST_USERNAME, $username);
     return $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $password, $this->providerKey));
 }
开发者ID:plozmun,项目名称:RecaptchaBundle,代码行数:31,代码来源:RecaptchaFormAuthenticationListener.php

示例5: process

 /**
  * @param LineItem $lineItem
  *
  * @return bool
  */
 public function process(LineItem $lineItem)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         /** @var EntityManagerInterface $manager */
         $manager = $this->registry->getManagerForClass('OroB2BShoppingListBundle:LineItem');
         $manager->beginTransaction();
         // handle case for new shopping list creation
         $formName = $this->form->getName();
         $formData = $this->request->request->get($formName, []);
         if (empty($formData['shoppingList']) && !empty($formData['shoppingListLabel'])) {
             $shoppingList = $this->shoppingListManager->createCurrent($formData['shoppingListLabel']);
             $formData['shoppingList'] = $shoppingList->getId();
             $this->request->request->set($formName, $formData);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /** @var LineItemRepository $lineItemRepository */
             $lineItemRepository = $manager->getRepository('OroB2BShoppingListBundle:LineItem');
             $existingLineItem = $lineItemRepository->findDuplicate($lineItem);
             if ($existingLineItem) {
                 $this->updateExistingLineItem($lineItem, $existingLineItem);
             } else {
                 $manager->persist($lineItem);
             }
             $manager->flush();
             $manager->commit();
             return true;
         } else {
             $manager->rollBack();
         }
     }
     return false;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:38,代码来源:LineItemHandler.php

示例6: process

 /**
  * Process form
  *
  * @param  Task $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Task $entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
     $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
     if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
         $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'owner', ['read_only' => true]);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             } elseif ($targetEntityClass && $action === 'activity') {
                 // if we don't have "contexts" form field
                 // we should save association between activity and target manually
                 $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId));
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:antrampa,项目名称:crm,代码行数:36,代码来源:TaskHandler.php

示例7: process

 /**
  * Process form
  *
  * @param  Issue $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Issue $entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
     $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
     if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
         $entity->setAssignee($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'assignee', ['read_only' => true]);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             /* if ($targetEntityClass && $action === 'activity') {
                    $this->activityManager->addActivityTarget(
                        $entity,
                        $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId)
                    );
                }*/
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:sergeypererva,项目名称:platform-application,代码行数:32,代码来源:IssueHandler.php

示例8: createAction

 /**
  * @return RedirectResponse|Response
  *
  * @throws AccessDeniedException
  */
 public function createAction(Request $request = null)
 {
     $this->admin->checkAccess('create');
     $class = $this->get('sonata.page.manager.snapshot')->getClass();
     $pageManager = $this->get('sonata.page.manager.page');
     $snapshot = new $class();
     if ($request->getMethod() == 'GET' && $request->get('pageId')) {
         $page = $pageManager->findOne(array('id' => $request->get('pageId')));
     } elseif ($this->admin->isChild()) {
         $page = $this->admin->getParent()->getSubject();
     } else {
         $page = null;
         // no page selected ...
     }
     $snapshot->setPage($page);
     $form = $this->createForm('sonata_page_create_snapshot', $snapshot);
     if ($request->getMethod() == 'POST') {
         $form->submit($request);
         if ($form->isValid()) {
             $snapshotManager = $this->get('sonata.page.manager.snapshot');
             $transformer = $this->get('sonata.page.transformer');
             $page = $form->getData()->getPage();
             $page->setEdited(false);
             $snapshot = $transformer->create($page);
             $this->admin->create($snapshot);
             $pageManager->save($page);
             $snapshotManager->enableSnapshots(array($snapshot));
         }
         return $this->redirect($this->admin->generateUrl('edit', array('id' => $snapshot->getId())));
     }
     return $this->render('SonataPageBundle:SnapshotAdmin:create.html.twig', array('action' => 'create', 'form' => $form->createView()));
 }
开发者ID:RunOpenCode,项目名称:SonataPageBundle,代码行数:37,代码来源:SnapshotAdminController.php

示例9: index

 function index(Request $request, Application $app)
 {
     $extension = $app['extensions']->getExtensionById('org.openacalendar.facebook');
     $appID = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('app_id'));
     $appSecret = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('app_secret'));
     $userToken = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('user_token'));
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('submitted') == 'appdetails') {
         $appID = $request->request->get('app_id');
         $appSecret = $request->request->get('app_secret');
         // Beacuse we are using a different app, we'll need a different user token to.
         $userToken = '';
         $app['appconfig']->setValue($extension->getAppConfigurationDefinition('app_id'), $appID);
         $app['appconfig']->setValue($extension->getAppConfigurationDefinition('app_secret'), $appSecret);
         $app['appconfig']->setValue($extension->getAppConfigurationDefinition('user_token'), $userToken);
     }
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken() && $request->request->get('submitted') == 'userdetails') {
         // Convert this short lived into long lived
         $url = "https://graph.facebook.com/oauth/access_token?client_id=" . $appID . "&client_secret=" . $appSecret . "&grant_type=fb_exchange_token&fb_exchange_token=" . $request->get('newfacebookaccesstoken');
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
         $result = curl_exec($ch);
         curl_close($ch);
         parse_str($result, $resultArray);
         if (!$resultArray['access_token']) {
             die("Did not get long-lived access token, problem.");
         }
         $userToken = $resultArray['access_token'];
         $app['appconfig']->setValue($extension->getAppConfigurationDefinition('user_token'), $userToken);
     }
     return $app['twig']->render('facebook/sysadmin/user/index.html.twig', array('app_id' => $appID, 'app_secret' => $appSecret ? substr($appSecret, 0, 5) . "XXXXXXX" : '', 'user_token' => $userToken ? substr($userToken, 0, 5) . "XXXXXXX" : ''));
 }
开发者ID:radical-assembly,项目名称:OpenACalendar-Web-Core,代码行数:33,代码来源:UserController.php

示例10: process

 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     if (!$entity->getCalendar()) {
         if ($this->securityFacade->getLoggedUser() && $this->securityFacade->getOrganization()) {
             /** @var Calendar $defaultCalendar */
             $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
             $entity->setCalendar($defaultCalendar);
         } else {
             throw new \LogicException('Current user did not define');
         }
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:xamin123,项目名称:platform,代码行数:43,代码来源:CalendarEventHandler.php

示例11: process

 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 if ($this->form->get('passwordGenerate')->getData()) {
                     $generatedPassword = $this->userManager->generatePassword(10);
                     $accountUser->setPlainPassword($generatedPassword);
                 }
                 if ($this->form->get('sendEmail')->getData()) {
                     $this->userManager->sendWelcomeEmail($accountUser);
                 }
             }
             $token = $this->securityFacade->getToken();
             if ($token instanceof OrganizationContextTokenInterface) {
                 $organization = $token->getOrganizationContext();
                 $accountUser->setOrganization($organization)->addOrganization($organization);
             }
             $this->userManager->updateUser($accountUser);
             return true;
         }
     }
     return false;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:31,代码来源:AccountUserHandler.php

示例12: attemptAuthentication

    /**
     * {@inheritdoc}
     */
    protected function attemptAuthentication(Request $request)
    {
        if ($this->options['post_only'] && 'post' !== strtolower($request->getMethod())) {
            if (null !== $this->logger) {
                $this->logger->debug(sprintf('Authentication method not supported: %s.', $request->getMethod()));
            }

            return null;
        }

        if (null !== $this->csrfProvider) {
            $csrfToken = $request->get($this->options['csrf_parameter']);

            if (false === $this->csrfProvider->isCsrfTokenValid($this->options['csrf_page_id'], $csrfToken)) {
                throw new InvalidCsrfTokenException('Invalid CSRF token.');
            }
        }

        $username = trim($request->get($this->options['username_parameter']));
        $password = $request->get($this->options['password_parameter']);

        $request->getSession()->set(SecurityContextInterface::LAST_USERNAME, $username);

        return $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $password, $this->providerKey));
    }
开发者ID:Gregwar,项目名称:symfony,代码行数:28,代码来源:UsernamePasswordFormAuthenticationListener.php

示例13: auth

 public function auth(Request $request)
 {
     $token = $request->headers->get('X-Auth-Token');
     if (empty($token)) {
         // 兼容老的协议,即将去除
         $token = $request->headers->get('Auth-Token', '');
     }
     $method = strtolower($request->headers->get('X-Auth-Method'));
     if ($method == 'keysign') {
         $decoded = $this->decodeKeysign($token);
         $this->setCurrentUser(array('id' => 0, 'nickname' => '游客', 'currentIp' => $request->getClientIp(), 'roles' => array()));
     } else {
         $whilelist = isset($this->whilelist[$request->getMethod()]) ? $this->whilelist[$request->getMethod()] : array();
         $path = rtrim($request->getPathInfo(), '/');
         $inWhiteList = 0;
         foreach ($whilelist as $pattern) {
             if (preg_match($pattern, $path)) {
                 $inWhiteList = 1;
                 break;
             }
         }
         if (!$inWhiteList && empty($token)) {
             throw new \RuntimeException('API Token不存在!');
         }
         $token = $this->getUserService()->getToken('mobile_login', $token);
         if (!$inWhiteList && empty($token['userId'])) {
             throw new \RuntimeException('API Token不不正确!');
         }
         $user = $this->getUserService()->getUser($token['userId']);
         if (!$inWhiteList && empty($user)) {
             throw new \RuntimeException('登录用户不存在!');
         }
         $this->setCurrentUser($user);
     }
 }
开发者ID:fujianguo,项目名称:EduSoho,代码行数:35,代码来源:ApiAuth.php

示例14: process

 /**
  * Process form
  *
  * @param  Call $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Call $entity)
 {
     $targetEntityClass = $this->request->get('entityClass');
     $targetEntityId = $this->request->get('entityId');
     $options = [];
     if ($targetEntityClass && $this->request->getMethod() === 'GET') {
         $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
         if (!$entity->getId()) {
             $entity->setPhoneNumber($this->phoneProvider->getPhoneNumber($targetEntity));
         }
         $options = ['phone_suggestions' => array_unique(array_map(function ($item) {
             return $item[0];
         }, $this->phoneProvider->getPhoneNumbers($targetEntity)))];
     }
     $this->form = $this->formFactory->createNamed($this->formName, $this->formType, $entity, $options);
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($targetEntityClass) {
                 $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
                 $this->callActivityManager->addAssociation($entity, $targetEntity);
                 $phones = $this->phoneProvider->getPhoneNumbers($targetEntity);
                 foreach ($phones as $phone) {
                     if ($entity->getPhoneNumber() === $phone[0]) {
                         $this->callActivityManager->addAssociation($entity, $phone[1]);
                     }
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:rodolfobandeira,项目名称:crm,代码行数:42,代码来源:CallHandler.php

示例15: initializeRequestAttributes

 protected function initializeRequestAttributes(Request $request, $master)
 {
     if ($master) {
         // set the context even if the parsing does not need to be done
         // to have correct link generation
         $this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'is_secure' => $request->isSecure()));
     }
     if ($request->attributes->has('_controller')) {
         // routing is already done
         return;
     }
     // add attributes based on the path info (routing)
     try {
         $parameters = $this->router->match($request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
         }
         $request->attributes->add($parameters);
         if ($locale = $request->attributes->get('_locale')) {
             $request->getSession()->setLocale($locale);
         }
     } catch (NotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new NotFoundHttpException($message, $e);
     } catch (MethodNotAllowedException $e) {
         $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:35,代码来源:RequestListener.php


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