diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..042d009
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# This file is for unifying the coding style for different editors and IDEs
+# editorconfig.org
+
+root = true
+
+[*]
+end_of_line = lf
+charset = utf-8
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+indent_size = 2
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index 282131b..da236c8 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
- runs: 3
+ runs: 12
php_code_sniffer:
enabled: true
config:
diff --git a/.travis.yml b/.travis.yml
index 4915c53..cc4af1e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
language: php
+sudo: false
+
php:
- 5.5.9
- 5.5
@@ -7,11 +9,14 @@ php:
- 7.0
- hhvm
-sudo: false
+env:
+ - TESTBENCH_VERSION=3.0.*
+ - TESTBENCH_VERSION=3.1.*
+ - TESTBENCH_VERSION=3.2.*
before_script:
- travis_retry composer self-update
- - travis_retry composer install --prefer-source --no-interaction
+ - travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench:${TESTBENCH_VERSION}"
script:
- composer validate
@@ -19,5 +24,5 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
after_script:
- - if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- - if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
+ - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
+ - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
diff --git a/README.md b/README.md
index 44bc872..3b60ce1 100644
--- a/README.md
+++ b/README.md
@@ -27,142 +27,21 @@
*By [ARCANEDEV©](http://www.arcanedev.net/)*
-Flexible flash notifications helper for Laravel 5.
+Flexible flash notifications helper for Laravel 5.
Feel free to check out the [releases](https://github.com/ARCANEDEV/Notify/releases), [license](LICENSE.md), and [contribution guidelines](CONTRIBUTING.md).
-### Requirements
-
- - PHP >= 5.5.9
-
-## INSTALLATION
-
-### Composer
-
-You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json` :
-
-```json
-{
- "require": {
- "arcanedev/notify": "~2.0"
- }
-}
-```
-
-Then install it via `composer install` or `composer update`.
-
-### Laravel
-
-include the service provider within `config/app.php`.
-
-```php
-'providers' => [
- Arcanedev\Notify\NotifyServiceProvider::class
-];
-```
-
-And add a facade alias to this same file at the bottom:
-
-```php
-'aliases' => [
- 'Notify' => Arcanedev\Notify\Facades\Notify::class
-];
-```
-
-## USAGE
-
-Within your controllers, before you perform a redirect...
-
-```php
-public function store()
-{
- Notify::message('Welcome !');
-
- return Redirect::home();
-}
-```
-
-You may also do:
-
-```php
-// Info alert notification
-Notify::info('Message')
-
-// Success alert notification
-Notify::success('Message')
-
-// Danger alert notification
-Notify::error('Message')
-
-// Warning alert notification
-Notify::warning('Message')
-
-// Modal notification
-Notify::overlay('Modal Message', 'Modal Title')
-```
-
-Again, if using Laravel, this will set a few keys in the session :
-
- - `notifier.message`: The message you're flashing
- - `notifier.level`: A string that represents the type of notification (good for applying HTML class names)
-
-Alternatively, again, if you're using Laravel, you may reference the `notify()` helper function, instead of the facade.
-
-Here's an example:
-
-```php
-/**
- * Destroy the user's session (logout).
- *
- * @return Response
- */
-public function destroy()
-{
- Auth::logout();
-
- notify()->success('You have been logged out.');
-
- return home();
-}
-```
-
-Or, for a general information flash, just do: `notify('Some message');`.
-
-With this message flashed to the session, you may now display it in your view(s). Maybe something like:
-
-```html
-@if (Session::has('notifier.message'))
-
-
-
- {{ Session::get('notifier.message') }}
-
-@endif
-```
-
-> Note that this package is optimized for use with Twitter Bootstrap.
-
-Because flash messages and overlays are so common, if you want, you may use (or modify) the views that are included with this package.
-
-Simply append to your layout view:
-
-```html
-@include('notify::message')
-```
-
### TODOS:
- - [ ] Complete Documentation
- - [ ] Examples
- - [ ] Zurb Foundation 5 support
- - [ ] Laravel 5.0 support
- - [ ] Refactoring
+ - [ ] Complete Documentation.
+ - [ ] Examples.
### DONE:
- - [x] Laravel 4.2 support
- - [x] Laravel 5.1 support
- - [x] Bootstrap 3 supported
-
+ - [x] Laravel 4.2 supported.
+ - [x] Laravel 5.0 supported.
+ - [x] Laravel 5.1 supported.
+ - [x] Laravel 5.2 supported.
+
## Contribution
Any ideas are welcome. Feel free to submit any issues or pull requests, please check the [contribution guidelines](CONTRIBUTING.md).
diff --git a/composer.json b/composer.json
index 2b97b6e..7f9603f 100644
--- a/composer.json
+++ b/composer.json
@@ -7,7 +7,7 @@
{
"name": "ARCANEDEV",
"email": "arcanedev.maroc@gmail.com",
- "homepage": "https://github.com/ARCANEDEV",
+ "homepage": "https://github.com/arcanedev-maroc",
"role": "Developer"
}
],
@@ -18,7 +18,6 @@
"arcanedev/support": "~3.0"
},
"require-dev": {
- "orchestra/testbench": "~3.1",
"phpunit/phpcov": "~2.0",
"phpunit/phpunit": "~4.0|~5.0"
},
@@ -33,9 +32,12 @@
"Arcanedev\\Notify\\Tests\\": "tests/"
}
},
+ "scripts": {
+ "testbench": "composer require --dev \"orchestra/testbench=~3.0\""
+ },
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-master": "3.2-dev"
}
}
}
diff --git a/config/notify.php b/config/notify.php
index 77b424d..94b83f9 100644
--- a/config/notify.php
+++ b/config/notify.php
@@ -6,6 +6,6 @@
| ------------------------------------------------------------------------------------------------
*/
'session' => [
- 'prefix' => 'notifier.'
+ 'prefix' => 'notifier'
],
];
diff --git a/helpers.php b/helpers.php
index 9f4629b..dd7ad66 100644
--- a/helpers.php
+++ b/helpers.php
@@ -6,11 +6,11 @@
*
* @param string|null $message
*
- * @return \Arcanedev\Notify\Contracts\NotifyInterface
+ * @return \Arcanedev\Notify\Contracts\Notify
*/
function notify($message = null)
{
- /** @var Arcanedev\Notify\Contracts\NotifyInterface $notifier */
+ /** @var Arcanedev\Notify\Contracts\Notify $notifier */
$notifier = app('arcanedev.notify');
if ( ! is_null($message)) {
diff --git a/src/Contracts/NotifyInterface.php b/src/Contracts/Notify.php
similarity index 96%
rename from src/Contracts/NotifyInterface.php
rename to src/Contracts/Notify.php
index e675961..bf79cb5 100644
--- a/src/Contracts/NotifyInterface.php
+++ b/src/Contracts/Notify.php
@@ -1,12 +1,12 @@
*/
-interface NotifyInterface
+interface Notify
{
/* ------------------------------------------------------------------------------------------------
| Getters & Setters
diff --git a/src/Contracts/SessionStoreInterface.php b/src/Contracts/SessionStore.php
similarity index 92%
rename from src/Contracts/SessionStoreInterface.php
rename to src/Contracts/SessionStore.php
index 3bea296..0a8bf4e 100644
--- a/src/Contracts/SessionStoreInterface.php
+++ b/src/Contracts/SessionStore.php
@@ -1,12 +1,12 @@
*/
-interface SessionStoreInterface
+interface SessionStore
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
diff --git a/src/Notify.php b/src/Notify.php
index b0b54dc..7460365 100644
--- a/src/Notify.php
+++ b/src/Notify.php
@@ -1,7 +1,7 @@
*/
-class Notify implements NotifyInterface
+class Notify implements NotifyContract
{
/* ------------------------------------------------------------------------------------------------
| Properties
@@ -20,16 +20,12 @@ class Notify implements NotifyInterface
*
* @var string
*/
- protected $sessionPrefix = '';
+ protected $sessionPrefix;
- /* ------------------------------------------------------------------------------------------------
- | Properties
- | ------------------------------------------------------------------------------------------------
- */
/**
* The session writer.
*
- * @var SessionStoreInterface
+ * @var \Arcanedev\Notify\Contracts\SessionStore
*/
private $session;
@@ -40,10 +36,10 @@ class Notify implements NotifyInterface
/**
* Create a new flash notifier instance.
*
- * @param SessionStoreInterface $session
- * @param string $prefix
+ * @param \Arcanedev\Notify\Contracts\SessionStore $session
+ * @param string $prefix
*/
- public function __construct(SessionStoreInterface $session, $prefix)
+ public function __construct(SessionStore $session, $prefix)
{
$this->session = $session;
$this->sessionPrefix = $prefix;
@@ -123,13 +119,11 @@ public function ready()
*/
public function flash($message, $type = '', array $options = [])
{
- $data = [
- $this->sessionPrefix . 'message' => $message,
- $this->sessionPrefix . 'type' => $type,
- $this->sessionPrefix . 'options' => json_encode($options),
- ];
-
- $this->session->flash($data);
+ $this->session->flash([
+ $this->getPrefixedName('message') => $message,
+ $this->getPrefixedName('type') => $type,
+ $this->getPrefixedName('options') => json_encode($options),
+ ]);
return $this;
}
@@ -138,6 +132,12 @@ public function flash($message, $type = '', array $options = [])
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
+
+ private function getPrefixedName($name)
+ {
+ return "{$this->sessionPrefix}.$name";
+ }
+
/**
* Get session value.
*
@@ -147,6 +147,8 @@ public function flash($message, $type = '', array $options = [])
*/
private function getSession($name)
{
- return $this->session->get($this->sessionPrefix . $name);
+ return $this->session->get(
+ $this->getPrefixedName($name)
+ );
}
}
diff --git a/src/NotifyServiceProvider.php b/src/NotifyServiceProvider.php
index cca069c..cf5a1fa 100644
--- a/src/NotifyServiceProvider.php
+++ b/src/NotifyServiceProvider.php
@@ -1,6 +1,5 @@
registerConfig();
+
+ $this->bindSession();
+ $this->registerNotifyService();
+ }
+
/**
* Boot the package.
*/
@@ -63,39 +73,43 @@ public function boot()
}
/**
- * Register the service provider.
+ * Get the services provided by the provider.
+ *
+ * @return array
*/
- public function register()
+ public function provides()
{
- $this->registerConfig();
+ return ['arcanedev.notify'];
+ }
+ /* ------------------------------------------------------------------------------------------------
+ | Services
+ | ------------------------------------------------------------------------------------------------
+ */
+ /**
+ * Bind the Session Class.
+ */
+ private function bindSession()
+ {
$this->bind(
- Contracts\SessionStoreInterface::class,
- Session::class
+ \Arcanedev\Notify\Contracts\SessionStore::class,
+ \Arcanedev\Notify\Storage\Session::class
);
+ }
+ /**
+ * Register the Notify service.
+ */
+ private function registerNotifyService()
+ {
$this->singleton('arcanedev.notify', function ($app) {
- /**
- * @var \Illuminate\Foundation\Application $app
- * @var \Illuminate\Config\Repository $config
- */
- $session = $app[Contracts\SessionStoreInterface::class];
+ /** @var \Illuminate\Config\Repository $config */
$config = $app['config'];
return new Notify(
- $session,
+ $app[\Arcanedev\Notify\Contracts\SessionStore::class],
$config->get('notify.session.prefix', 'notifier.')
);
});
}
-
- /**
- * Get the services provided by the provider.
- *
- * @return array
- */
- public function provides()
- {
- return ['arcanedev.notify'];
- }
}
diff --git a/src/Storage/Session.php b/src/Storage/Session.php
index 0074539..5245fe1 100644
--- a/src/Storage/Session.php
+++ b/src/Storage/Session.php
@@ -1,6 +1,6 @@
*/
-class Session implements SessionStoreInterface
+class Session implements SessionStore
{
/* ------------------------------------------------------------------------------------------------
| Properties
@@ -18,7 +18,7 @@ class Session implements SessionStoreInterface
/**
* The Illuminate Session instance.
*
- * @var IlluminateSession
+ * @var \Illuminate\Session\Store
*/
private $session;
@@ -29,7 +29,7 @@ class Session implements SessionStoreInterface
/**
* Make session store instance.
*
- * @param IlluminateSession $session
+ * @param \Illuminate\Session\Store $session
*/
public function __construct(IlluminateSession $session)
{
diff --git a/tests/NotifyServiceProviderTest.php b/tests/NotifyServiceProviderTest.php
index e12e3be..6e3f636 100644
--- a/tests/NotifyServiceProviderTest.php
+++ b/tests/NotifyServiceProviderTest.php
@@ -32,23 +32,20 @@ public function setUp()
public function tearDown()
{
- parent::tearDown();
-
unset($this->provider);
+
+ parent::tearDown();
}
/* ------------------------------------------------------------------------------------------------
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
- /**
- * @test
- */
- public function testCanGetWhatHeProvides()
+ /** @test */
+ public function it_can_provides()
{
- // This is for 100% code converge
- $this->assertEquals([
- 'arcanedev.notify'
- ], $this->provider->provides());
+ $expected = ['arcanedev.notify'];
+
+ $this->assertEquals($expected, $this->provider->provides());
}
}
diff --git a/tests/NotifyTest.php b/tests/NotifyTest.php
index ad0b386..01c9dae 100644
--- a/tests/NotifyTest.php
+++ b/tests/NotifyTest.php
@@ -1,6 +1,6 @@
notify = new Notify(app(SessionStoreInterface::class), $this->sessionPrefix);
+ $this->notify = new Notify(app(SessionStore::class), $this->sessionPrefix);
$this->assertFalse($this->notify->ready());
}
public function tearDown()
{
- parent::tearDown();
-
unset($this->notify);
+
+ parent::tearDown();
}
/* ------------------------------------------------------------------------------------------------
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 1595f08..6607455 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -1,6 +1,6 @@