diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index eac262be4..0760e8cec 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1515,9 +1515,9 @@ App::post('/v1/account/recovery') $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $profile->getId(), 'secret' => $secret, 'expire' => $expire]); $url = Template::unParseURL($url); - $body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl'); + $body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl'); $content = Template::fromHtmlString($locale->getText('account.emails.recovery.body')); - $cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl'); + $cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl'); $body ->setParam('{{content}}', $content->render(false)) @@ -1719,9 +1719,9 @@ App::post('/v1/account/verification') $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $verificationSecret, 'expire' => $expire]); $url = Template::unParseURL($url); - $body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl'); + $body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl'); $content = Template::fromHtmlString($locale->getText('account.emails.verification.body')); - $cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl'); + $cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl'); $body ->setParam('{{content}}', $content->render(false)) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 66cf88149..34b6bdffd 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -419,9 +419,9 @@ App::post('/v1/teams/:teamId/memberships') $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['membershipId' => $membership->getId(), 'teamId' => $team->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]); $url = Template::unParseURL($url); - $body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl'); + $body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl'); $content = Template::fromHtmlString($locale->getText('account.emails.invitation.body')); - $cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl'); + $cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl'); $title = \sprintf($locale->getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])); $body diff --git a/src/Appwrite/Template/Template.php b/src/Appwrite/Template/Template.php index 7b880a9ef..5c0c7c9db 100644 --- a/src/Appwrite/Template/Template.php +++ b/src/Appwrite/Template/Template.php @@ -5,9 +5,32 @@ namespace Appwrite\Template; use Exception; use Utopia\View; +use function PHPUnit\Framework\isReadable; + class Template extends View { + /** + * fromFile + * + * Creates a new Template() from the file at $path + * + * @param string $path + * + * @return self + * + */ + public static function fromFile(string $path): self + { + if (\is_readable($path)) { + throw new Exception("$path view template is not readable."); + } + + $template = new Template(); + return $template->setPath($path); + } + + /** * @var string */ @@ -28,6 +51,7 @@ class Template extends View if (empty($html)) { throw new Exception('Empty HTML string'); } + $template = new Template(); return $template->setHtml($html); }