/** * Flash used container names. * * @param Notification $notification * @return void */ protected function flashContainerNames(Notification $notification) { $names = array(); foreach ($notification->getContainers() as $container) { $names[] = $container->getName(); } $this->getSession()->flash($this->getConfig()->get('notification.session_prefix') . 'containers', $names); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $containerNames = $this->session->get($this->sessionPrefix . 'containers', array()); $sessionVariables = $this->session->all(); foreach ($containerNames as $containerName) { foreach ($sessionVariables as $sessionKey => $value) { if (strpos($sessionKey, $this->sessionPrefix . $containerName) === 0 && is_string($value)) { $jsonMessage = json_decode($value); $this->notification->container($containerName)->add($jsonMessage->type, new Message($jsonMessage->type, $jsonMessage->message, false, $jsonMessage->format, $jsonMessage->alias, $jsonMessage->position), false); } } } return $next($request); }
/** * Register the service provider. * * @return void */ public function register() { $this->app['config']->package('edvinaskrucas/notification', __DIR__ . '/../config'); $this->app['notification'] = $this->app->share(function ($app) { $config = $app['config']; $notification = new Notification($config->get('notification::default_container'), $config->get('notification::default_types'), $config->get('notification::default_format'), $config->get('notification::default_formats')); $notification->setEventDispatcher($app['events']); return $notification; }); $this->app->bind('Krucas\\Notification\\Subscriber', function ($app) { return new Subscriber($app['session'], $app['config']); }); $this->app['events']->subscribe('Krucas\\Notification\\Subscriber'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $containers = $this->session->get($this->key, []); if (count($containers) > 0) { foreach ($containers as $name => $messages) { /** @var \Krucas\Notification\Message $message */ foreach ($messages as $message) { $this->notification->container($name)->add($message->getType(), $message, false); } } } $this->session->forget($this->key); return $next($request); }
/** * Register the service provider. * * @return void */ public function register() { $this->mergeConfigFrom(__DIR__ . '/../../config/notification.php', 'notification'); $this->app->singleton('notification', function ($app) { $config = $app['config']; $notification = new Notification($config->get('notification.default_container'), $config->get('notification.default_types'), $config->get('notification.types'), $config->get('notification.default_format'), $config->get('notification.format'), $config->get('notification.default_formats'), $config->get('notification.formats')); $notification->setEventDispatcher($app['events']); return $notification; }); $this->app->alias('notification', 'Krucas\\Notification\\Notification'); $this->app->singleton('Krucas\\Notification\\Subscriber', function ($app) { return new Subscriber($app['session.store'], $app['config']['notification.session_key']); }); $this->app->singleton('Krucas\\Notification\\Middleware\\NotificationMiddleware', function ($app) { return new NotificationMiddleware($app['session.store'], $app['notification'], $app['config']->get('notification.session_key')); }); }
/** * Unset the event dispatcher for models. * * @return void * @static */ public static function unsetEventDispatcher() { \Krucas\Notification\Notification::unsetEventDispatcher(); }
/** * {@inheritdoc} * * @param string $message * @param array $parameters (optional) * @return void **/ public function warning($message, array $parameters = []) { $this->notification->warning($message); }