-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFlasherInterface.php
106 lines (100 loc) · 4.29 KB
/
FlasherInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace Flasher\Prime;
use Flasher\Prime\Factory\NotificationFactoryInterface;
use Flasher\Prime\Response\Presenter\ArrayPresenter;
/**
* FlasherInterface - The primary entry point to the notification system.
*
* This interface defines the contract for the notification service,
* providing methods to access notification factories and render
* notifications. It's the main touchpoint for client code.
*
* Design pattern: Façade Pattern - Provides a simplified interface
* to the complex notification subsystems.
*
* @mixin \Flasher\Prime\Notification\NotificationBuilder
*
* @phpstan-import-type ArrayPresenterType from ArrayPresenter
*/
interface FlasherInterface
{
/**
* Get a notification factory instance by its alias.
*
* This method provides access to specific notification factories (like Toastr, SweetAlert, etc.)
* through a unified interface. It allows you to use specialized notification features
* while maintaining a consistent API.
*
* Example:
* ```php
* $flasher->use('toastr')->success('Message using Toastr library');
* ```
*
* @param string $alias The alias of the factory to retrieve (e.g., 'toastr', 'sweetalert')
*
* @throws \InvalidArgumentException When the requested factory cannot be resolved
*
* @phpstan-return ($alias is 'flasher' ? \Flasher\Prime\Factory\FlasherFactoryInterface :
* ($alias is 'noty' ? \Flasher\Noty\Prime\NotyInterface :
* ($alias is 'notyf' ? \Flasher\Notyf\Prime\NotyfInterface :
* ($alias is 'sweetalert' ? \Flasher\SweetAlert\Prime\SweetAlertInterface :
* ($alias is 'toastr' ? \Flasher\Toastr\Prime\ToastrInterface :
* \Flasher\Prime\Factory\NotificationFactoryInterface)))))
*/
public function use(string $alias): NotificationFactoryInterface;
/**
* Get a notification factory instance by its alias (alias for use()).
*
* This method is identical to use() but provides a more intuitive name
* for creating new notification factories.
*
* Example:
* ```php
* $flasher->create('sweetalert')->success('Message using SweetAlert library');
* ```
*
* @param string $alias The alias of the factory to retrieve (e.g., 'toastr', 'sweetalert')
*
* @throws \InvalidArgumentException When the requested factory cannot be resolved
*
* @phpstan-return ($alias is 'flasher' ? \Flasher\Prime\Factory\FlasherFactoryInterface :
* ($alias is 'noty' ? \Flasher\Noty\Prime\NotyInterface :
* ($alias is 'notyf' ? \Flasher\Notyf\Prime\NotyfInterface :
* ($alias is 'sweetalert' ? \Flasher\SweetAlert\Prime\SweetAlertInterface :
* ($alias is 'toastr' ? \Flasher\Toastr\Prime\ToastrInterface :
* \Flasher\Prime\Factory\NotificationFactoryInterface)))))
*/
public function create(string $alias): NotificationFactoryInterface;
/**
* Renders the flash notifications based on the specified criteria, presenter, and context.
*
* This method retrieves notifications from storage and formats them for display.
* Different presenter formats can be specified (html, json, array) to support
* various output requirements.
*
* Example:
* ```php
* // Render as HTML
* $html = $flasher->render('html');
*
* // Render as JSON (for API responses)
* $json = $flasher->render('json');
*
* // Render with filtering criteria
* $errors = $flasher->render('html', ['type' => 'error']);
* ```
*
* @param string $presenter The format to render notifications in ('html', 'json', 'array')
* @param array<string, mixed> $criteria Optional filtering criteria for notifications
* @param array<string, mixed> $context Additional context or options for rendering
*
* @return mixed The rendered notifications in the requested format
*
* @phpstan-return ($presenter is 'html' ? string :
* ($presenter is 'array' ? ArrayPresenterType :
* ($presenter is 'json' ? ArrayPresenterType :
* mixed)))
*/
public function render(string $presenter = 'html', array $criteria = [], array $context = []): mixed;
}