示例#1
0
 /**
  * {@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));
 }
示例#2
0
 public function testRun()
 {
     $render = new Html($this->view);
     $this->assertEquals('N;', $render->run(null, null));
     $this->assertEquals('s:4:"null";', $render->run(null, 'null'));
     $this->assertEquals('s:0:"";', $render->run(null, ''));
     $this->assertEquals('i:0;', $render->run(null, 0));
     $this->assertEquals('i:123;', $render->run(null, 123));
     $this->assertEquals('a:0:{}', $render->run(null, []));
     $this->assertEquals('a:1:{s:2:"id";i:123;}', $render->run(null, ['id' => 123]));
 }
示例#3
0
 /**
  * {@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));
 }
示例#4
0
 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();
 }
示例#5
0
 /**
  * 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;
 }