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


PHP Twig_Environment::mergeGlobals方法代码示例

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


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

示例1: sendMail

 /**
  * Sends an email
  *
  * @param string $recipient
  * @param string $templatePath Path to the twig template
  * @param array $data
  * @param array $blindCopyRecipients Recipients to send bcc
  *
  * @return bool
  */
 public function sendMail($recipient, $templatePath, $data = array(), $blindCopyRecipients = array())
 {
     $tmplData = array_merge($data, array('footerTxt' => $this->templateFooterTxtPath, 'footerHtml' => $this->templateFooterHtmlPath));
     // Load template from twig.
     $template = $this->twig->loadTemplate($templatePath);
     // Merge twig globals so that they also are available in renderBlock.
     $tmplData = $this->twig->mergeGlobals($tmplData);
     // Get subject from block.
     $subject = $template->renderBlock('subject', $tmplData);
     $emailBodyText = $template->renderBlock('body_text', $tmplData);
     $emailBodyHtml = $template->renderBlock('body_html', $tmplData);
     /** @var \Swift_Message $message */
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->emailFrom)->setTo($recipient)->setBody($emailBodyText, 'text/plain')->addPart($emailBodyHtml, 'text/html');
     // add blind copy recipients
     foreach ($blindCopyRecipients as $bcc) {
         $message->addBcc($bcc);
     }
     $failedRecipients = array();
     $this->mailer->send($message, $failedRecipients);
     if (count($failedRecipients) > 0) {
         $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
         return false;
     }
     return true;
 }
开发者ID:sulu,项目名称:sulu-sales,代码行数:35,代码来源:EmailManager.php

示例2: render

 /**
  * {@inheritdoc}
  */
 public function render(EmailInterface $email, array $data = array())
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         if ($template->hasBlock('subject')) {
             $subject = $template->renderBlock('subject', $data);
         } else {
             $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
             $subjectTemplate = $twig->createTemplate($email->getSubject());
             $subject = $subjectTemplate->render($data);
         }
         $body = $template->renderBlock('body', $data);
     } else {
         $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
         $subjectTemplate = $twig->createTemplate($email->getSubject());
         $bodyTemplate = $twig->createTemplate($email->getContent());
         $subject = $subjectTemplate->render($data);
         $body = $bodyTemplate->render($data);
     }
     /** @var EmailRenderEvent $event */
     $event = $this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_RENDER, new EmailRenderEvent(new RenderedEmail($subject, $body)));
     return $event->getRenderedEmail();
 }
开发者ID:JulienDemangeon,项目名称:SyliusMailerBundle,代码行数:28,代码来源:TwigAdapter.php

示例3: create

 /**
  * {@inheritdoc}
  */
 public function create($templateName, array $context = array())
 {
     if (!isset($this->templateConfigs[$templateName])) {
         throw new TemplateNotExistsException($templateName);
     }
     $templateConfig = $this->templateConfigs[$templateName];
     if (isset($context['utm'])) {
         $templateConfig['utm'] = array_merge($templateConfig['utm'], $context['utm']);
     }
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateConfig['template']);
     $subject = $template->renderBlock('subject', $context);
     $htmlBody = $template->renderBlock('body_html', $context);
     $textBody = $template->renderBlock('body_text', $context);
     if (empty($subject)) {
         throw new TemplatePartRequiredException('subject', $templateConfig['template']);
     }
     if (empty($htmlBody)) {
         throw new TemplatePartRequiredException('body_html', $templateConfig['template']);
     }
     $htmlBody = $this->cssToInline($htmlBody);
     $htmlBody = $this->addUtmParams($htmlBody, $templateConfig['host'], $templateConfig['utm']);
     if (empty($textBody) && $templateConfig['generate_text_version']) {
         $textBody = $this->htmlToText($htmlBody);
     }
     $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($htmlBody, 'text/html');
     if (!empty($textBody)) {
         $message->addPart($textBody, 'text/plain');
     }
     return $message;
 }
开发者ID:fullpipe,项目名称:email-template-bundle,代码行数:34,代码来源:MessageFactory.php

示例4: sendNotification

 /**
  * sendNotification.
  *
  * @param string $templateName
  * @param array  $context
  */
 private function sendNotification($templateName, array $context)
 {
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $message = $template->renderBlock('body', $context);
     $notification = new Notification($message);
     $this->notifier->notify($notification);
 }
开发者ID:hogosha,项目名称:hogosha,代码行数:14,代码来源:NotificationCenter.php

示例5: send

 /**
  * {@inheritdoc}
  */
 public function send($template, array $recipients, array $data = array())
 {
     $data = $this->twig->mergeGlobals($data);
     $template = $this->twig->loadTemplate($template);
     $content = $template->renderBlock('content', $data);
     $originator = $template->renderBlock('originator', $data);
     $this->sender->send($recipients[0], $content, $originator);
 }
开发者ID:liverbool,项目名称:dos-user-bundle,代码行数:11,代码来源:Sender.php

示例6: provideEmailWithTemplate

 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function provideEmailWithTemplate(EmailInterface $email, array $data)
 {
     $data = $this->twig->mergeGlobals($data);
     /** @var \Twig_Template $template */
     $template = $this->twig->loadTemplate($email->getTemplate());
     $subject = $template->renderBlock('subject', $data);
     $body = $template->renderBlock('body', $data);
     return new RenderedEmail($subject, $body);
 }
开发者ID:sylius,项目名称:sylius,代码行数:15,代码来源:EmailTwigAdapter.php

示例7: sendMessage

 /**
  * Sends the email message.
  *
  * @param  string $templateName The template name
  * @param  array  $context      An array of context to pass to the template
  * @param  mixed $fromEmail     The from email
  * @param  mixed $toEmail       The to email
  */
 protected function sendMessage($templateName, array $context, $fromEmail, $toEmail)
 {
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $subject = $template->renderBlock('subject', $context);
     $body = $template->renderBlock('body', $context);
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setTo($toEmail)->setBody($body, 'text/html');
     $this->mailer->send($message);
 }
开发者ID:sfblaauw,项目名称:pulsar,代码行数:17,代码来源:AbstractTwigMailer.php

示例8: sendNotification

 /**
  * sendNotification.
  *
  * @param string $templateName
  * @param array  $context
  * @param array  $options
  */
 private function sendNotification($templateName, array $context, array $options = [])
 {
     $optionsResolver = new OptionsResolver();
     $optionsResolver->setRequired(['color']);
     $options = $optionsResolver->resolve($options);
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $message = $template->renderBlock('body', $context);
     $this->notifier->send($message, $options);
 }
开发者ID:hogosha,项目名称:hogosha,代码行数:17,代码来源:Notification.php

示例9: renderBlock

 /**
  * {@inheritdoc}
  */
 public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
 {
     $cacheKey = $view->vars[self::CACHE_KEY_VAR];
     $context = $this->environment->mergeGlobals($variables);
     ob_start();
     // By contract,This method can only be called after getting the resource
     // (which is passed to the method). Getting a resource for the first time
     // (with an empty cache) is guaranteed to invoke loadResourcesFromTheme(),
     // where the property $template is initialized.
     // We do not call renderBlock here to avoid too many nested level calls
     // (XDebug limits the level to 100 by default)
     $this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
     return ob_get_clean();
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:17,代码来源:TwigRendererEngine.php

示例10: loadTemplate

 /**
  * Loads the template.
  *
  * @param string $template The template relative path
  * @param array  $vars     The template variables
  *
  * @throws TemplateNotFoundException    When template does not exist
  * @throws UnsupportedTemplateException When template format is not supported
  *
  * @return TemplateInterface
  */
 public function loadTemplate($template, array $vars = [])
 {
     if (!$this->supports($template)) {
         throw new UnsupportedTemplateException(sprintf('Template %s is not supported by this engine.', $template));
     }
     try {
         $reference = $this->twig->resolveTemplate($template);
     } catch (\Twig_Error_Loader $exception) {
         throw new TemplateNotFoundException(sprintf('Template %s does not exist.', $template), $exception);
     } catch (\Exception $exception) {
         throw new UnsupportedTemplateException(sprintf('Invalid template %s provided.', $template), $exception);
     }
     return new Template($reference->getTemplateName(), $this->twig->mergeGlobals($vars));
 }
开发者ID:Symfomany,项目名称:laravelcinema,代码行数:25,代码来源:TwigEngineAdapter.php

示例11: sendMessage

 /**
  * sendMessage.
  *
  * @param string $templateName
  * @param array  $context
  * @param string $toEmail
  */
 private function sendMessage($templateName, array $context, $toEmail)
 {
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $subject = $template->renderBlock('subject', $context);
     $textBody = $template->renderBlock('body_text', $context);
     $htmlBody = $template->renderBlock('body_html', $context);
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->fromEmail)->setTo($toEmail);
     if (!empty($htmlBody)) {
         $message->setBody($htmlBody, 'text/html')->addPart($textBody, 'text/plain');
     } else {
         $message->setBody($textBody);
     }
     $this->mailer->send($message);
 }
开发者ID:hogosha,项目名称:hogosha,代码行数:22,代码来源:Mailer.php

示例12: sendMessage

 /**
  * @param string $templateName
  * @param array  $context
  * @param string $fromEmail
  * @param string $toEmail
  */
 protected function sendMessage($templateName, $context, $toEmail)
 {
     $fromEmail = $this->parameters['from_email'];
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $subject = $template->renderBlock('subject', $context);
     $textBody = trim($template->renderBlock('text_body', $context));
     $htmlContent = trim($template->renderBlock('content_html_body', $context));
     $htmlBody = trim($template->renderBlock('html_body', $context));
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail['address'], $fromEmail['sender_name'])->setTo($toEmail);
     $message->setBody($textBody);
     if (!empty($htmlBody) && !empty($htmlContent)) {
         $message->addPart($htmlBody, 'text/html');
     }
     $this->mailer->send($message);
 }
开发者ID:jaapjansma,项目名称:homefinance,代码行数:22,代码来源:TwigMailer.php

示例13: sendMessage

 /**
  * @param string $templateName
  * @param array  $context
  * @param string|array $fromEmail
  * @param string|array $toEmail
  */
 protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
 {
     if ($this->noSend) {
         return;
     }
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $subject = $template->renderBlock('subject', $context);
     $textBody = $template->renderBlock('body_text', $context);
     $htmlBody = $template->renderBlock('body_html', $context);
     /*
     $message = \Swift_Message::newInstance()
         ->setSubject($subject)
         ->setFrom($fromEmail)
         ->setTo($toEmail);
     
     if (!empty($htmlBody)) {
         $message->setBody($htmlBody, 'text/html')
             ->addPart($textBody, 'text/plain');
     } else {
         $message->setBody($textBody);
     }
     
     $this->mailer->send($message);
     */
     mail($toEmail, $subject, $htmlBody, "From: {$fromEmail}" . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n");
 }
开发者ID:ronaldoaf,项目名称:silex-simpleuser,代码行数:33,代码来源:Mailer.php

示例14: loadResourcesFromTheme

 /**
  * Loads the resources for all blocks in a theme.
  *
  * @param string $cacheKey The cache key for storing the resource.
  * @param mixed  $theme    The theme to load the block from. This parameter
  *                         is passed by reference, because it might be necessary
  *                         to initialize the theme first. Any changes made to
  *                         this variable will be kept and be available upon
  *                         further calls to this method using the same theme.
  */
 protected function loadResourcesFromTheme($cacheKey, &$theme)
 {
     if (!$theme instanceof \Twig_Template) {
         /* @var \Twig_Template $theme */
         $theme = $this->environment->loadTemplate($theme);
     }
     if (null === $this->template) {
         // Store the first \Twig_Template instance that we find so that
         // we can call displayBlock() later on. It doesn't matter *which*
         // template we use for that, since we pass the used blocks manually
         // anyway.
         $this->template = $theme;
     }
     // Use a separate variable for the inheritance traversal, because
     // theme is a reference and we don't want to change it.
     $currentTheme = $theme;
     $context = $this->environment->mergeGlobals(array());
     // The do loop takes care of template inheritance.
     // Add blocks from all templates in the inheritance tree, but avoid
     // overriding blocks already set.
     do {
         foreach ($currentTheme->getBlocks() as $block => $blockData) {
             if (!isset($this->resources[$cacheKey][$block])) {
                 // The resource given back is the key to the bucket that
                 // contains this block.
                 $this->resources[$cacheKey][$block] = $blockData;
             }
         }
     } while (false !== ($currentTheme = $currentTheme->getParent($context)));
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:40,代码来源:TwigRendererEngine.php

示例15: getRenderedEmail

 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function getRenderedEmail(EmailInterface $email, array $data)
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         $subject = $template->renderBlock('subject', $data);
         $body = $template->renderBlock('body', $data);
         return new RenderedEmail($subject, $body);
     }
     $twig = new \Twig_Environment(new \Twig_Loader_Array([]));
     $subjectTemplate = $twig->createTemplate($email->getSubject());
     $bodyTemplate = $twig->createTemplate($email->getContent());
     $subject = $subjectTemplate->render($data);
     $body = $bodyTemplate->render($data);
     return new RenderedEmail($subject, $body);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:23,代码来源:EmailTwigAdapter.php


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