Skip to content

Commit

Permalink
Merge pull request #2 from ARCANEDEV/develop
Browse files Browse the repository at this point in the history
Updating the package for Laravel 5.x
  • Loading branch information
arcanedev-maroc committed Dec 25, 2015
2 parents b20f2e2 + f1b2b00 commit c3cab82
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 206 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 12
php_code_sniffer:
enabled: true
config:
Expand Down
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
language: php

sudo: false

php:
- 5.5.9
- 5.5
- 5.6
- 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
- mkdir -p build/logs
- 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
137 changes: 8 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
<div class="alert alert-{{ Session::get('notifier.level') }}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

{{ Session::get('notifier.message') }}
</div>
@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).
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "ARCANEDEV",
"email": "[email protected]",
"homepage": "https://github.com/ARCANEDEV",
"homepage": "https://github.com/arcanedev-maroc",
"role": "Developer"
}
],
Expand All @@ -18,7 +18,6 @@
"arcanedev/support": "~3.0"
},
"require-dev": {
"orchestra/testbench": "~3.1",
"phpunit/phpcov": "~2.0",
"phpunit/phpunit": "~4.0|~5.0"
},
Expand All @@ -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"
}
}
}
2 changes: 1 addition & 1 deletion config/notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
| ------------------------------------------------------------------------------------------------
*/
'session' => [
'prefix' => 'notifier.'
'prefix' => 'notifier'
],
];
4 changes: 2 additions & 2 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace Arcanedev\Notify\Contracts;

/**
* Interface NotifyInterface
* Interface Notify
*
* @package Arcanedev\Notify\Contracts
* @author ARCANEDEV <[email protected]>
*/
interface NotifyInterface
interface Notify
{
/* ------------------------------------------------------------------------------------------------
| Getters & Setters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace Arcanedev\Notify\Contracts;

/**
* Interface SessionStoreInterface
* Interface SessionStore
*
* @package Arcanedev\Notify\Contracts
* @author ARCANEDEV <[email protected]>
*/
interface SessionStoreInterface
interface SessionStore
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
Expand Down
42 changes: 22 additions & 20 deletions src/Notify.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php namespace Arcanedev\Notify;

use Arcanedev\Notify\Contracts\NotifyInterface;
use Arcanedev\Notify\Contracts\SessionStoreInterface;
use Arcanedev\Notify\Contracts\Notify as NotifyContract;
use Arcanedev\Notify\Contracts\SessionStore;

/**
* Class Notify
*
* @package Arcanedev\Notify
* @author ARCANEDEV <[email protected]>
*/
class Notify implements NotifyInterface
class Notify implements NotifyContract
{
/* ------------------------------------------------------------------------------------------------
| Properties
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -138,6 +132,12 @@ public function flash($message, $type = '', array $options = [])
| Other Functions
| ------------------------------------------------------------------------------------------------
*/

private function getPrefixedName($name)
{
return "{$this->sessionPrefix}.$name";
}

/**
* Get session value.
*
Expand All @@ -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)
);
}
}
Loading

0 comments on commit c3cab82

Please sign in to comment.