Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbuckingham89 committed Oct 3, 2021
1 parent 4a9f785 commit 7ab5e5a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 80 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# gbuckingham89/laraflash v3.3.0
# gbuckingham89/laraflash v4.0.0

A simple package for handling flash messages / notifications in Laravel. Written to suit my needs - but hopefully someone else will find it useful too.

The current version requires Laravel 5.6 (PHP 7.1) or greater. [Version 2.0.0](https://github.com/gbuckingham89/laraflash/tree/2.0.0) supports earlier 5.* versions. The levels of priority for messages and included view file are optimised for use with [Bootstrap 3](http://www.getbootstrap.com).
The current version requires Laravel 7.0 (PHP 7.4) or greater. If you have a project that requires a lower version of PHP or Laravel, check the requirements of the older releases.

## Installation

Expand All @@ -18,7 +18,7 @@ For the service provider, add the following to the `providers` array in your `ap

For the facade, add the following to the `aliases` array in your `app.php` config file:

'Laraflash' => Gbuckingham89\Laraflash\Facade::class
'Laraflash' => Gbuckingham89\Laraflash\Facade\Laraflash::class

Finally, you'll need to publish the view file (unless you want to roll your own). Do this by running this command in your terminal:

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"source": "https://github.com/gbuckingham89/laraflash"
},
"require": {
"php": "^7.1|^8.0",
"illuminate/session": "^5.6|^5.7|^5.8|^6.0|^7.0|^8.0",
"illuminate/support": "^5.6|^5.7|^5.8|^6.0|^7.0|^8.0"
"php": "^7.4|^8.0",
"illuminate/session": "^7.0|^8.0",
"illuminate/support": "^7.0|^8.0"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 0 additions & 22 deletions src/Facade.php

This file was deleted.

18 changes: 18 additions & 0 deletions src/Facade/Laraflash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Gbuckingham89\Laraflash\Facade;

use Illuminate\Support\Facades\Facade;

class Laraflash extends Facade
{

/**
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'laraflash';
}

}
34 changes: 15 additions & 19 deletions src/Laraflash.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

namespace Gbuckingham89\Laraflash;

/**
* Class Laraflash
* @package Gbuckingham89\Laraflash
*/
class Laraflash
{

/**
* @var \Gbuckingham89\Laraflash\SessionStorage
*/
private $session;
private SessionStorage $session;

/**
* Laraflash constructor.
Expand All @@ -24,10 +20,10 @@ function __construct(SessionStorage $session)
$this->session = $session;
}

/**
* @return \Gbuckingham89\Laraflash\Laraflash
*/
public function reflash()
/**
* @return $this
*/
public function reflash(): self
{
$this->session->reflash();

Expand All @@ -38,9 +34,9 @@ public function reflash()
* @param string $message
* @param string $level
*
* @return \Gbuckingham89\Laraflash\Laraflash
* @return $this
*/
public function flash($message, $level)
public function flash(string $message, string $level): self
{
$this->session->flash('laraflash.message', $message);
$this->session->flash('laraflash.level', $level);
Expand All @@ -51,39 +47,39 @@ public function flash($message, $level)
/**
* @param string $message
*
* @return \Gbuckingham89\Laraflash\Laraflash
* @return $this
*/
public function success($message)
public function success(string $message) :self
{
return $this->flash($message, 'success');
}

/**
* @param string $message
*
* @return \Gbuckingham89\Laraflash\Laraflash
* @return $this
*/
public function info($message)
public function info(string $message): self
{
return $this->flash($message, 'info');
}

/**
* @param string $message
*
* @return \Gbuckingham89\Laraflash\Laraflash
* @return $this
*/
public function warning($message)
public function warning(string $message): self
{
return $this->flash($message, 'warning');
}

/**
* @param string $message
*
* @return \Gbuckingham89\Laraflash\Laraflash
* @return $this
*/
public function danger($message)
public function danger(string $message): self
{
return $this->flash($message, 'danger');
}
Expand Down
22 changes: 12 additions & 10 deletions src/LaravelSessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

use Illuminate\Session\Store;

/**
* Class LaravelSessionStorage
* @package Gbuckingham89\Laraflash
*/
class LaravelSessionStorage implements SessionStorage
{

/**
* @var \Illuminate\Session\Store
*/
private $session;
private Store $session;

/**
* LaravelSessionStorage constructor.
Expand All @@ -30,9 +26,11 @@ function __construct(Store $session)
* Flash a value to the session
*
* @param string $key
* @param string $value
* @param mixed $value
*
* @return void
*/
public function flash($key, $value)
public function flash(string $key, $value=null): void
{
$this->session->flash($key, $value);
}
Expand All @@ -41,17 +39,21 @@ public function flash($key, $value)
* Get a value from the session
*
* @param string $key
* @param null $default
* @param mixed $default
*
* @return void
*/
public function get($key, $default=null)
public function get(string $key, $default=null): void
{
$this->session->get($key, $default);
}

/**
* Reflash data in the session
*
* @return void
*/
public function reflash()
public function reflash(): void
{
$this->session->reflash();
}
Expand Down
8 changes: 2 additions & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

use Illuminate\Support\ServiceProvider as BaseServiceProvider;

/**
* Class ServiceProvider
* @package Gbuckingham89\Laraflash
*/
class ServiceProvider extends BaseServiceProvider
{

Expand All @@ -16,7 +12,7 @@ class ServiceProvider extends BaseServiceProvider
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->bind(
SessionStorage::class,
Expand All @@ -33,7 +29,7 @@ public function register()
*
* @return void
*/
public function boot()
public function boot(): void
{
$this->loadViewsFrom(__DIR__ . '/../views', 'laraflash');
$this->publishes([
Expand Down
32 changes: 15 additions & 17 deletions src/SessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@

namespace Gbuckingham89\Laraflash;

/**
* Interface SessionStorage
* @package Gbuckingham89\Laraflash
*/
interface SessionStorage
{

/**
* @param string $key
* @param string $value
* @param mixed $value
*
* @return void
*/
public function flash($key, $value);
public function flash(string $key, $value=null): void;

/**
* @param string $key
* @param null $default
*
* @return mixed
*/
public function get($key, $default=null);
/**
* @param string $key
* @param mixed $default
*
* @return void
*/
public function get(string $key, $default=null): void;

/**
* @return void
*/
public function reflash();
/**
* @return void
*/
public function reflash(): void;

}

0 comments on commit 7ab5e5a

Please sign in to comment.