Exemplo n.º 1
0
 protected function render($template, $data = [])
 {
     foreach ($data as $key => $value) {
         $this->smarty->assign($key, $value);
     }
     return $this->smarty->fetch(__DIR__ . DS . "fixtures" . DS . $template);
 }
Exemplo n.º 2
0
 public function generate(ModuleGenerateEvent $event)
 {
     $templates = $this->findInPath($event->getResourcesPath(), "/__MODULE__.*\\.php\$/");
     $this->parser->assign("moduleCode", $event->getModuleCode());
     $this->parser->assign("tables", $event->getEntities());
     $this->processModule($templates, $event->getResourcesPath(), $event->getModulePath(), $event->getModuleCode());
 }
Exemplo n.º 3
0
 protected function internalRender($resourceType, $resourceContent, array $data)
 {
     foreach ($data as $key => $value) {
         $this->smarty->assign($key, $value);
     }
     return $this->smarty->fetch(sprintf("%s:%s", $resourceType, $resourceContent));
 }
Exemplo n.º 4
0
 /**
  * @param  \TheliaStudio\Parser\Entity\Table $table
  * @param  \SplFileInfo[]                    $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processTemplate(Table $table, $templates, $resourcesPath, $moduleCode)
 {
     $this->parser->assign("table", $table);
     foreach ($templates as $template) {
         $fetchedTemplate = $this->parser->fetch($template->getRealPath());
         $fileName = str_replace("__TABLE__", str_replace("_", "-", $table->getRawTableName()), $template->getFilename());
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = THELIA_MODULE_DIR . $moduleCode . DS . $relativePath . DS . $fileName;
         $this->writeFile($completeFilePath, $fetchedTemplate, false, true);
     }
 }
Exemplo n.º 5
0
 /**
  * @param  ModuleGenerateEvent $event
  * @return mixed
  */
 protected function generate(ModuleGenerateEvent $event)
 {
     $formConfig = $this->readConfigFormFile($event->getModulePath());
     if (empty($formConfig)) {
         return;
     }
     $this->parser->assign("form", $formConfig);
     $this->parser->assign("moduleCode", $event->getModuleCode());
     $this->generateClasses($event->getResourcesPath(), $event->getModulePath(), $event->getModuleCode());
     $this->generateTemplates($event->getResourcesPath(), $event->getModulePath(), $event->getModuleCode());
     $this->generateConfiguration($event->getModulePath(), $event->getModuleCode());
     $this->generateRouting($event->getModulePath(), $event->getModuleCode());
 }
Exemplo n.º 6
0
 /**
  * Create message with HTML and TEXT body from template HTMl and TEXT fields
  * using a text and a html layout
  */
 public function testMessageWithTextAndHtmlBodyAndTextAndHtmlExtendableLayout()
 {
     $message = new ModelMessage();
     $message->setLocale('fr_FR');
     $message->setSubject("The subject");
     $message->setTextMessage('TEXT <template> & content v={$myvar}');
     $message->setHtmlMessage('HTML <template> & content v={$myvar}');
     $message->setHtmlLayoutFileName('layout6.html.tpl');
     $message->setTextLayoutFileName('layout6.text.tpl');
     $path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
     $this->parser->assign('myvar', 'my-value');
     file_put_contents($path . DS . 'layout6.html.tpl', 'HTML Layout 6: {block name="message-body"}{$message_body nofilter}{/block}');
     file_put_contents($path . DS . 'layout6.text.tpl', 'TEXT Layout 6: {block name="message-body"}{$message_body nofilter}{/block}');
     $instance = \Swift_Message::newInstance();
     $message->buildMessage($this->parser, $instance);
     $this->assertEquals("The subject", $instance->getSubject());
     $this->assertEquals("HTML Layout 6: HTML <template> & content v=my-value", $instance->getBody());
     $this->assertEquals("TEXT Layout 6: TEXT <template> & content v=my-value", $instance->getChildren()[0]->getBody());
 }
Exemplo n.º 7
0
 /**
  * Initialize the smarty parser.
  *
  * The intl function is replaced, and locales are assigned.
  *
  * @throws \SmartyException
  */
 protected function initParser()
 {
     $this->parser->unregisterPlugin('function', 'intl');
     $this->parser->registerPlugin('function', 'intl', [$this, 'translate']);
     $this->parser->assign("locales", $this->locales);
 }
Exemplo n.º 8
0
 /**
  * Process a {forhook rel="hookname"} ... {/forhook}
  *
  * The forhook iterates over the results return by a hookblock :
  *
  * {hookblock name="product.additional"}
  *      {forhook rel="product.additional"}
  *          <div id="{$id}">
  *              <h2>{$title}</h2>
  *              <p>{$content}</p>
  *          </div>
  *      {/forhook}
  * {/hookblock}
  *
  * @param array        $params
  * @param string       $content
  * @param \TheliaSmarty\Template\SmartyParser $smarty
  * @param bool         $repeat
  *
  * @throws \InvalidArgumentException
  * @return string                    the generated content
  */
 public function processForHookBlock($params, $content, $smarty, &$repeat)
 {
     $rel = $this->getParam($params, 'rel');
     if (null == $rel) {
         throw new \InvalidArgumentException($this->translator->trans("Missing 'rel' parameter in forHook arguments"));
     }
     /** @var FragmentBag $fragments */
     $fragments = null;
     // first call
     if ($content === null) {
         if (!array_key_exists($rel, $this->hookResults)) {
             throw new \InvalidArgumentException($this->translator->trans("Related hook name '%name' is not defined.", ['%name' => $rel]));
         }
         $fragments = $this->hookResults[$rel];
         $fragments->rewind();
         if ($fragments->isEmpty()) {
             $repeat = false;
         }
     } else {
         $fragments = $this->hookResults[$rel];
         $fragments->next();
     }
     if ($fragments->valid()) {
         /** @var Fragment $fragment */
         $fragment = $fragments->current();
         // On first iteration, save variables that may be overwritten by this hook
         if (!isset($this->varstack[$rel])) {
             $saved_vars = array();
             $varlist = $fragment->getVars();
             foreach ($varlist as $var) {
                 $saved_vars[$var] = $smarty->getTemplateVars($var);
             }
             $this->varstack[$rel] = $saved_vars;
         }
         foreach ($fragment->getVarVal() as $var => $val) {
             $smarty->assign($var, $val);
         }
         // continue iteration
         $repeat = true;
     }
     // end
     if (!$repeat) {
         // Restore previous variables values before terminating
         if (isset($this->varstack[$rel])) {
             foreach ($this->varstack[$rel] as $var => $value) {
                 $smarty->assign($var, $value);
             }
             unset($this->varstack[$rel]);
         }
     }
     if ($content !== null) {
         if ($fragments->isEmpty()) {
             $content = "";
         }
         return $content;
     }
     return '';
 }