Ejemplo n.º 1
0
 /**
  * Execute PHP code and send result message in connector
  * @param $code
  */
 public function dispatchCode($code)
 {
     if ($this->isActive()) {
         $previousLastError = error_get_last();
         $oldDisplayErrors = ini_set('display_errors', false);
         $result = $this->evalProvider->evaluate($code);
         ini_set('display_errors', $oldDisplayErrors);
         $message = new \PhpConsole\EvalResultMessage();
         $message->return = $this->dumper->dump($result->return);
         $message->output = $this->dumper->dump($result->output);
         $message->time = round($result->time, 6);
         $newLastError = error_get_last();
         if ($newLastError && $newLastError != $previousLastError) {
             $this->connector->getErrorsDispatcher()->dispatchError($newLastError['type'], $newLastError['message'], $newLastError['file'], $newLastError['line'], 999);
         }
         if ($result->exception) {
             $this->connector->getErrorsDispatcher()->dispatchException($result->exception);
         }
         $this->sendMessage($message);
     }
 }
Ejemplo n.º 2
0
 public function testThrowedInCodeExceptionIsCaught()
 {
     $result = $this->evalProvider->evaluate('throw new \\Exception(123)');
     $this->assertEquals(123, $result->exception->getMessage());
 }