Skip to content

Commit 841e668

Browse files
committed
docs: update symfony README.md file
1 parent 01905e6 commit 841e668

File tree

1 file changed

+330
-16
lines changed

1 file changed

+330
-16
lines changed

README.md

Lines changed: 330 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,340 @@
66

77
<p align="center">
88
<picture>
9-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/php-flasher/art/main/php-flasher-github-dark.png">
10-
<img src="https://raw.githubusercontent.com/php-flasher/art/main/php-flasher-github.png" alt="PHPFlasher Logo">
9+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/php-flasher/art/main/php-flasher-logo-dark.png">
10+
<img src="https://raw.githubusercontent.com/php-flasher/art/main/php-flasher-logo.png" alt="PHPFlasher Logo">
1111
</picture>
1212
</p>
1313

14-
## About PHPFlasher
14+
<p align="center">
15+
<a href="https://www.linkedin.com/in/younes--ennaji"><img src="https://img.shields.io/badge/[email protected]" alt="Author Badge"></a>
16+
<a href="https://github.com/php-flasher/php-flasher"><img src="https://img.shields.io/badge/source-php--flasher/php--flasher-blue.svg" alt="Source Code Badge"></a>
17+
<a href="https://github.com/php-flasher/php-flasher/releases"><img src="https://img.shields.io/github/tag/php-flasher/flasher.svg" alt="GitHub Release Badge"></a>
18+
<a href="https://github.com/php-flasher/flasher/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="License Badge"></a>
19+
<a href="https://packagist.org/packages/php-flasher/flasher"><img src="https://img.shields.io/packagist/dt/php-flasher/flasher.svg" alt="Packagist Downloads Badge"></a>
20+
<a href="https://github.com/php-flasher/php-flasher"><img src="https://img.shields.io/github/stars/php-flasher/php-flasher.svg" alt="GitHub Stars Badge"></a>
21+
<a href="https://packagist.org/packages/php-flasher/flasher"><img src="https://img.shields.io/packagist/php-v/php-flasher/flasher.svg" alt="Supported PHP Version Badge"></a>
22+
</p>
23+
24+
## Table of Contents
25+
26+
- [About PHPFlasher Symfony Adapter](#about-phpflasher-symfony-adapter)
27+
- [Features](#features)
28+
- [Supported Versions](#supported-versions)
29+
- [Installation](#installation)
30+
- [Core Package](#core-package)
31+
- [Adapters](#adapters)
32+
- [Configuration](#configuration)
33+
- [Configuration File](#configuration-file)
34+
- [Configuration Options](#configuration-options)
35+
- [Quick Start](#quick-start)
36+
- [Usage Examples](#usage-examples)
37+
- [Adapters Overview](#adapters-overview)
38+
- [Official Documentation](#official-documentation)
39+
- [Contributors and Sponsors](#contributors-and-sponsors)
40+
- [Contact](#contact)
41+
- [License](#license)
42+
43+
## About PHPFlasher Symfony Adapter
44+
45+
**PHPFlasher Symfony Adapter** is an open-source package that seamlessly integrates PHPFlasher’s robust flash messaging capabilities into your **Symfony** applications. It streamlines the process of adding flash messages, offering an intuitive API to enhance user experience with minimal configuration.
46+
47+
With PHPFlasher Symfony Adapter, you can effortlessly display success, error, warning, and informational messages to your users, ensuring clear communication of application states and actions.
48+
49+
## Features
50+
51+
- **Seamless Symfony Integration**: Designed specifically for Symfony, ensuring compatibility and ease of use.
52+
- **Multiple Notification Libraries**: Supports various frontend libraries like Toastr, Noty, SweetAlert, and Notyf.
53+
- **Flexible Configuration**: Customize the appearance and behavior of flash messages to fit your application's needs.
54+
- **Intuitive API**: Simple methods to create and manage flash messages without boilerplate code.
55+
- **Extensible**: Easily add or create new adapters for different frontend libraries.
56+
57+
## Supported Versions
58+
59+
| PHPFlasher Symfony Adapter Version | PHP Version | Symfony Version |
60+
|------------------------------------|-------------|-----------------|
61+
| **v2.x** | ≥ 8.2 | ≥ 7.0 |
62+
| **v1.x** | ≥ 5.3 | ≥ 2.0 |
63+
64+
> **Note:** Ensure your project meets the PHP and Symfony version requirements for the PHPFlasher Symfony Adapter version you intend to use. For older PHP or Symfony versions, refer to [PHPFlasher v1.x](https://github.com/php-flasher/flasher-symfony/tree/1.x).
65+
66+
## Installation
67+
68+
### Core Package
69+
70+
Install the PHPFlasher Symfony Adapter via Composer:
71+
72+
```bash
73+
composer require php-flasher/flasher-symfony
74+
```
75+
76+
After installation, set up the necessary assets:
77+
78+
```shell
79+
php bin/console flasher:install
80+
```
81+
82+
> **Note:** PHPFlasher automatically injects the necessary JavaScript and CSS assets into your Blade templates. No additional steps are required for asset injection.
83+
84+
### Adapters
85+
86+
PHPFlasher provides various adapters for different notification libraries. Below is an overview of available adapters for Symfony:
87+
88+
- [flasher-toastr-symfony](https://github.com/php-flasher/flasher-toastr-symfony) - Symfony Adapter
89+
- [flasher-noty-symfony](https://github.com/php-flasher/flasher-noty-symfony) - Symfony Adapter
90+
- [flasher-notyf-symfony](https://github.com/php-flasher/flasher-notyf-symfony) - Symfony Adapter
91+
- [flasher-sweetalert-symfony](https://github.com/php-flasher/flasher-sweetalert-symfony) - Symfony Adapter
92+
93+
For detailed installation and usage instructions for each adapter, refer to their respective `README.md`.
94+
95+
## Configuration
96+
97+
After installing the PHPFlasher Symfony Adapter, you can configure it by publishing the configuration file or by modifying it directly.
98+
99+
### Configuration File
100+
101+
If you need to customize the default settings, publish the configuration file using the following command:
102+
103+
```bash
104+
php bin/console flasher:install --config
105+
```
106+
107+
This will create a file at `config/packages/flasher.yaml` with the following content:
108+
109+
```yaml
110+
flasher:
111+
# Default notification library (e.g., 'flasher', 'toastr', 'noty', 'notyf', 'sweetalert')
112+
default: flasher
113+
114+
# Path to the main PHPFlasher JavaScript file
115+
main_script: '/vendor/flasher/flasher.min.js'
116+
117+
# List of CSS files to style your notifications
118+
styles:
119+
- '/vendor/flasher/flasher.min.css'
120+
121+
# Set global options for all notifications (optional)
122+
# options:
123+
# # Time in milliseconds before the notification disappears
124+
# timeout: 5000
125+
# # Where the notification appears on the screen
126+
# position: 'top-right'
127+
128+
# Automatically inject JavaScript and CSS assets into your HTML pages
129+
inject_assets: true
130+
131+
# Enable message translation using Symfony's translation service
132+
translate: true
133+
134+
# URL patterns to exclude from asset injection and flash_bag conversion
135+
excluded_paths:
136+
- '/^\/_profiler/'
137+
- '/^\/_fragment/'
138+
139+
# Map Symfony flash message keys to notification types
140+
flash_bag:
141+
success: ['success']
142+
error: ['error', 'danger']
143+
warning: ['warning', 'alarm']
144+
info: ['info', 'notice', 'alert']
145+
146+
# Set criteria to filter which notifications are displayed (optional)
147+
# filter:
148+
# # Maximum number of notifications to show at once
149+
# limit: 5
150+
151+
# Define notification presets to simplify notification creation (optional)
152+
# presets:
153+
# # Example preset:
154+
# entity_saved:
155+
# type: 'success'
156+
# title: 'Entity saved'
157+
# message: 'Entity saved successfully'
158+
```
159+
160+
### Configuration Options
161+
162+
| **Option** | **Description** |
163+
|------------------|---------------------------------------------------------------------------------------------------------------------------|
164+
| `default` | **String**: The default notification library to use (e.g., `'flasher'`, `'toastr'`, `'noty'`, `'notyf'`, `'sweetalert'`). |
165+
| `main_script` | **String**: Path to the main PHPFlasher JavaScript file. |
166+
| `styles` | **Array**: List of CSS files to style your notifications. |
167+
| `options` | **Array** (Optional): Global options for all notifications (e.g., `'timeout'`, `'position'`). |
168+
| `inject_assets` | **Boolean**: Whether to automatically inject JavaScript and CSS assets into your HTML pages. |
169+
| `translate` | **Boolean**: Enable message translation using Symfony’s translation service. |
170+
| `excluded_paths` | **Array**: URL patterns to exclude from asset injection and flash_bag conversion. |
171+
| `flash_bag` | **Array**: Map Symfony flash message keys to notification types. |
172+
| `filter` | **Array** (Optional): Criteria to filter which notifications are displayed (e.g., `'limit'`). |
173+
| `presets` | **Array** (Optional): Define notification presets to simplify notification creation. |
174+
175+
## Quick Start
176+
177+
To display a notification message, you can either use the `flash()` helper function or obtain an instance of `flasher` from the service container. Then, before returning a view or redirecting, call the desired method (`success()`, `error()`, etc.) and pass in the message to be displayed.
178+
179+
### Using the `flash()` Helper
180+
181+
```php
182+
<?php
183+
184+
namespace App\Controller;
185+
186+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
187+
use Symfony\Component\HttpFoundation\RedirectResponse;
188+
189+
class BookController extends AbstractController
190+
{
191+
public function saveBook(): RedirectResponse
192+
{
193+
// Your logic here
194+
195+
flash('Your changes have been saved!');
196+
197+
return $this->redirectToRoute('book_list');
198+
}
199+
}
200+
```
201+
202+
### Using the `flasher` Service
203+
204+
```php
205+
<?php
206+
207+
namespace App\Controller;
208+
209+
use Flasher\Prime\FlasherInterface;
210+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
211+
use Symfony\Component\HttpFoundation\RedirectResponse;
212+
213+
class AnotherController extends AbstractController
214+
{
215+
private FlasherInterface $flasher;
216+
217+
public function __construct(FlasherInterface $flasher)
218+
{
219+
$this->flasher = $flasher;
220+
}
221+
222+
public function register(): RedirectResponse
223+
{
224+
// Your logic here
225+
226+
$this->flasher->success('Your changes have been saved!');
227+
228+
// ... redirect or render the view
229+
return $this->redirectToRoute('home');
230+
}
231+
232+
public function update(): RedirectResponse
233+
{
234+
// Your logic here
235+
236+
$this->flasher->error('An error occurred while updating.');
237+
238+
return $this->redirectToRoute('update_page');
239+
}
240+
}
241+
```
242+
243+
## Usage Examples
244+
245+
### Success Message
246+
247+
```php
248+
flash()->success('Operation completed successfully!');
249+
```
250+
251+
### Error Message
252+
253+
```php
254+
flash()->error('An error occurred.');
255+
```
256+
257+
### Info Message
258+
259+
```php
260+
flash()->info('This is an informational message.');
261+
```
262+
263+
### Warning Message
264+
265+
```php
266+
flash()->warning('This is a warning message.');
267+
```
268+
269+
### Passing Options
270+
271+
```php
272+
flash()->success('Custom message with options.', ['timeout' => 3000, 'position' => 'bottom-left']);
273+
```
274+
275+
### Using presets
276+
277+
Define a preset in your `config/packages/flasher.yaml`:
278+
279+
```yaml
280+
flasher:
281+
# ... other configurations
282+
283+
presets:
284+
entity_saved:
285+
type: 'success'
286+
title: 'Entity Saved'
287+
message: 'The entity has been saved successfully.'
288+
entity_deleted:
289+
type: 'warning'
290+
title: 'Entity Deleted'
291+
message: 'The entity has been deleted.'
292+
```
293+
294+
Use the preset in your controller:
295+
296+
```php
297+
<?php
298+
299+
namespace App\Controller;
300+
301+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
302+
use Symfony\Component\HttpFoundation\RedirectResponse;
303+
304+
class BookController extends AbstractController
305+
{
306+
public function save(): RedirectResponse
307+
{
308+
// Your saving logic
309+
310+
flash()->preset('entity_saved');
311+
312+
return $this->redirectToRoute('books.index');
313+
}
314+
315+
public function delete(): RedirectResponse
316+
{
317+
// Your deletion logic
318+
319+
flash()->preset('entity_deleted');
320+
321+
return $this->redirectToRoute('books.index');
322+
}
323+
}
324+
```
15325

16-
PHPFlasher is a powerful and easy-to-use package that allows you to quickly and easily add flash messages to your Laravel or Symfony projects.
17-
Whether you need to alert users of a successful form submission, an error, or any other important information, flash messages are a simple and effective solution for providing feedback to your users.
326+
## Adapters Overview
18327

19-
With PHPFlasher, you can easily record and store messages within the session, making it simple to retrieve and display them on the current or next page.
20-
This improves user engagement and enhances the overall user experience on your website or application.
328+
PHPFlasher supports various adapters to integrate seamlessly with different frontend libraries. Below is an overview of available adapters for Symfony:
21329

22-
Whether you're a beginner or an experienced developer, PHPFlasher's intuitive and straightforward design makes it easy to integrate into your projects.
23-
So, if you're looking for a reliable, flexible and easy to use flash messages solution, PHPFlasher is the perfect choice.
330+
| Adapter Repository | Description |
331+
|-----------------------------------------------------------------------------------------|--------------------------------|
332+
| [flasher-symfony](https://github.com/php-flasher/flasher-symfony) | Symfony framework adapter |
333+
| [flasher-toastr-symfony](https://github.com/php-flasher/flasher-toastr-symfony) | Toastr adapter for Symfony |
334+
| [flasher-noty-symfony](https://github.com/php-flasher/flasher-noty-symfony) | Noty adapter for Symfony |
335+
| [flasher-notyf-symfony](https://github.com/php-flasher/flasher-notyf-symfony) | Notyf adapter for Symfony |
336+
| [flasher-sweetalert-symfony](https://github.com/php-flasher/flasher-sweetalert-symfony) | SweetAlert adapter for Symfony |
24337

338+
> **Note:** Each adapter has its own repository. For detailed installation and usage instructions, please refer to the [Official Documentation](https://php-flasher.io).
25339
26340
## Official Documentation
27341

28-
Documentation for PHPFlasher can be found on the [https://php-flasher.io](https://php-flasher.io).
342+
Comprehensive documentation for PHPFlasher is available at [https://php-flasher.io](https://php-flasher.io). Here you will find detailed guides, API references, and advanced usage examples to help you get the most out of PHPFlasher.
29343

30344
## Contributors and sponsors
31345

@@ -42,7 +356,7 @@ Shining stars of our community:
42356
<table>
43357
<tbody>
44358
<tr>
45-
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/younes--ennaji//"><img src="https://avatars.githubusercontent.com/u/10859693?v=4?s=100" width="100px;" alt="Younes ENNAJI"/><br /><sub><b>Younes ENNAJI</b></sub></a><br /><a href="https://github.com/php-flasher/php-flasher/commits?author=yoeunes" title="Code">💻</a> <a href="https://github.com/php-flasher/php-flasher/commits?author=yoeunes" title="Documentation">📖</a> <a href="#maintenance-yoeunes" title="Maintenance">🚧</a></td>
359+
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/younes--ennaji/"><img src="https://avatars.githubusercontent.com/u/10859693?v=4?s=100" width="100px;" alt="Younes ENNAJI"/><br /><sub><b>Younes ENNAJI</b></sub></a><br /><a href="https://github.com/php-flasher/php-flasher/commits?author=yoeunes" title="Code">💻</a> <a href="https://github.com/php-flasher/php-flasher/commits?author=yoeunes" title="Documentation">📖</a> <a href="#maintenance-yoeunes" title="Maintenance">🚧</a></td>
46360
<td align="center" valign="top" width="14.28%"><a href="https://github.com/salmayno"><img src="https://avatars.githubusercontent.com/u/27933199?v=4?s=100" width="100px;" alt="Salma Mourad"/><br /><sub><b>Salma Mourad</b></sub></a><br /><a href="#financial-salmayno" title="Financial">💵</a></td>
47361
<td align="center" valign="top" width="14.28%"><a href="https://www.youtube.com/rstacode"><img src="https://avatars.githubusercontent.com/u/35005761?v=4?s=100" width="100px;" alt="Nashwan Abdullah"/><br /><sub><b>Nashwan Abdullah</b></sub></a><br /><a href="#financial-codenashwan" title="Financial">💵</a></td>
48362
<td align="center" valign="top" width="14.28%"><a href="https://darvis.nl/"><img src="https://avatars.githubusercontent.com/u/7394837?v=4?s=100" width="100px;" alt="Arvid de Jong"/><br /><sub><b>Arvid de Jong</b></sub></a><br /><a href="#financial-darviscommerce" title="Financial">💵</a></td>
@@ -52,7 +366,7 @@ Shining stars of our community:
52366
</tr>
53367
<tr>
54368
<td align="center" valign="top" width="14.28%"><a href="https://www.instagram.com/lucas.maciel_z"><img src="https://avatars.githubusercontent.com/u/80225404?v=4?s=100" width="100px;" alt="Lucas Maciel"/><br /><sub><b>Lucas Maciel</b></sub></a><br /><a href="#design-LucasStorm" title="Design">🎨</a></td>
55-
<td align="center" valign="top" width="14.28%"><a href="https://siek.io/"><img src="https://avatars.githubusercontent.com/u/5730766?v=4?s=100" width="100px;" alt="Antoni Siek"/><br /><sub><b>Antoni Siek</b></sub></a><br /><a href="https://github.com/php-flasher/php-flasher/commits?author=ImJustToNy" title="Code">💻</a></td>
369+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AhmedGamal"><img src="https://avatars.githubusercontent.com/u/11786167?v=4?s=100" width="100px;" alt="Ahmed Gamal"/><br /><sub><b>Ahmed Gamal</b></sub></a><br /><a href="https://github.com/php-flasher/php-flasher/commits?author=AhmedGamal" title="Code">💻</a> <a href="https://github.com/php-flasher/php-flasher/commits?author=AhmedGamal" title="Documentation">📖</a></td>
56370
</tr>
57371
</tbody>
58372
</table>
@@ -64,17 +378,17 @@ Shining stars of our community:
64378

65379
## Contact
66380

67-
PHPFlasher is being actively developed by <a href="https://github.com/yoeunes">yoeunes</a>.
381+
PHPFlasher is being actively developed by <a href="https://github.com/yoeunes">yoeunes</a>.
68382
You can reach out with questions, bug reports, or feature requests on any of the following:
69383

70-
- [Github Issues](https://github.com/php-flasher/php-flasher/issues)
384+
- [Github Issues](https://github.com/php-flasher/php-flasher/issues)
71385
- [Github](https://github.com/yoeunes)
72386
- [Twitter](https://twitter.com/yoeunes)
73-
- [Linkedin](https://www.linkedin.com/in/younes--ennaji//)
387+
- [Linkedin](https://www.linkedin.com/in/younes--ennaji/)
74388
- [Email me directly](mailto:[email protected])
75389

76390
## License
77391

78392
PHPFlasher is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
79393

80-
<p align="center"> <b>Made with ❤️ by <a href="https://www.linkedin.com/in/younes--ennaji//">Younes ENNAJI</a> </b> </p>
394+
<p align="center"> <b>Made with ❤️ by <a href="https://www.linkedin.com/in/younes--ennaji/">Younes ENNAJI</a> </b> </p>

0 commit comments

Comments
 (0)