-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maxime Dupaul
committed
May 13, 2016
1 parent
69335f9
commit 4531faa
Showing
1 changed file
with
139 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,139 @@ | ||
<?php namespace Mdupaul\Flash; | ||
|
||
use Illuminate\Support\Facades\Session; | ||
|
||
class FlashNotifier | ||
{ | ||
|
||
/** | ||
* The session writer. | ||
* | ||
* @var SessionStore | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* Create a new flash notifier instance. | ||
* | ||
* @param SessionStore $session | ||
*/ | ||
function __construct(SessionStore $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Flash an information message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function info($message) | ||
{ | ||
$this->message($message, 'info'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a success message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function success($message) | ||
{ | ||
$this->message($message, 'success'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash an error message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function error($message) | ||
{ | ||
$this->message($message, 'danger'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a warning message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function warning($message) | ||
{ | ||
$this->message($message, 'warning'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash an overlay modal. | ||
* | ||
* @param string $message | ||
* @param string $title | ||
* @return $this | ||
*/ | ||
public function overlay($message, $title = 'Notice') | ||
{ | ||
$this->message($message); | ||
|
||
$this->session->flash('flash_notification.overlay', true); | ||
$this->session->flash('flash_notification.title', $title); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a general message. | ||
* | ||
* @param string $message | ||
* @param string $level | ||
* @return $this | ||
*/ | ||
public function message($message, $level = 'info') | ||
{ | ||
|
||
$messages = []; | ||
if (Session::has('flash_notification.messages')) { | ||
$messages = Session::get('flash_notification.messages'); | ||
} | ||
$messages[] = [$level => $message]; | ||
|
||
$this->session->flash('flash_notification.messages', $messages); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add an "important" flash to the session. | ||
* | ||
* @return $this | ||
*/ | ||
public function important() | ||
{ | ||
$this->session->flash('flash_notification.important', true); | ||
|
||
return $this; | ||
} | ||
|
||
} | ||
<?php namespace Mdupaul\Flash; | ||
|
||
use Illuminate\Support\Facades\Session; | ||
|
||
class FlashNotifier | ||
{ | ||
|
||
/** | ||
* The session writer. | ||
* | ||
* @var SessionStore | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* Create a new flash notifier instance. | ||
* | ||
* @param SessionStore $session | ||
*/ | ||
function __construct(SessionStore $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Flash an information message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function info($message) | ||
{ | ||
$this->message($message, 'info'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a success message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function success($message) | ||
{ | ||
$this->message($message, 'success'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash an error message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function error($message) | ||
{ | ||
$this->message($message, 'danger'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a warning message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function warning($message) | ||
{ | ||
$this->message($message, 'warning'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a sticky message. | ||
* | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function sticky($message) | ||
{ | ||
$this->message($message, 'sticky'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash an overlay modal. | ||
* | ||
* @param string $message | ||
* @param string $title | ||
* @return $this | ||
*/ | ||
public function overlay($message, $title = 'Notice') | ||
{ | ||
$this->message($message); | ||
|
||
$this->session->flash('flash_notification.overlay', true); | ||
$this->session->flash('flash_notification.title', $title); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Flash a general message. | ||
* | ||
* @param string $message | ||
* @param string $level | ||
* @return $this | ||
*/ | ||
public function message($message, $level = 'info') | ||
{ | ||
|
||
$messages = []; | ||
if (Session::has('flash_notification.messages')) { | ||
$messages = Session::get('flash_notification.messages'); | ||
} | ||
$messages[] = [$level => $message]; | ||
|
||
$this->session->flash('flash_notification.messages', $messages); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add an "important" flash to the session. | ||
* | ||
* @return $this | ||
*/ | ||
public function important() | ||
{ | ||
$this->session->flash('flash_notification.important', true); | ||
|
||
return $this; | ||
} | ||
|
||
} |