0

Ok, ill try to explain as easy as possible: In my PHP Web Application in which i have setup some automated Tasks with "lavary/crunz".

The Problem i am facing is when trying to use "Twig Templating engine" to create my Email Body, somehow it wont work and i the error message i get when debugging is not helpfull.:

class MyClass
{
    public static function _testTask()
        {
        $receiver = ['email'=>COMPANY_EMAIL,'name'=>COMPANY_NAME];
        return function() use($receiver)
               {
                $mail = new \MailerCtrl();

                $loader = new \Twig_Loader_Filesystem("views/templates");
                $twig = new \Twig_Environment($loader,["cache" => "views/cache"]);

                $content = array('name'=>'My Name','age'=>25);
                $subject = 'Something';
                $mail->send($subject,$receiver,$twig->render('report.html.twig', $content));
               };
    }
}



$schedule->run(MyClass::_testTask())->cron('* * * * *');

My MailerCtrl class is a simple PHPMailer representation which expects the html body i expect to render from $twig->render('report.html.twig', $content);

Is there another or even a better way to accomplish this? When i call this script from http it works as expected but when running it through "crunz" i am getting this error:

PHP Catchable fatal error:

Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given, called in /home/httpd/vhosts//httpdocs/vendor/twig/twig/lib/Twig/Extension/Core.php on line 139 and defined in /home/httpd/vhosts//httpdocs/vendor/twig/twig/lib/Twig/Filter.php on line 35

jhon dano
  • 660
  • 6
  • 23

1 Answers1

1

HTTP is running PHP 7 and

"lavary/crunz"

via PHP command line isn't running PHP 7 as Twig 2.0 is required at least PHP 7 as describe here: https://stackoverflow.com/a/41888528/1865829

Update your PHP command line to 7 and it should work.

Shahbaz
  • 326
  • 5
  • 18