Пример #1
0
 /**
  * @param  \SplFileInfo[]   $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processModule($templates, $resourcesPath, $modulePath, $moduleCode)
 {
     foreach ($templates as $template) {
         $fileName = str_replace("__MODULE__", $moduleCode, $template->getFilename());
         $fileName = str_replace("FIX", "", $fileName);
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = $modulePath . $relativePath . DS . $fileName;
         $isFix = false !== strpos($template->getFilename(), "FIX");
         // Expect special rule for Module\Module
         $isModuleClass = $modulePath . $relativePath . DS . $moduleCode . ".php" === $completeFilePath;
         if ($isFix && !file_exists($completeFilePath) || !$isFix) {
             if ($isModuleClass && is_file($completeFilePath)) {
                 $caught = false;
                 try {
                     $reflection = new \ReflectionClass("{$moduleCode}\\{$moduleCode}");
                 } catch (\ReflectionException $e) {
                     $caught = true;
                     // The class is not valid
                 }
                 if (!$caught && $reflection->hasConstant("MESSAGE_DOMAIN")) {
                     continue;
                     // If the class already have the constant, don't override it
                 }
             }
             $fetchedTemplate = $this->parser->fetch($template->getRealPath());
             $this->writeFile($completeFilePath, $fetchedTemplate, true, true);
         }
     }
 }
Пример #2
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);
     }
 }
Пример #3
0
 /**
  * @param Table          $table
  * @param \SplFileInfo[] $templates
  * @param $resourcesPath
  * @param $moduleCode
  */
 protected function processPhp(Table $table, $templates, $resourcesPath, $moduleCode, $modulePath)
 {
     $this->parser->assign("table", $table);
     foreach ($templates as $template) {
         $fileName = str_replace("__TABLE__", $table->getTableName(), $template->getFilename());
         $fileName = str_replace("FIX", "", $fileName);
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = $modulePath . DS . $relativePath . DS . $fileName;
         $isFix = false !== strpos($template->getFilename(), "FIX");
         $isI18n = false !== strpos($template->getFilename(), "I18n");
         if (($isFix && !file_exists($completeFilePath) || !$isFix) && ($isI18n && $table->hasI18nBehavior() || !$isI18n)) {
             $fetchedTemplate = $this->parser->fetch($template->getRealPath());
             $this->writeFile($completeFilePath, $fetchedTemplate, true, true);
         }
     }
 }
Пример #4
0
 protected function generateTemplates($resourcesPath, $modulePath, $moduleCode)
 {
     $templates = $this->findInPath($resourcesPath, "/__CONFIG_FORM__.*\\.html/");
     $previousLeft = $this->parser->left_delimiter;
     $previousRight = $this->parser->right_delimiter;
     $this->parser->left_delimiter = '[{';
     $this->parser->right_delimiter = '}]';
     /** @var \SplFileInfo $template */
     foreach ($templates as $template) {
         $fetchedTemplate = $this->parser->fetch($template->getRealPath());
         $relativePath = str_replace($resourcesPath, '', $template->getRealPath());
         $relativePath = str_replace("__CONFIG_FORM__", strtolower($moduleCode), $relativePath);
         $fullPath = $modulePath . $relativePath;
         $this->writeFile($fullPath, $fetchedTemplate, false, true);
     }
     $this->parser->left_delimiter = $previousLeft;
     $this->parser->right_delimiter = $previousRight;
 }
Пример #5
0
 /**
  * Add a subject and a body (TEXT, HTML or both, depending on the message
  * configuration.
  *
  * @param  ParserInterface $parser
  * @param  \Swift_Message  $messageInstance
  * @param  bool            $useFallbackTemplate When we send mail from a module and don't use the `default` email
  *                                              template, if the file (html/txt) is not found in the template then
  *                                              the template file located in the module under
  *                                              `templates/email/default/' directory is used if
  *                                              `$useFallbackTemplate` is set to `true`.
  */
 public function buildMessage(ParserInterface $parser, \Swift_Message $messageInstance, $useFallbackTemplate = true)
 {
     $parser->setTemplateDefinition($parser->getTemplateHelper()->getActiveMailTemplate(), $useFallbackTemplate);
     $subject = $parser->fetch(sprintf("string:%s", $this->getSubject()));
     $htmlMessage = $this->getHtmlMessageBody($parser);
     $textMessage = $this->getTextMessageBody($parser);
     $messageInstance->setSubject($subject);
     // If we do not have an HTML message
     if (empty($htmlMessage)) {
         // Message body is the text message
         $messageInstance->setBody($textMessage, 'text/plain');
     } else {
         // The main body is the HTML messahe
         $messageInstance->setBody($htmlMessage, 'text/html');
         // Use the text as a message part, if we have one.
         if (!empty($textMessage)) {
             $messageInstance->addPart($textMessage, 'text/plain');
         }
     }
     return $messageInstance;
 }