Skip to content

Commit

Permalink
Merge pull request #22 from dotkernel/issue-21
Browse files Browse the repository at this point in the history
added documentation
  • Loading branch information
alexmerlin committed May 3, 2024
2 parents 82d7513 + 1087411 commit 92446ba
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 207 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Continuous Integration"

on:
pull_request:
push:
branches:
tags:

jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x
47 changes: 0 additions & 47 deletions .github/workflows/cs-tests.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: docs-build

on:
release:
types: [published]
workflow_dispatch:

jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Build Docs
uses: dotkernel/documentation-theme/github-actions/docs@main
env:
DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 0 additions & 47 deletions .github/workflows/static-analysis.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/unit-tests.yml

This file was deleted.

121 changes: 56 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# dot-flashmessenger


![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-flashmessenger)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-flashmessenger/3.4.2)

Expand All @@ -9,35 +8,31 @@
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-flashmessenger)](https://github.com/dotkernel/dot-flashmessenger/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-flashmessenger)](https://github.com/dotkernel/dot-flashmessenger/blob/3.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-flashmessenger/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-flashmessenger/actions/workflows/static-analysis.yml)
[![Build Static](https://github.com/dotkernel/dot-flashmessenger/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-flashmessenger/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-flashmessenger/graph/badge.svg?token=B4WAT3RYKJ)](https://codecov.io/gh/dotkernel/dot-flashmessenger)

[![SymfonyInsight](https://insight.symfony.com/projects/94ace687-5124-446f-a324-0ecca1b47f88/big.svg)](https://insight.symfony.com/projects/94ace687-5124-446f-a324-0ecca1b47f88)


Flash messenger library for session messages between redirects. A flash message, or session message is a piece of text data that survives one requests(available only in the next request).
Flash messenger library for session messages between redirects. A flash message, or session message is a piece of text data that survives one requests(available only in the next request).
This library accepts session data as well, not just string messages, with the same behaviour.
The flash messenger is a convenient way to add data to the session and get it back on the next request without bothering with setting and clearing the data manually.

## Installation

Run the following command in your project folder
```bash
$ composer require dotkernel/dot-flashmessenger
```

composer require dotkernel/dot-flashmessenger

This will also install `laminas/laminas-session` as session handling is based on this library.
Next, merge the `ConfigProvider` to your application's configuration

## Configuration

```php
return [
'dot_flashmessenger' => [
'namespace' => 'flash messeges session namespace name'
],
];
```
return [
'dot_flashmessenger' => [
'namespace' => 'flash messages session namespace name'
],
];

Sets the session namespace to use for all flash messages and data

Expand All @@ -46,75 +41,71 @@ Sets the session namespace to use for all flash messages and data
If following the installation step, you'll already have a FlashMessenger service in the service manager.
Just inject this service in you classes, wherever you need flash messages.

##### Getting the service in a factory
```php
$container->get(FlashMessengerInterface::class);
```
### Getting the service in a factory

$container->get(FlashMessengerInterface::class);

### Using the flash messenger service

##### Using the flash messenger service
To add and retrieve text messages
```php
$this->flashMessenger->addMessage('error', 'This is a error flash message');

//on the next request you can get all messages from a namespace, or all messages from all namespaces if namespace is omitted
$this->flashMessenger->getMessages('error');
```
$this->flashMessenger->addMessage('error', 'This is a error flash message');

//on the next request you can get all messages from a namespace, or all messages from all namespaces if namespace is omitted
$this->flashMessenger->getMessages('error');

Adding general data, not just messages, has a different method for that, accepting data as key/value pairs
```php
$this->flashMessenger->addData('myData', $someData);

//next request
$this->flashMessenger->getData('myData');
```
$this->flashMessenger->addData('myData', $someData);

// next request
$this->flashMessenger->getData('myData');

There are also some predefined namespaces, along with shortcuts to add a message in the predefined namespaces
```php
FlashMessengerInterface::ERROR_NAMESPACE
FlashMessengerInterface::WARNING_NAMESPACE
FlashMessengerInterface::INFO_NAMESPACE
FlashMessengerInterface::SUCCESS_NAMESPACE
```

```php
/**
* @param string $error
* @return void
*/
public function addError($error);
/**
* @param string $info
* @return void
*/
public function addInfo($info);
/**
* @param string $warning
* @return void
*/
public function addWarning($warning);
/**
* @param string $success
* @return void
*/
public function addSuccess($success);
```

FlashMessengerInterface::ERROR_NAMESPACE
FlashMessengerInterface::WARNING_NAMESPACE
FlashMessengerInterface::INFO_NAMESPACE
FlashMessengerInterface::SUCCESS_NAMESPACE

using the methods:

/**
* @param string $error
* @return void
*/
public function addError($error);

/**
* @param string $info
* @return void
*/
public function addInfo($info);

/**
* @param string $warning
* @return void
*/
public function addWarning($warning);

/**
* @param string $success
* @return void
*/
public function addSuccess($success);

## FlashMessengerRenderer

A class that is able to parse the content of the flash messenger service in an HTML format.
A class that is able to parse the content of the flash messenger service in an HTML format.
It uses the TemplateInterface to parse a partial, sending to the partial template the messages, the service and the renderer itself.
There are also a twig extension provided in [dot-twigrenderer](https://github.com/dotkernel/dot-twigrenderer), for easy parsing of messages blocks.

## Registered services

```php
Dot\FlashMessenger\FlashMessengerInterface::class
```
Dot\FlashMessenger\FlashMessengerInterface::class

The flash messenger service

```php
Dot\FlashMessenger\View\RendererInterface::class
```
Dot\FlashMessenger\View\RendererInterface::class

The registered renderer class
39 changes: 39 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Security Policy

## Supported Versions


| Version | Supported | PHP Version |
|---------|--------------------|------------------------------------------------------------------------------------------------------------------------|
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-flashmessenger/3.4.2) |
| <= 2.x | :x: | |


## Reporting Potential Security Issues

If you have encountered a potential security vulnerability in this project,
please report it to us at <security@dotkernel.com>. We will work with you to
verify the vulnerability and patch it.

When reporting issues, please provide the following information:

- Component(s) affected
- A description indicating how to reproduce the issue
- A summary of the security vulnerability and impact

We request that you contact us via the email address above and give the
project contributors a chance to resolve the vulnerability and issue a new
release prior to any public exposure; this helps protect the project's
users, and provides them with a chance to upgrade and/or update in order to
protect their applications.


## Policy

If we verify a reported security vulnerability, our policy is:

- We will patch the current release branch, as well as the immediate prior minor
release branch.

- After patching the release branches, we will immediately issue new security
fix releases for each patched release branch.
1 change: 1 addition & 0 deletions docs/book/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../README.md

0 comments on commit 92446ba

Please sign in to comment.