Beispiel #1
0
 /**
  * Render the notifications' script tag
  *
  * @return string
  * @internal param bool $flashed Whether to get the
  *
  */
 public function render()
 {
     $notifications = $this->session->get('toastr::notifications');
     if (!$notifications) {
         $notifications = [];
     }
     $output = '<script type="text/javascript">';
     $lastConfig = [];
     foreach ($notifications as $notification) {
         $config = $this->config->get('toastr.options');
         if (count($notification['options']) > 0) {
             // Merge user supplied options with default options
             $config = array_merge($config, $notification['options']);
         }
         // Config persists between toasts
         if ($config != $lastConfig) {
             $output .= 'toastr.options = ' . json_encode($config) . ';';
             $lastConfig = $config;
         }
         // Toastr output
         $output .= 'toastr.' . $notification['type'] . "('" . str_replace("'", "\\'", str_replace(['&lt;', '&gt;'], ['<', '>'], e($notification['message']))) . "'" . (isset($notification['title']) ? ", '" . str_replace("'", "\\'", htmlentities($notification['title'])) . "'" : null) . ');';
     }
     $output .= '</script>';
     return $output;
 }
 protected function mockApplication()
 {
     $app = m::mock(ApplicationStub::class)->makePartial();
     $app->singleton('config', function () {
         $repo = new \Illuminate\Config\Repository();
         $repo->set('jwt', include __DIR__ . '/../config/jwt.php');
         return $repo;
     });
     $app->singleton(\Illuminate\Contracts\Cache\Repository::class, function () {
         return m::mock(\Illuminate\Contracts\Cache\Repository::class);
     });
     return $app;
 }
Beispiel #3
0
 /**
  * Injects the alerts into the given Response.
  * Based on https://github.com/barryvdh/laravel-debugbar/blob/master/src/LaravelDebugbar.php
  *
  * @param \Symfony\Component\HttpFoundation\Response $response A Response instance
  */
 protected function injectAlerts(Response $response)
 {
     $app = $this->app;
     $containerId = $this->config->get('kotfire/system-alerts::container_id');
     $htmlContainer = 'id="' . $containerId . '"';
     $content = $response->getContent();
     $pos = strripos($content, $htmlContainer);
     if ($pos !== false) {
         // Search end of the open html tag
         $pos = strpos($content, '>', $pos);
         if ($pos !== false) {
             $alerts = $this->loadAlerts();
             // Load view
             $view = View::make('kotfire/system-alerts::template')->with('alerts', $alerts)->render();
             // Set position at the end of the container open tag
             $pos += 1;
             // Inject view into content
             $content = substr($content, 0, $pos) . $view . substr($content, $pos);
         }
     }
     $response->setContent($content);
 }