render() 공개 메소드

Renders a template.
public render ( string $name, array $context = [] ) : string
$name string The template name
$context array An array of parameters to pass to the template
리턴 string The rendered template
 /**
  * {@inheritdoc}
  */
 public function validate($emailTemplate, Constraint $constraint)
 {
     /** @var EmailTemplate $emailTemplate */
     /** @var VariablesConstraint $constraint */
     $fieldsToValidate = array('subject' => $emailTemplate->getSubject(), 'content' => $emailTemplate->getContent());
     foreach ($emailTemplate->getTranslations() as $trans) {
         if (in_array($trans->getField(), array('subject', 'content'))) {
             $fieldsToValidate[$trans->getLocale() . '.' . $trans->getField()] = $trans->getContent();
         }
     }
     $relatedEntity = false;
     if (class_exists($emailTemplate->getEntityName())) {
         $className = $emailTemplate->getEntityName();
         $relatedEntity = new $className();
     }
     $errors = array();
     foreach ($fieldsToValidate as $field => $value) {
         try {
             $this->twig->render($value, array('entity' => $relatedEntity, 'user' => $this->getUser()));
         } catch (\Exception $e) {
             $errors[$field] = true;
         }
     }
     if (!empty($errors)) {
         $this->context->addViolation($constraint->message);
     }
 }
예제 #2
0
 /**
  * Execute Command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $email = $this->twig->render('test.twig');
     $message = $this->mailer->createMessage()->setSubject('PHP RFC Digestor Test Email')->setFrom('*****@*****.**')->setTo($input->getArgument('email'))->setBody($email, 'text/html');
     $this->mailer->send($message);
     $output->writeln(sprintf('<info>Email sent to %s</info>', $input->getArgument('email')));
 }
 /**
  * @return string
  */
 public function summernoteInit()
 {
     $template = $this->parameters['init_template'];
     $options = [];
     $options['fontname'] = count($this->parameters['fontname']) > 0 ? $this->prepareArrayParameter('fontname') : $this->getDefaultFontname();
     $options['fontnocheck'] = count($this->parameters['fontnocheck'] > 0) ? $this->prepareArrayParameter('fontnocheck') : null;
     $options['language'] = isset($this->parameters['language']) ? $this->parameters['language'] : null;
     $options['plugins'] = isset($this->parameters['plugins']) ? $this->parameters['plugins'] : null;
     $options['selector'] = $this->parameters['selector'];
     $options['width'] = $this->parameters['width'];
     $options['height'] = $this->parameters['height'];
     $options['include_jquery'] = $this->parameters['include_jquery'];
     $options['include_bootstrap'] = $this->parameters['include_bootstrap'];
     $options['include_fontawesome'] = $this->parameters['include_fontawesome'];
     $options['fontawesome_path'] = $this->parameters['fontawesome_path'];
     $options['bootstrap_css_path'] = $this->parameters['bootstrap_css_path'];
     $options['bootstrap_js_path'] = $this->parameters['bootstrap_js_path'];
     $options['jquery_path'] = $this->parameters['jquery_path'];
     $options['summernote_css_path'] = $this->parameters['summernote_css_path'];
     $options['summernote_js_path'] = $this->parameters['summernote_js_path'];
     $options['jquery_version'] = $this->parameters['jquery_version'];
     $options['toolbar'] = $this->prepareToolbar();
     $base_path = !isset($this->parameters['base_path']) ? 'bundles/fmsummernote/Jquery' . $options['jquery_version'] . '.x/' : $this->parameters['base_path'];
     return $this->twig->render($template, ['sn' => $options, 'base_path' => $base_path]);
 }
 public function parse($buffer, $context = array())
 {
     /** @var \Twig_Loader_Array $loader */
     $loader = $this->twigEnvironment->getLoader();
     $loader->setTemplate('__TEMPLATE__', $buffer);
     return $this->twigEnvironment->render('__TEMPLATE__', $context);
 }
 /**
  * @param Activity $activity
  *
  * @return Result
  */
 public function run(Activity $activity)
 {
     $challenge = $activity->getChallengeObject();
     $worker = $this->getWorker($challenge->getExecutionMode());
     // 1) write all of the files        (different for contexts)
     // 2) call setupContext()           (different for contexts)
     // 3) call grade() and use results  (different for contexts)
     $filesToWrite = $this->getFilesToCreate($activity);
     $initialExecutionResult = new CodingExecutionResult($filesToWrite);
     // serialize this, so we can easily fetch the input files
     $filesToWrite['executionResult.cache'] = serialize($initialExecutionResult);
     // write the challenge class name
     $filesToWrite['ChallengeClass.php'] = $activity->getChallengeClassContents();
     // write our executor.php and execute that
     $executionCode = $this->twig->render('code_executor.php.twig', array('workerClass' => get_class($worker), 'projectPath' => $this->projectRootDir, 'challengeFilename' => 'ChallengeClass.php', 'challengeClassName' => $activity->getChallengeClassName(), 'entryPointFilename' => $challenge->getFileBuilder()->getEntryPointFilename()));
     $filesToWrite['execution.php'] = $executionCode;
     $codeExecutor = new CodeExecutor($filesToWrite, 'execution.php');
     $executionResult = $codeExecutor->executePhpProcess();
     $result = new Result($activity);
     // clean things up just in case - but the worker should take care of this
     $result->setLanguageError(self::cleanError($executionResult->getLanguageError(), $executionResult->getCodeDirectory()));
     $result->setGradingError($executionResult->getGradingError());
     $result->setOutput($executionResult->getOutput());
     return $result;
 }
예제 #6
0
 public function getLogs($entity)
 {
     if (!is_object($entity)) {
         return '';
     }
     return $this->twig->render($this->template, array('logEntities' => $this->logsFromEntity($entity)));
 }
예제 #7
0
 public function replace($zpl, array $params = [])
 {
     if (empty($zpl)) {
         return '';
     }
     return $this->twig->render($zpl, $params);
 }
예제 #8
0
 protected function renderTwig($template, $vars)
 {
     $vars['alerts'] = $this->getAlerts();
     if (!empty($this->post)) {
         $vars['post'] = $this->post;
     } else {
         if (!empty($_SESSION['post'])) {
             $vars['post'] = $_SESSION['post'];
         }
     }
     if (!empty($this->get)) {
         $vars['get'] = $this->get;
     } else {
         if (!empty($_SESSION['get'])) {
             $vars['get'] = $_SESSION['get'];
         }
     }
     if (!empty($_SESSION['user'])) {
         $vars['curUser'] = $_SESSION['user'];
     }
     echo $this->twig->render($template, $vars);
     $this->resetAlerts();
     unset($_SESSION['post']);
     unset($_SESSION['get']);
 }
예제 #9
0
 /**
  * @see IRenderEngine::fetch()
  */
 function fetch($template)
 {
     if (strpos('.', $template) === false) {
         $template .= '.html';
     }
     return $this->twig->render($template, $this->assignments);
 }
예제 #10
0
 /**
  * @param \Twig_Environment $environment
  * @param FieldableEntity $entity
  * @param string $field
  *
  * @return string
  * @internal param \Twig_Environment $environment
  */
 public function renderFieldDisplay(\Twig_Environment $environment, FieldableEntity $entity, $field)
 {
     $class = get_class($entity);
     $displayMapping = $this->displayManager->getEntityConfig($class);
     $fieldSettings = $this->fieldManager->getEntityFieldMapping($class);
     $html = '';
     if ($displayMapping['options']['fields'][$field]) {
         $displayFieldSettings = $displayMapping['options']['fields'][$field] + ['type' => null, 'label' => true, 'label_inline' => false, 'options' => []];
         $display = $this->displayManager->getDisplayDefinition($displayFieldSettings['type']);
         $fieldEntity = call_user_func([$entity, 'get' . $field]);
         $fieldDisplayOptions = $displayFieldSettings['options'] ?: [];
         $templateOptions = ['entity' => $fieldEntity, 'field_settings' => $fieldSettings, 'field_name' => $field, 'label' => is_string($displayFieldSettings['label']) ?: ($displayFieldSettings['label'] ? $field : false), 'label_inline' => $displayFieldSettings['label_inline']];
         if ($fieldSettings[$field]['options']['limit'] > 1) {
             $subHtml = '';
             $subTemplateOptions = $templateOptions;
             $subTemplateOptions['label'] = false;
             foreach ($fieldEntity as $fieldEntityItem) {
                 $subHtml .= $environment->render($display->getTemplate(), $subTemplateOptions + $display->getTemplateOptions($fieldEntityItem, $fieldDisplayOptions));
             }
             $templateOptions['rows'] = $subHtml;
             $html = $environment->render($display->getListTemplate(), $templateOptions + $display->getListTemplateOptions($fieldEntity, $fieldDisplayOptions));
         } else {
             $html = $environment->render($display->getTemplate(), $templateOptions + $display->getTemplateOptions($fieldEntity, $fieldDisplayOptions));
         }
     }
     return $html;
 }
예제 #11
0
 /**
  * {@inheritDoc}
  */
 public function process($layoutSrc, Response $response, array $placeResponses)
 {
     if (!$this->twig->hasExtension('supraPage')) {
         throw new \UnexpectedValueException('Missing for Supra Page extension.');
     }
     $response->setContent($this->twig->render($layoutSrc, array('responses' => $placeResponses)));
 }
 /**
  * @return string
  */
 public function summernoteInit()
 {
     $template = $this->parameters['init_template'];
     $options = [];
     $options['language'] = isset($this->parameters['language']) ? $this->parameters['language'] : null;
     $options['plugins'] = isset($this->parameters['plugins']) ? $this->parameters['plugins'] : null;
     $options['selector'] = $this->parameters['selector'];
     $options['width'] = $this->parameters['width'];
     $options['height'] = $this->parameters['height'];
     $options['include_jquery'] = $this->parameters['include_jquery'];
     $options['include_bootstrap'] = $this->parameters['include_bootstrap'];
     $options['include_fontawesome'] = $this->parameters['include_fontawesome'];
     $options['fontawesome_path'] = $this->parameters['fontawesome_path'];
     $options['bootstrap_css_path'] = $this->parameters['bootstrap_css_path'];
     $options['bootstrap_js_path'] = $this->parameters['bootstrap_js_path'];
     $options['jquery_path'] = $this->parameters['jquery_path'];
     $options['summernote_css_path'] = $this->parameters['summernote_css_path'];
     $options['summernote_js_path'] = $this->parameters['summernote_js_path'];
     $options['upload_images'] = $this->parameters['upload_images'];
     $options['image_upload_route'] = $this->parameters['image_upload_route'];
     $options['max_upload_size'] = $this->parameters['max_upload_size'];
     $options['toolbar'] = $this->prepareToolbar();
     $basePath = !isset($this->parameters['base_path']) ? 'bundles/adnsummernote/' : $this->parameters['base_path'];
     return $this->twig->render($template, ['sn' => $options, 'base_path' => $basePath]);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function render(array $context, $template = null)
 {
     if (null === $template) {
         $template = $this->template;
     }
     return $this->twig->render($template, $context);
 }
예제 #14
0
 public function indexAction(Request $request)
 {
     $response = new Response();
     $response->setPrivate();
     $response->setContent($this->twig->render('www/Index.twig', array()));
     return $response;
 }
 public function getBacktraceView(array $backtrace)
 {
     $result = [];
     $appRoot = realpath($this->appRoot . '/../');
     foreach ($backtrace as $k => $v) {
         $item = [];
         if (isset($v['file'])) {
             $item['location'] = str_replace($appRoot, '', $v['file']) . '(' . $v['line'] . ')';
             if (strpos($item['location'], '/vendor') === 0) {
                 $item['hidden'] = true;
                 foreach ($this->excludes as $exclude) {
                     if (preg_match('#^/vendor/' . $exclude . '#', $item['location'])) {
                         $item['hidden'] = false;
                         break;
                     }
                 }
             } else {
                 $item['hidden'] = false;
             }
         } else {
             $item['location'] = '[internal function]';
             $item['hidden'] = true;
         }
         if (isset($v['type'])) {
             $item['element'] = $v['class'] . $v['type'] . $v['function'] . '()';
         } else {
             $item['element'] = $v['function'] . '()';
         }
         $result[] = $item;
     }
     return $this->environment->render('AkhristenkoDoctrineStacktraceBundle:Backtrace:view.html.twig', ['backtrace' => $backtrace, 'result' => $result]);
 }
 /**
  * Renders a template.
  *
  * @param string $name    The template name
  * @param array  $context An array of parameters to pass to the template
  *
  * @return string The rendered template
  *
  * @throws \Twig_Error_Loader  When the template cannot be found
  * @throws \Twig_Error_Syntax  When an error occurred during compilation
  * @throws \Twig_Error_Runtime When an error occurred during rendering
  */
 public function render($name, array $context = array())
 {
     $e = $this->stopwatch->start(array('server' => 'localhost', 'group' => 'twig::render', 'twig_template' => (string) $name));
     $ret = $this->environment->render($name, $context);
     $e->stop();
     return $ret;
 }
 /**
  * @param  string $bucket
  * @return string
  */
 public function listAction($bucket)
 {
     $errors = [];
     $buckets = [];
     try {
         $result = $this->s3Client->listBuckets();
         $buckets = $result->get('Buckets');
     } catch (S3Exception $e) {
         $errors[] = sprintf('Cannot retrieve buckets: %s', $e->getMessage());
     }
     $objects = [];
     if (!empty($bucket)) {
         try {
             $maxIteration = 10;
             $iteration = 0;
             $marker = '';
             do {
                 $result = $this->s3Client->listObjects(['Bucket' => $bucket, 'Marker' => $marker]);
                 if ($result->get('Contents')) {
                     $objects = array_merge($objects, $result->get('Contents'));
                 }
                 if (count($objects)) {
                     $marker = $objects[count($objects) - 1]['Key'];
                 }
             } while ($result->get('IsTruncated') && ++$iteration < $maxIteration);
             if ($result->get('IsTruncated')) {
                 $errors[] = sprintf('The number of keys greater than %u, the first part is shown', count($objects));
             }
         } catch (S3Exception $e) {
             $errors[] = sprintf('Cannot retrieve objects: %s', $e->getMessage());
         }
     }
     return $this->twig->render('list.html.twig', ['selected_bucket' => $bucket, 'buckets' => $buckets, 'objects' => $objects, 'errors' => $errors]);
 }
예제 #18
0
 private final function buildTopNavMenu(ParameterBag $parameterBag)
 {
     static $tabDataContent = null;
     if (null === $tabDataContent) {
         $yamlParser = new Parser();
         $yamlNavigationPath = __DIR__ . '/../Resources/config/admin/navigation.yml';
         $tabConfiguration = $yamlParser->parse(file_get_contents($yamlNavigationPath));
         $explodedControllerInfo = explode('::', $parameterBag->get('_controller'));
         $explodedControllerName = explode('\\', $explodedControllerInfo[0]);
         $controllerNameIndex = count($explodedControllerName) - 1;
         $controllerName = $explodedControllerName[$controllerNameIndex];
         if (isset($tabConfiguration[$controllerName])) {
             // Construct tabs and inject into twig tpl
             $tabDataContent = array();
             // Get current route name to know when to put "current" class on HTML dom
             $currentRouteName = $parameterBag->get('_route');
             foreach ($tabConfiguration[$controllerName] as $tabName => $tabData) {
                 $tabData['isCurrent'] = false;
                 if ($currentRouteName === $tabData['route']) {
                     $tabData['isCurrent'] = true;
                 }
                 $tabDataContent[] = $this->environment->render('PrestaShopBundle:Admin/Common/_partials:_header_tab.html.twig', array('tabData' => $tabData));
             }
             // Inject them to templating system as global to be able to pass it to the legacy afterwards and once
             // controller has given a response
         }
     }
     return $tabDataContent;
 }
예제 #19
0
 /**
  * Render the activity
  *
  * @param ActivityStream $stream
  *
  * @return mixed
  */
 public function renderFilter(ActivityStream $stream)
 {
     $em = $this->objectManager->getRepository($stream->getObjectType());
     $entity = $em->find($stream->getObjectId());
     $bundleName = self::getBundleName($stream->getObjectType());
     return $this->twig->render($bundleName . ":Dashboard:" . $stream->getVerb() . ".html.twig", array('entity' => $entity, 'stream' => $stream));
 }
예제 #20
0
 /**
  * {@inheritdoc}
  */
 public function render(Field $field, $data)
 {
     if ('.' !== $field->getPath()) {
         $data = $this->dataExtractor->get($field, $data);
     }
     return $this->twig->render($field->getOptions()['template'], ['data' => $data]);
 }
예제 #21
0
 public function indexAction()
 {
     //        $this->init($app);
     $posts = $this->db->fetchAll('SELECT * FROM post');
     //var_dump($posts);
     return $this->twig->render('post/index.twig', array('posts' => $posts));
 }
예제 #22
0
 public function testAutoescapeOption()
 {
     $loader = new Twig_Loader_Array(array('html' => '{{ foo }} {{ foo }}', 'js' => '{{ bar }} {{ bar }}'));
     $twig = new Twig_Environment($loader, array('debug' => true, 'cache' => false, 'autoescape' => array($this, 'escapingStrategyCallback')));
     $this->assertEquals('foo&lt;br/ &gt; foo&lt;br/ &gt;', $twig->render('html', array('foo' => 'foo<br/ >')));
     $this->assertEquals('foo\\x3Cbr\\x2F\\x20\\x3E foo\\x3Cbr\\x2F\\x20\\x3E', $twig->render('js', array('bar' => 'foo<br/ >')));
 }
예제 #23
0
 /**
  * From the specified plugin name, create a directory
  * Create views/, cache/ and src/Namespace directories
  * Generate cli-config.php, doctrine-config.php and plugin-identifier.php
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pluginIdentifier = $input->getArgument('pluginIdentifier');
     $pluginNameParts = explode('-', $pluginIdentifier);
     array_walk($pluginNameParts, function (&$value, $key) {
         $value = ucfirst($value);
     });
     $pluginNamespace = join('', $pluginNameParts);
     $pluginName = join(' ', $pluginNameParts);
     $fs = new Filesystem();
     // create directories
     try {
         $fs->mkdir(array('../' . $pluginIdentifier, '../' . $pluginIdentifier . '/resources', '../' . $pluginIdentifier . '/resources/views', '../' . $pluginIdentifier . '/resources/public', '../' . $pluginIdentifier . '/data', '../' . $pluginIdentifier . '/data/cache', '../' . $pluginIdentifier . '/data/proxies', '../' . $pluginIdentifier . '/src', '../' . $pluginIdentifier . '/src/' . $pluginNamespace, '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type'));
     } catch (IOException $e) {
         $output->writeln('An error occured while creating directories: ' . $e->getMessage());
     }
     $templatesDirectory = __DIR__ . '/../../../templates';
     // generate files
     $loader = new \Twig_Loader_Filesystem($templatesDirectory);
     $twig = new \Twig_Environment($loader);
     file_put_contents('../' . $pluginIdentifier . '/doctrine-config.php', $twig->render('doctrine-config.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace)));
     file_put_contents('../' . $pluginIdentifier . '/' . $pluginIdentifier . '.php', $twig->render('plugin.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace, 'pluginName' => $pluginName)));
     file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller/DefaultController.php', $twig->render('src/DefaultController.php.twig', array('pluginNamespace' => $pluginNamespace)));
     file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity/Person.php', $twig->render('src/Person.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace)));
     file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type/PersonType.php', $twig->render('src/PersonType.php.twig', array('pluginNamespace' => $pluginNamespace)));
     // copy files
     $fs->copy($templatesDirectory . '/resources/views/index.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/index.html.twig');
     $fs->copy($templatesDirectory . '/resources/views/create.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/create.html.twig');
     $fs->copy($templatesDirectory . '/resources/views/edit.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/edit.html.twig');
     $output->writeln('Created "' . $pluginName . '" plugin in "' . $pluginIdentifier . '".');
     $output->writeln('Please ensure both "' . $pluginIdentifier . '/data/cache" and "' . $pluginIdentifier . '/data/proxies" exist and are writable by Apache\'s user.');
     $output->writeln('To finish, you need to activate your plugin in "Plugins".');
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public function render(Field $field, $data, array $options)
 {
     if ('.' !== $field->getPath()) {
         $data = $this->dataExtractor->get($field, $data);
     }
     return $this->twig->render($options['template'], ['data' => $data, 'options' => $options]);
 }
예제 #25
0
 /**
  * @param FormView $form
  */
 protected function renderBlock(FormView $form)
 {
     if (isset($form->vars['block_config'])) {
         foreach ($form->vars['block_config'] as $code => $blockConfig) {
             $this->createBlock($code, $blockConfig);
         }
     }
     foreach ($form->children as $name => $child) {
         if (isset($child->vars['block']) || isset($child->vars['subblock'])) {
             $block = null;
             if ($this->formConfig->hasBlock($child->vars['block'])) {
                 $block = $this->formConfig->getBlock($child->vars['block']);
             }
             if (!$block) {
                 $blockCode = $child->vars['block'];
                 $block = $this->createBlock($blockCode);
                 $this->formConfig->addBlock($block);
             }
             $subBlock = $this->getSubBlock($name, $child, $block);
             $tmpChild = $child;
             $formPath = '';
             while ($tmpChild->parent) {
                 $formPath = sprintf('.children[\'%s\']', $tmpChild->vars['name']) . $formPath;
                 $tmpChild = $tmpChild->parent;
             }
             $subBlock->addData($this->env->render('{{ form_row(' . $this->formVariableName . $formPath . ') }}', $this->context));
         }
         $this->renderBlock($child);
     }
 }
예제 #26
0
 protected function processPart(Email\Part $part)
 {
     if (!$part instanceof Email\TwigTemplatePart) {
         return;
     }
     $part->setContent($this->twig->render($part->getTemplateName(), $part->getVars()));
 }
 /**
  * @param $date
  * @param $item
  * @param $precision 
  * @param $route_new
  * @param $route_show 
  */
 public function renderDay($date, $item, $project, $precision, $route_new, $route_show)
 {
     $start = new \DateTime($date);
     $end = (new \DateTime($date))->modify('+1 day');
     $bookings = $this->doctrine->getRepository($this->entity)->createQueryBuilder('b')->select('b')->where('b.start <= :start and b.end >= :end')->orwhere('b.end >= :start and b.end <= :end')->orwhere('b.start >= :start and b.start <= :end')->andWhere('b.item = :item')->orderBy('b.start', 'ASC')->setParameters(array('start' => $start, 'end' => $end, 'item' => $item))->getQuery()->getResult();
     return $this->environment->render('SladBookingBundle:Calendar:day.html.twig', array('date' => new \DateTime($date), 'item' => $item, 'project' => $project, 'bookings' => $bookings, 'precision' => $precision, 'route_new' => $route_new, 'route_show' => $route_show));
 }
 /**
  * @param string $instance
  * @param array  $parameters
  *
  * @throws \Twig_Error_Runtime
  *
  * @return mixed
  */
 public function summernote($instance = 'default', $selector = '.summenote', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0'))
 {
     if (!is_string($instance)) {
         throw new Twig_Error_Runtime('The function can be applied to strings only.');
     }
     return $this->twig->render('FMElfinderBundle:Elfinder/helper:_summernote.html.twig', array('instance' => $instance, 'selector' => $selector, 'width' => $parameters['width'], 'height' => $parameters['height'], 'title' => $parameters['title']));
 }
예제 #29
0
 public function render($name, array $values = array())
 {
     if (defined('ENV_DEV')) {
         $this->engine->clearCacheFiles();
         $this->engine->clearTemplateCache();
     }
     return $this->engine->render($name . $this->suffix, $values);
 }
예제 #30
-6
 /**
  * @param $fromEmail
  * @param BatchEntryMail $batchMail
  * @param $doSend
  */
 private function sendBatchMail($fromEmail, BatchEntryMail $batchMail, $doSend)
 {
     $receivers = $batchMail->getReceiverEntries($this->em);
     $this->writeOutput('Sending "' . $batchMail->getName() . '" mail to ' . count($receivers) . ' people from ' . $fromEmail);
     $spool = $this->mailer->getTransport()->getSpool();
     foreach ($receivers as $receiver) {
         try {
             $this->writeOutput(' -> ' . $receiver->getEmail());
             $htmlTemplate = $batchMail->getHtmlTemplate($receiver);
             $plainTextTemplate = $batchMail->getPlainTextTemplate($receiver);
             $templateData = $batchMail->getTemplateData($receiver, $this->em);
             $this->translator->setLocale($receiver->getPool()->getLocale());
             $plainTextBody = $this->twig->render($plainTextTemplate, $templateData);
             $htmlBody = $this->twig->render($htmlTemplate, $templateData);
             $message = \Swift_Message::newInstance()->setSubject($batchMail->getSubject($receiver, $this->translator))->setFrom($fromEmail, $batchMail->getFrom($receiver, $this->translator))->setTo($receiver->getEmail())->setBody($plainTextBody)->addPart($htmlBody, 'text/html');
             if ($doSend) {
                 $this->mailer->send($message);
                 $batchMail->handleMailSent($receiver, $this->em);
             }
         } catch (\Exception $e) {
             $this->writeOutput(sprintf('<error>An error occurred while sending mail for email "%s"</error>', $receiver->getEmail()));
             // mark as handled, as otherwise the system will keep retrying over and over again
             $batchMail->handleMailSent($receiver, $this->em);
         }
     }
     if ($doSend) {
         // only flush queue at the end of a batch
         $spool->flushQueue($this->transport);
     }
 }