Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Updated according to scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Jan 1, 2016
1 parent 8045d71 commit 6647099
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
78 changes: 72 additions & 6 deletions docs/en/index.md
@@ -1,3 +1,34 @@
# Quickstart

This extension replace default flash messages handling. If you want to use one interface for displaying messages, use this extension. For eg. if you are showing messages in modal windows, but sometimes this windows are deactivated, you can reach it with this extension. It store messages in one place and check if were displayed or not.

## Installation

The best way to install ipub/flash-messages is using [Composer](http://getcomposer.org/):

```sh
$ composer require ipub/flash-messages
```

After that you have to register extension in config.neon.

```neon
extensions:
flashMessages: IPub\FlashMessages\DI\FlashMessagesExtension
```

Package contains trait, which you will have to use in presenters or components to implement Flash messages component factory. This works only for PHP 5.4+, for older version you can simply copy trait content and paste it into class where you want to use it.

```php
<?php

class BasePresenter extends Nette\Application\UI\Presenter
{
use IPub\FlashMessages\TFlashMessages;

// ...
}
```

## Usage

Expand All @@ -10,7 +41,7 @@ namespace Your\Coool\Namespace\Presenter;

use IPub\FlashMessages;

class SomePresenter
class SomePresenter extends Nette\Application\UI\Presenter
{
/**
* Insert extension trait (only for PHP 5.4+)
Expand Down Expand Up @@ -59,8 +90,13 @@ And if you want to display some message you can use Nette default method to stor
```php
<?php

class BasePresenter extends Nette\Application\UI\Presenter
class SomePresenter extends Nette\Application\UI\Presenter
{
/**
* Insert extension trait (only for PHP 5.4+)
*/
use FlashMessages\TFlashMessages;

public function actionSome()
{
$this->flashMessage('Message text', 'warning');
Expand All @@ -77,15 +113,20 @@ This extension has its own methods to create flash messages, which support more
```php
<?php

class BasePresenter extends Nette\Application\UI\Presenter
class SomePresenter extends Nette\Application\UI\Presenter
{
/**
* Insert extension trait (only for PHP 5.4+)
*/
use FlashMessages\TFlashMessages;

public function actionSome()
{
$this->flashNotifier->message('Message text', 'warning', 'My message title');

// or

$this->warning('Message text', 'My message title');
$this->flashNotifier->warning('Message text', 'My message title');
}
}
```
Expand All @@ -99,6 +140,31 @@ Available methods to store message:

Message title is optional parameter.

### Important modal messages
### Messages in modal windows with overlay

If you want to create important message and display it in modal window, you can use special option for it: *overlay*
If you want to create important message and display it in modal window, you can use special option or special method:

```php
<?php

class SomePresenter extends Nette\Application\UI\Presenter
{
/**
* Insert extension trait (only for PHP 5.4+)
*/
use FlashMessages\TFlashMessages;

public function actionSome()
{
$this->flashNotifier->overlay('Message text', 'warning', 'My message title');

// or

$this->flashNotifier->overlay('Message text', 'My message title'); // Without level info message will be created

// or

$this->flashNotifier->message('Message text', 'warning', 'My message title', TRUE);
}
}
```
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -10,7 +10,7 @@

Flash messages handler for [Nette Framework](http://nette.org/)

This component replace default flash messages handling. If you want to use one interface for displaying messages, use this extension. For eg. if you are showing messages in modal windows, but sometimes this windows are deactivated, you can reach it with this extension. It store messages in one place and check if were displayed or not.
This extension replace default flash messages handling. If you want to use one interface for displaying messages, use this extension. For eg. if you are showing messages in modal windows, but sometimes this windows are deactivated, you can reach it with this extension. It store messages in one place and check if were displayed or not.

## Installation

Expand Down
6 changes: 5 additions & 1 deletion src/IPub/FlashMessages/Adapters/KdybyPhraseAdapter.php
Expand Up @@ -48,7 +48,11 @@ public function __construct(Translation\Phrase $phrase)
*/
public function translate(Localization\ITranslator $translator)
{
return $this->phrase->translate($translator);
if ($translator instanceof Translation\Translator) {
return $this->phrase->translate($translator);
}

return NULL;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/IPub/FlashMessages/Components/Control.php
Expand Up @@ -80,19 +80,15 @@ public function attached($presenter)
/**
* @param NULL|string $templateFile
* @param FlashMessages\SessionStorage $sessionStorage
* @param Nette\ComponentModel\IContainer $parent
* @param null $name
*
* @throws Exceptions\FileNotFoundException
*/
public function __construct(
$templateFile = NULL,
FlashMessages\SessionStorage $sessionStorage,
Nette\ComponentModel\IContainer $parent = NULL, $name = NULL
FlashMessages\SessionStorage $sessionStorage
)
{
// TODO: remove, only for tests
parent::__construct(NULL, NULL);
parent::__construct();

if ($templateFile !== NULL) {
$this->setTemplateFile($templateFile);
Expand Down

0 comments on commit 6647099

Please sign in to comment.