/** * {@inheritdoc} */ public function run(Core $app, Http $answer) : Answer { # Create the render and set some attributes $render = new Html($app->getCore() . 'views/welcome.php'); # Returns the answer return $answer->setData($render->run($app)); }
/** * {@inheritdoc} */ public function run(Core $app, Http $answer) : Answer { # Set a default error $answer->setStatus(500); $data['error'] = $data['title'] = 'Exception'; # Create the render and set some attributes $render = new Html($app->getCore() . 'views/exception.php'); if ($app->getException() !== null) { # Core custom exception only if ($app->getException() instanceof \Core\HttpException) { $answer->setStatus($app->getException()->getStatus()); } if (defined('insight')) { # Get the detailed exception $data['error'] = sprintf("%s\n\n# %s(%s)\n%s", $app->getException()->getMessage(), $app->getException()->getFile(), $app->getException()->getLine(), str_replace('Stack trace:', '', $app->getException()->getTraceAsString())); } else { # Get an user acceptable error message $data['error'] = $app->getException()->getMessage(); } } # Returns the answer return $answer->setData($render->run($app, $data)); }
public function testDisplay() { $render = new Html($this->view); ob_start(); $render->display('&'); $stream = ob_get_clean(); $this->assertEquals('&', $stream); }
public function testMailRun() { $raw = new Letter(); $raw->setType('text/plain'); $raw->setData('This mail was automatically sent running the unit tests of Core without render.'); $render = new Html($this->letter); $html = new Letter(); $html->setData($render->run(null, ['title' => 'Core Mail', 'custom' => 'This mail was automatically sent running the unit tests of Core with the render.'])); $attachment = new Attachment('Invoice.pdf'); $attachment->setType('application/pdf'); $attachment->setData($this->attachment); $mail = new Mail(['*****@*****.**']); $mail->setSender('*****@*****.**', 'Developers'); $mail->setSubject('Core Mail'); $mail->addLetter($raw); $mail->addLetter($html); $mail->addAttachment($attachment); $mail->run(); }
/** * Try to inject the insight in an html answer * * @param Answer $answer * @return Answer */ protected function doInjectInsight(Answer $answer) : Answer { if (defined('insight') && $answer instanceof Http && $answer->getType() === 'text/html') { $render = new Html($this->getCore() . 'views/insight.php'); # Try to puts the insight addition into the html body $insight = str_replace('</body>', $render->run($this) . '</body>', $answer->getData(), $count); # Add only when there is 1 occurrence of the replacement (malformed html) if ($count === 1) { $answer->setData($insight); } } return $answer; }