mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 23:17:47 +01:00
chore: update the doc and improve phpstan annotations
This commit is contained in:
+15
-28
@@ -12,16 +12,18 @@ Then, before returning a view or redirecting, call the `success()` method and pa
|
||||
```php
|
||||
{{ id }}
|
||||
|
||||
use Flasher\Prime\FlasherInterface;
|
||||
|
||||
class BookController
|
||||
{
|
||||
public function saveBook()
|
||||
{
|
||||
// ...
|
||||
|
||||
flash('{{ message }}');
|
||||
|
||||
flash()->success('{{ site.data.messages["success"] | sample }}');
|
||||
|
||||
|
||||
flash('{{ message }}');
|
||||
|
||||
// ... redirect or render the view
|
||||
}
|
||||
|
||||
@@ -31,9 +33,9 @@ class BookController
|
||||
public function register(FlasherInterface $flasher)
|
||||
{
|
||||
// ...
|
||||
|
||||
|
||||
$flasher->success('{{ site.data.messages["success"] | sample }}');
|
||||
|
||||
|
||||
// ... redirect or render the view
|
||||
}
|
||||
}
|
||||
@@ -116,31 +118,27 @@ flash()->flash(string $type, string $message, string $title = null, array $optio
|
||||
flash()->flash('{{ type }}', '{{ message }}');
|
||||
```
|
||||
|
||||
| param | description |
|
||||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `$type` | Notification type : <span class="text-white bg-green-600 px-2 py-1 rounded">success</span>, <span class="text-white bg-red-600 px-2 py-1 rounded">error</span>, <span class="text-white bg-yellow-600 px-2 py-1 rounded">warning</span>, <span class="text-white bg-blue-600 px-2 py-1 rounded">info</span> ....etc |
|
||||
| `$message` | The body of the message you want to deliver to your user. This may contain HTML. If you add links, be sure to add the appropriate classes for the framework you are using. |
|
||||
| `$title` | The notification title, Can also include HTML |
|
||||
| `$options` | Custom options for javascript libraries (toastr, noty, notyf ...etc) | |
|
||||
| param | description |
|
||||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `$type` | Notification type : <span class="text-white bg-green-600 px-2 py-1 rounded">success</span>, <span class="text-white bg-red-600 px-2 py-1 rounded">error</span>, <span class="text-white bg-yellow-600 px-2 py-1 rounded">warning</span>, <span class="text-white bg-blue-600 px-2 py-1 rounded">info</span> |
|
||||
| `$message` | The body of the message you want to deliver to your user. This may contain HTML. If you add links, be sure to add the appropriate classes for the framework you are using. |
|
||||
| `$title` | The notification title, Can also include HTML |
|
||||
| `$options` | Custom options for javascript libraries (toastr, noty, notyf ...etc) |
|
||||
|
||||
|
||||
---
|
||||
|
||||
## <i class="fa-duotone fa-list-radio"></i> Modifiers
|
||||
|
||||
<p id="method-options"><a href="#method-options" class="anchor"><i class="fa-duotone fa-link"></i> options</a></p>
|
||||
|
||||
You can specify **custom options** for the flash messages when using a JavaScript library like `toastr`, `noty`, or `notyf`. <br /><br />
|
||||
The `options()` method allows you to set multiple options at once by passing an array of `key-value` pairs,
|
||||
while the `option()` method allows you to set a single option by specifying its name and value as separate arguments. <br /><br />
|
||||
The optional `$merge` argument for the `options()` method can be used to specify whether the new options should be merged with any existing options,
|
||||
The optional `$append` argument for the `options()` method can be used to specify whether the new options should be appended to any existing options,
|
||||
or whether they should overwrite them.
|
||||
|
||||
```php
|
||||
flash()->options(array $options, bool $merge = true);
|
||||
flash()->options(array $options, bool $append = true);
|
||||
```
|
||||
|
||||
> Refer to the documentation for your chosen JavaScript library to see which options are available and how they should be formatted.
|
||||
|
||||
{% assign id = '#/ usage options' %}
|
||||
{% assign type = site.data.messages.types | sample %}
|
||||
@@ -158,12 +156,6 @@ flash()
|
||||
])
|
||||
->{{ type }}('{{ message }}');
|
||||
```
|
||||
|
||||
| param | description |
|
||||
|------------|--------------------------------------------------------------------------------------|
|
||||
| `$options` | Custom options to be passed to the javascript libraries (toastr, noty, notyf ...etc) |
|
||||
| `$merge` | Merge options if you call the options method multiple times |
|
||||
|
||||
---
|
||||
|
||||
<p id="method-option"><a href="#method-option" class="anchor"><i class="fa-duotone fa-link"></i> option</a></p>
|
||||
@@ -189,11 +181,6 @@ flash()
|
||||
->{{ type }}('{{ message }}');
|
||||
```
|
||||
|
||||
| param | description |
|
||||
|-----------|--------------|
|
||||
| `$option` | Option key |
|
||||
| `$value` | Option value |
|
||||
|
||||
---
|
||||
|
||||
<p id="method-priority"><a href="#method-priority" class="anchor"><i class="fa-duotone fa-link"></i> priority</a></p>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<div data-controller="playground"
|
||||
data-playground-adapter-value="flasher"
|
||||
data-playground-type-value="info"
|
||||
data-playground-message-value="Welcome to PHPFlasher!"
|
||||
data-playground-title-value="Information"
|
||||
class="max-w-7xl mx-auto p-8 bg-white rounded-xl shadow-lg my-10">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-10">
|
||||
<div class="space-y-6">
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label for="title" class="block text-sm font-semibold text-gray-700">Title</label>
|
||||
<input id="title" type="text" data-playground-target="title" value="Information" class="mt-2 block w-full rounded-lg border border-gray-300 shadow-sm focus:border-indigo-600 focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 text-lg px-4 py-2"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="message" class="block text-sm font-semibold text-gray-700">Message</label>
|
||||
<input id="message" type="text" data-playground-target="message" value="Welcome to PHPFlasher!" class="mt-2 block w-full rounded-lg border border-gray-300 shadow-sm focus:border-indigo-600 focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 text-lg px-4 py-2"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-700">Type</label>
|
||||
<div id="type-options" class="mt-4 flex space-x-4">
|
||||
<button type="button" class="py-1 px-4 rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" data-action="click->playground#selectType" data-value="info">info</button>
|
||||
<button type="button" class="py-1 px-4 rounded-md text-white bg-yellow-500 hover:bg-yellow-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-yellow-500" data-action="click->playground#selectType" data-value="warning">warning</button>
|
||||
<button type="button" class="py-1 px-4 rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500" data-action="click->playground#selectType" data-value="error">error</button>
|
||||
<button type="button" class="py-1 px-4 rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500" data-action="click->playground#selectType" data-value="success">success</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div data-playground-target="optionsContainer" class="space-y-4"></div>
|
||||
|
||||
<button data-action="click->playground#showNotification" class="w-full bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-md transition ease-in-out duration-150">
|
||||
Show Notification
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="rounded-lg">
|
||||
<pre id="php-code-snippet" class="text-white overflow-auto"><code data-playground-target="codeSnippet" class="language-php"></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user