TemplateDisplayWrapper.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\App;
  3. use \ThurData\Servers\KerioEmail\Core\ServiceLocator;
  4. /**
  5. * Template Display Wrapper
  6. *
  7. * @author slawomir@thurdata.com
  8. */
  9. class TemplateDisplayWrapper
  10. {
  11. use \ThurData\Servers\KerioEmail\Core\Traits\Lang;
  12. protected $templateName = null;
  13. protected $templateDir = null;
  14. protected $vars = [];
  15. public function __construct($templateName = null, $templateDir = null, $vars = [], $lang = null)
  16. {
  17. $this->setTemplate($templateName, $templateDir);
  18. $this->setVars($vars);
  19. $this->setLang($lang);
  20. }
  21. public function toHtml()
  22. {
  23. $pageContent = ServiceLocator::call('smarty')
  24. ->setLang($this->lang)
  25. ->setTemplateDir($path)
  26. ->view($fileName, $vars);
  27. return $pageContent;
  28. }
  29. public function setTemplate($templateName = null, $templateDir = null)
  30. {
  31. if (file_exists($templateDir . DIRECTORY_SEPARATOR . $templateName . '.tpl'))
  32. {
  33. $this->templateName = $templateName;
  34. $this->templateDir = $templateDir;
  35. }
  36. }
  37. public function setVars($vars = [])
  38. {
  39. if (is_array($vars))
  40. {
  41. $this->vars = $vars;
  42. }
  43. }
  44. public function setLang($lang = null)
  45. {
  46. if ($lang instanceof \ThurData\Servers\KerioEmail\Core\Lang)
  47. {
  48. $this->lang = $lang;
  49. }
  50. $this->loadLang();
  51. }
  52. }