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


PHP RequestContext::setParameter方法代码示例

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


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

示例1: 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
         $context = new RequestContext($request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $request->isSecure() ? $this->httpPort : $request->getPort(), $request->isSecure() ? $request->getPort() : $this->httpsPort);
         if ($session = $request->getSession()) {
             $context->setParameter('_locale', $session->getLocale());
         }
         $this->router->setContext($context);
     }
     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'], $this->parametersToString($parameters)));
         }
         $request->attributes->add($parameters);
     } catch (ResourceNotFoundException $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);
     }
     if ($master && ($locale = $request->attributes->get('_locale'))) {
         $request->getSession()->setLocale($locale);
         $context->setParameter('_locale', $locale);
     }
 }
开发者ID:rfc1483,项目名称:blog,代码行数:40,代码来源:RequestListener.php

示例2: testUrlWithGlobalParameter

 public function testUrlWithGlobalParameter()
 {
     $routes = $this->getRoutes('test', new Route('/testing/{foo}'));
     $generator = $this->getGenerator($routes);
     $context = new RequestContext('/app.php');
     $context->setParameter('foo', 'bar');
     $generator->setContext($context);
     $url = $generator->generate('test', array());
     $this->assertEquals('/app.php/testing/bar', $url);
 }
开发者ID:rouffj,项目名称:symfony,代码行数:10,代码来源:UrlGeneratorTest.php

示例3: testGlobalParameterHasHigherPriorityThanDefault

 public function testGlobalParameterHasHigherPriorityThanDefault()
 {
     $routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en')));
     $generator = $this->getGenerator($routes);
     $context = new RequestContext('/app.php');
     $context->setParameter('_locale', 'de');
     $generator->setContext($context);
     $url = $generator->generate('test', array());
     $this->assertSame('/app.php/de', $url);
 }
开发者ID:zmerrychristmas,项目名称:firstapp,代码行数:10,代码来源:UrlGeneratorTest.php

示例4: testSetParameter

 public function testSetParameter()
 {
     $requestContext = new RequestContext();
     $requestContext->setParameter('foo', 'bar');
     $this->assertEquals('bar', $requestContext->getParameter('foo'));
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:6,代码来源:RequestContextTest.php

示例5: testGenerateThrowsException

 /**
  * @dataProvider getGenerateThrowsExceptionFixtures
  * @expectedException Symfony\Component\Routing\Exception\RouteNotFoundException
  */
 public function testGenerateThrowsException($locale, $host, $route)
 {
     $router = $this->getNonRedirectingHostMapRouter();
     $context = new RequestContext();
     $context->setParameter('_locale', $locale);
     $context->setHost($host);
     $router->setContext($context);
     $router->generate($route);
 }
开发者ID:DONIKAN,项目名称:JMSI18nRoutingBundle,代码行数:13,代码来源:I18nRouterTest.php

示例6: testSendTestEmailAction

 public function testSendTestEmailAction()
 {
     if (null !== static::$kernel) {
         static::$kernel->shutdown();
     }
     try {
         static::$kernel = static::createKernel(array());
     } catch (\RuntimeException $ex) {
         $this->markTestSkipped("There does not seem to be a full application available (e.g. running tests on travis.org). So this test is skipped.");
         return;
     }
     static::$kernel->boot();
     $container = static::$kernel->getContainer();
     $spoolDir = $container->getParameter('swiftmailer.spool.defaultMailer.file.path');
     // delete all spooled mails from other tests
     array_map('unlink', glob($spoolDir . "/*.messag*"));
     array_map('unlink', glob($spoolDir . "/.*.messag*"));
     $context = new RequestContext('/app.php');
     $context->setParameter('_locale', 'en');
     $router = $container->get('router');
     $router->setContext($context);
     $to = md5(time() . "to") . '@email.non-existent.to.mail.domain.com';
     $uri = $router->generate("azine_email_send_test_email", array('template' => AzineTemplateProvider::NEWSLETTER_TEMPLATE, 'email' => $to));
     $container->set('request', Request::create($uri, "GET"));
     // "login" a user
     $token = new UsernamePasswordToken("username", "password", "main");
     $recipientProvider = $container->get('azine_email_recipient_provider');
     $users = $recipientProvider->getNewsletterRecipientIDs();
     $token->setUser($recipientProvider->getRecipient($users[0]));
     $container->get('security.context')->setToken($token);
     // instantiate the controller and try to send the email
     $controller = new AzineEmailTemplateController();
     $controller->setContainer($container);
     $response = $controller->sendTestEmailAction(AzineTemplateProvider::NEWSLETTER_TEMPLATE, $to);
     $this->assertEquals(302, $response->getStatusCode(), "Status-Code 302 expected.");
     $uri = $router->generate("azine_email_template_index");
     $this->assertContains("Redirecting to {$uri}", $response->getContent(), "Redirect expected.");
     $findInFile = new FindInFileUtil();
     $findInFile->excludeMode = false;
     $findInFile->formats = array(".message");
     $this->assertEquals(1, sizeof($findInFile->find($spoolDir, "This is just the default content-block.")));
     $this->assertEquals(1, sizeof($findInFile->find($spoolDir, "Add some html content here")));
 }
开发者ID:keynetic,项目名称:email-bundle,代码行数:43,代码来源:AzineEmailTemplateControllerTest.php

示例7: sendEmail

 /**
  * (non-PHPdoc)
  * @see Azine\EmailBundle\Services.TemplateTwigSwiftMailerInterface::sendEmail()
  * @param array $failedRecipients
  * @param string $subject
  * @param String $from
  * @param String $fromName
  * @param array|String $to
  * @param String $toName
  * @param array|String $cc
  * @param String $ccName
  * @param array|String $bcc
  * @param String $bccName
  * @param $replyTo
  * @param $replyToName
  * @param array $params
  * @param $template
  * @param array $attachments
  * @param null $emailLocale
  * @param \Swift_Message $message
  * @return int
  */
 public function sendEmail(&$failedRecipients, $subject, $from, $fromName, $to, $toName, $cc, $ccName, $bcc, $bccName, $replyTo, $replyToName, array $params, $template, $attachments = array(), $emailLocale = null, \Swift_Message &$message = null)
 {
     // create the message
     if ($message == null) {
         $message = \Swift_Message::newInstance();
     }
     $message->setSubject($subject);
     // set the from-Name & -Emali to the default ones if not given
     if ($from == null) {
         $from = $this->noReplyEmail;
     }
     if ($fromName == null) {
         $fromName = $this->noReplyName;
     }
     // add the from-email for the footer-text
     if (!array_key_exists('fromEmail', $params)) {
         $params['sendMailAccountName'] = $this->noReplyName;
         $params['sendMailAccountAddress'] = $this->noReplyEmail;
     }
     // get the baseTemplate. => templateId without the ending.
     $templateBaseId = substr($template, 0, strrpos($template, ".", -6));
     // check if this email should be stored for web-view
     if ($this->templateProvider->saveWebViewFor($templateBaseId)) {
         // keep a copy of the vars for the web-view
         $webViewParams = $params;
         // add the web-view token
         $params[$this->templateProvider->getWebViewTokenId()] = SentEmail::getNewToken();
     } else {
         $webViewParams = array();
     }
     // recursively add all template-variables for the wrapper-templates and contentItems
     $params = $this->templateProvider->addTemplateVariablesFor($templateBaseId, $params);
     // recursively attach all messages in the array
     $this->embedImages($message, $params);
     // change the locale for the email-recipients
     if ($emailLocale !== null && strlen($emailLocale) > 0) {
         $currentUserLocale = $this->translator->getLocale();
         // change the router-context locale
         $this->routerContext->setParameter("_locale", $emailLocale);
         // change the translator locale
         $this->translator->setLocale($emailLocale);
     } else {
         $emailLocale = $this->translator->getLocale();
     }
     // recursively add snippets for the wrapper-templates and contentItems
     $params = $this->templateProvider->addTemplateSnippetsWithImagesFor($templateBaseId, $params, $emailLocale);
     // add the emailLocale (used for web-view)
     $params['emailLocale'] = $emailLocale;
     // render the email parts
     $twigTemplate = $this->loadTemplate($template);
     $textBody = $twigTemplate->renderBlock('body_text', $params);
     $message->addPart($textBody, 'text/plain');
     $htmlBody = $twigTemplate->renderBlock('body_html', $params);
     $campaignParams = $this->templateProvider->getCampaignParamsFor($templateBaseId, $params);
     if (sizeof($campaignParams) > 0) {
         $htmlBody = $this->emailTwigExtension->addCampaignParamsToAllUrls($htmlBody, $campaignParams);
     }
     // if email-tracking is enabled
     if ($this->emailOpenTrackingCodeBuilder) {
         // add an image at the end of the html tag with the tracking-params to track email-opens
         $imgTrackingCode = $this->emailOpenTrackingCodeBuilder->getTrackingImgCode($templateBaseId, $campaignParams, $params, $message->getId(), $to, $cc, $bcc);
         if ($imgTrackingCode && strlen($imgTrackingCode) > 0) {
             $htmlCloseTagPosition = strpos($htmlBody, "</body>");
             $htmlBody = substr_replace($htmlBody, $imgTrackingCode, $htmlCloseTagPosition, 0);
         }
     }
     $message->setBody($htmlBody, 'text/html');
     // remove unused/unreferenced embeded items from the message
     $message = $this->removeUnreferecedEmbededItemsFromMessage($message, $params, $htmlBody);
     // change the locale back to the users locale
     if (isset($currentUserLocale) && $currentUserLocale != null) {
         $this->routerContext->setParameter("_locale", $currentUserLocale);
         $this->translator->setLocale($currentUserLocale);
     }
     // add attachments
     foreach ($attachments as $fileName => $file) {
         // add attachment from existing file
         if (is_string($file)) {
//.........这里部分代码省略.........
开发者ID:azine,项目名称:email-bundle,代码行数:101,代码来源:AzineTwigSwiftMailer.php

示例8: testMatch

 public function testMatch()
 {
     $router = $this->getRouter();
     $router->setHostMap(array('en' => 'en.test', 'de' => 'de.test', 'fr' => 'fr.test'));
     $this->assertEquals(array('_controller' => 'foo', '_route' => 'welcome'), $router->match('/welcome'));
     $context = new RequestContext('', 'GET', 'en.test');
     $context->setParameter('_locale', 'en');
     $router->setContext($context);
     $this->assertEquals(array('_controller' => 'foo', '_locale' => 'en', '_route' => 'welcome'), $router->match('/welcome-on-our-website'));
     $this->assertEquals(array('_controller' => 'JMS\\I18nRoutingBundle\\Controller\\RedirectController::redirectAction', 'path' => '/willkommen-auf-unserer-webseite', 'host' => 'de.test', 'permanent' => true, 'scheme' => 'http', 'httpPort' => 80, 'httpsPort' => 443, '_route' => 'welcome'), $router->match('/willkommen-auf-unserer-webseite'));
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:11,代码来源:I18nRouterTest.php


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