diff --git a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php index 9b7b83e7f..e69d470ed 100644 --- a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php @@ -23,12 +23,9 @@ use CachetHQ\Cachet\Models\Meta; use CachetHQ\Cachet\Services\Dates\DateFactory; use Carbon\Carbon; use Illuminate\Contracts\Auth\Guard; - use Twig\Environment as Twig_Environment; use Twig\Loader\ArrayLoader as Twig_Loader_Array; - - /** * This is the create incident command handler. * @@ -67,7 +64,7 @@ class CreateIncidentCommandHandler $this->auth = $auth; $this->dates = $dates; - $this->twigConfig = config("cachet.twig"); + $this->twigConfig = config('cachet.twig'); } /** @@ -138,31 +135,34 @@ class CreateIncidentCommandHandler return $incident; } - protected function sandboxedTwigTemplateData(String $templateData) { - + protected function sandboxedTwigTemplateData(string $templateData) + { if (!$templateData) { - return ""; + return ''; } - $policy = new \Twig\Sandbox\SecurityPolicy($this->twigConfig["tags"], - $this->twigConfig["filters"], - $this->twigConfig["methods"], - $this->twigConfig["props"], - $this->twigConfig["functions"]); + $policy = new \Twig\Sandbox\SecurityPolicy( + $this->twigConfig['tags'], + $this->twigConfig['filters'], + $this->twigConfig['methods'], + $this->twigConfig['props'], + $this->twigConfig['functions'] + ); $sandbox = new \Twig\Extension\SandboxExtension($policy); $templateBasicLoader = new Twig_Loader_Array([ - 'firstStageLoader' => $templateData + 'firstStageLoader' => $templateData, ]); $sandBoxBasicLoader = new Twig_Loader_Array([ - 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}' + 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}', ]); $hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]); $twig = new Twig_Environment($hardenedLoader); $twig->addExtension($sandbox); + return $twig; } @@ -191,7 +191,7 @@ class CreateIncidentCommandHandler 'component_status' => $command->component_status, ], ]); - + return $template->render('secondStageLoader', $vars); } } diff --git a/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index 7f6074128..1bece52a5 100644 --- a/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -21,8 +21,6 @@ use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\IncidentTemplate; use CachetHQ\Cachet\Services\Dates\DateFactory; use Illuminate\Contracts\Auth\Guard; -use Twig\Environment as Twig_Environment; -use Twig\Loader\ArrayLoader as Twig_Loader_Array; /** * This is the update incident command handler. @@ -65,7 +63,7 @@ class UpdateIncidentCommandHandler $this->auth = $auth; $this->dates = $dates; - $this->twigConfig = $twigConfig = config("cachet.twig"); + $this->twigConfig = $twigConfig = config('cachet.twig'); } /** @@ -147,25 +145,29 @@ class UpdateIncidentCommandHandler }); } - protected function sandboxedTwigTemplateData(String $templateData) { - $policy = new \Twig\Sandbox\SecurityPolicy($this->twigConfig["tags"], - $this->twigConfig["filters"], - $this->twigConfig["methods"], - $this->twigConfig["props"], - $this->twigConfig["functions"]); + protected function sandboxedTwigTemplateData(string $templateData) + { + $policy = new \Twig\Sandbox\SecurityPolicy( + $this->twigConfig['tags'], + $this->twigConfig['filters'], + $this->twigConfig['methods'], + $this->twigConfig['props'], + $this->twigConfig['functions'] + ); $sandbox = new \Twig\Extension\SandboxExtension($policy); $templateBasicLoader = new \Twig\Loader\ArrayLoader([ - 'firstStageLoader' => $templateData + 'firstStageLoader' => $templateData, ]); $sandBoxBasicLoader = new \Twig\Loader\ArrayLoader([ - 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}' + 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}', ]); $hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]); $twig = new \Twig\Environment($hardenedLoader); $twig->addExtension($sandbox); + return $twig; } @@ -194,7 +196,7 @@ class UpdateIncidentCommandHandler 'component_status' => $command->component_status, ], ]); - + return $template->render('secondStageLoader', $vars); } } diff --git a/config/cachet.php b/config/cachet.php index b8f41b899..6e0c9f8de 100644 --- a/config/cachet.php +++ b/config/cachet.php @@ -46,7 +46,6 @@ return [ 'beacon' => env('CACHET_BEACON', true), - /* |-------------------------------------------------------------------------- | Templates configurations @@ -58,10 +57,10 @@ return [ | */ 'twig' => [ - 'methods' => [], + 'methods' => [], 'functions' => [], - 'filters' => ['escape'], - 'tags' => ['if'], - 'props' => [], - ] + 'filters' => ['escape'], + 'tags' => ['if'], + 'props' => [], + ], ];