コード例 #1
0
 public function setRequestLayout(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     // Get the necessary informations to check them in layout configurations
     $path = $request->getPathInfo();
     $host = $request->getHost();
     $layouts = $this->config['layouts'];
     // As a layout must be set, we force it to be empty if no layout is properly configured.
     // Then this will throw an exception, and the user will be warned of the "no-layout" config problem.
     $finalLayout = null;
     foreach ($layouts as $layoutConfig) {
         $match = false;
         if ($layoutConfig['host'] && $host === $layoutConfig['host']) {
             $match = true;
         }
         if ($layoutConfig['pattern'] && preg_match('~' . $layoutConfig['pattern'] . '~', $path)) {
             $match = true;
         }
         if ($match) {
             $finalLayout = $layoutConfig;
             break;
         }
     }
     if (null === $finalLayout || !$this->templating->exists($finalLayout['resource'])) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template %s for layout %s. The "layout" parameter must be a valid twig view to be used as a layout.', $finalLayout['resource'], $finalLayout['name']), 0, $finalLayout['resource']);
     }
     $event->getRequest()->attributes->set('_orbitale_cms_layout', $finalLayout);
 }
コード例 #2
0
 /**
  * @param string $view
  * @param string $templateName
  * @param array $params
  * @return string
  * @throws ResourceNotFoundException
  */
 protected function getHtml(string $view, string $templateName, array $params) : string
 {
     $template = null;
     if ($this->templating->exists($templateName)) {
         $template = $templateName;
     }
     if ($template === null) {
         $templateDir = $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     $viewPath = $view;
     if ($template === null && $viewPath !== '') {
         $templateDir = $viewPath . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = static::$TEMPLATE_DIR . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('View for ' . $templateName . ' does not exist!');
     }
     return $this->templating->render($template, $params);
 }
コード例 #3
0
ファイル: OptionType.php プロジェクト: vardius/list-bundle
 /**
  * @inheritDoc
  */
 public function configureOptions(OptionsResolver $resolver, $property, $templatePath)
 {
     parent::configureOptions($resolver, $property, $templatePath);
     $class = get_class($this);
     $resolver->setDefault('label', $this->templating->render($templatePath . strtolower(str_replace('Type', '', substr($class, strrpos($class, '\\') + 1))) . '.html.twig'));
     $resolver->remove('url');
     $resolver->remove('sort');
 }
コード例 #4
0
 /**
  * Setup
  */
 public function setup()
 {
     $this->mailer = $this->prophesize(Swift_Mailer::class);
     $this->templating = $this->prophesize(TwigEngine::class);
     $requestCollectorConfiguration = ['from_email' => '*****@*****.**'];
     $this->requestObject = new RequestObject();
     $this->collector = new MailerCollector($this->mailer->reveal(), $this->templating->reveal(), $requestCollectorConfiguration);
 }
コード例 #5
0
ファイル: Mail.php プロジェクト: Ravetracer/www
 public function sendTemplateMail(SendTemplateMailCommand $command)
 {
     $message = \Swift_Message::newInstance();
     $ext = $command->format === 'text/html' ? 'html' : 'txt';
     $tplIdentifier = 'Email/' . $command->template . '.' . $ext;
     $template = $this->cr->getContent($tplIdentifier);
     $templateData = $command->templateData;
     if ($command->image !== null) {
         $templateData['image'] = $message->embed(\Swift_Image::fromPath($command->image));
     }
     // Subject
     $env = new \Twig_Environment(new \Twig_Loader_String());
     $subject = $template->getProperties()->containsKey('subject') ? $template->getProperties()->get('subject') : $this->mailFromName;
     $subject = $env->render($subject, $templateData);
     // Body
     $body = $this->templating->render('bcrm_content:' . $tplIdentifier, $templateData);
     $message->setCharset('UTF-8');
     $message->setFrom($this->mailFromEmail, $this->mailFromName)->setSubject($subject)->setTo($command->email)->setBody($body, $command->format);
     $this->mailer->send($message);
 }
コード例 #6
0
 /**
  * Set all options for the twig template.
  *
  * @return string
  */
 public function createView()
 {
     $options = array();
     $options['id'] = $this->getTableId();
     $options['sAjaxSource'] = $this->getSAjaxSource();
     $options['tableHeaders'] = $this->getTableHeaders();
     $options['sDomOptions'] = $this->getSDomOptions();
     $options['fields'] = $this->getFieldsOptions();
     $options['actions'] = $this->getActions();
     $options['customizeOptions'] = $this->getCustomizeOptions();
     $options['routeParameters'] = $this->getRouteParameters();
     return $this->twig->render($this->getTemplate(), $options);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = array())
 {
     try {
         return parent::render($name, $parameters);
     } catch (\Twig_Error $e) {
         if ($name instanceof TemplateReference) {
             try {
                 // try to get the real file name of the template where the error occurred
                 $e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
             } catch (\Exception $e2) {
             }
         }
         throw $e;
     }
 }
コード例 #8
0
ファイル: Renderer.php プロジェクト: vardius/list-bundle
 /**
  * {@inheritdoc}
  */
 public function renderView(string $view, array $params = []) : string
 {
     $template = null;
     if ($this->templating->exists($this->getTemplateName())) {
         $template = $this->getTemplateName();
     }
     $viewPath = $view;
     if ($template === null && $viewPath) {
         $templateDir = $viewPath . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = self::TEMPLATE_DIR . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('Vardius\\Bundle\\ListBundle\\View\\Renderer: Wrong template path');
     }
     return $this->templating->render($template, $params);
 }
コード例 #9
0
ファイル: TwigEngine.php プロジェクト: symfony/symfony
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = array())
 {
     try {
         return parent::render($name, $parameters);
     } catch (\Twig_Error $e) {
         if ($name instanceof TemplateReference) {
             try {
                 // try to get the real name of the template where the error occurred
                 $name = $e->getTemplateName();
                 $path = (string) $this->locator->locate($this->parser->parse($name));
                 if (method_exists($e, 'setSourceContext')) {
                     $e->setSourceContext(new \Twig_Source('', $name, $path));
                 } else {
                     $e->setTemplateName($path);
                 }
             } catch (\Exception $e2) {
             }
         }
         throw $e;
     }
 }
コード例 #10
0
ファイル: MpdfService.php プロジェクト: sasedev/mpdf-bundle
 /**
  * Renders and set as html the template with the given context
  *
  * @param
  *        	$template
  * @param array $data
  */
 public function useTwigTemplate($template, array $data = array())
 {
     $html = $this->renderer->render($template, $data);
     $this->setHtml($html);
     return $this;
 }
コード例 #11
0
ファイル: Menu.php プロジェクト: vardius/menu-bundle
 /**
  * @inheritDoc
  */
 public function render($view = null)
 {
     $menuView = $view ?: $this->view;
     return $this->twigEngine->render($menuView, ['items' => $this->children]);
 }
コード例 #12
0
 /**
  * Renders a mailing part.
  *
  * @param MailerEvent $event
  * @param string      $extension
  *
  * @return string
  */
 private function renderMailPart(MailerEvent $event, $extension)
 {
     return $this->engine->render(sprintf('%s.%s', $event->getTemplateSource(), (string) $extension), $event->getParameters());
 }
コード例 #13
0
ファイル: HtmlRenderer.php プロジェクト: dstansby/camdram
 /**
  * Gets a DiaryView, passes it to the Twig template and returns the rendered HTML as a Symfony Response object
  *
  * @param Diary $diary
  *
  * @return Response
  */
 public function render(Diary $diary)
 {
     $view = $diary->createView();
     return $this->twig->render('ActsDiaryBundle:Diary:index.html.twig', array('diary' => $view));
 }
コード例 #14
0
ファイル: Paginator.php プロジェクト: vardius/list-bundle
 /**
  * {@inheritdoc}
  */
 public function render() : string
 {
     return $this->templating->render($this->getTemplatePath() . 'paginator.html.twig', ['currentPage' => $this->getCurrentPage(), 'previousPage' => $this->getPreviousPage(), 'lastPage' => $this->getLastPage(), 'nextPage' => $this->getNextPage()]);
 }
コード例 #15
0
ファイル: PoolCreator.php プロジェクト: jeboehm/lampcp
 /**
  * Render and return the pool configuration.
  *
  * @return string
  */
 public function getPoolConfiguration()
 {
     $vars = array('poolname' => $this->getPoolName(), 'user' => $this->_user->getName(), 'group' => $this->_user->getGroupname(), 'socket' => $this->getSocketPath());
     $file = $this->_twig->render(self::CFG_POOL_TEMPLATE, $vars);
     return $file;
 }