-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.php
53 lines (47 loc) · 1.91 KB
/
functions.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
<?php
declare(strict_types=1);
namespace Flasher\Prime;
use Flasher\Prime\Container\FlasherContainer;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Type;
if (!\function_exists('Flasher\Prime\flash')) {
/**
* Creates a flash message or returns the Flasher factory.
*
* This function provides a convenient shorthand for working with PHPFlasher.
* It serves as the primary entry point in namespaced contexts.
*
* Design pattern: Gateway - Provides a simple entry point to the complex API.
*
* @param string|null $message The message content of the flash notification
* @param string $type The notification type (success, error, warning, info)
* @param array<string, mixed> $options Additional configuration options
* @param string|null $title The notification title
*
* @return Envelope|FlasherInterface Returns an Envelope when creating a notification,
* or a FlasherInterface when called with no arguments
*
* @phpstan-return ($message is empty ? FlasherInterface : Envelope)
*
* Example usage:
* ```php
* // Get the flasher factory
* $flasher = \Flasher\Prime\flash();
* $flasher->info('Information message');
*
* // Create a notification directly
* \Flasher\Prime\flash('Operation successful', Type::SUCCESS);
*
* // With additional options
* \Flasher\Prime\flash('Profile updated', Type::SUCCESS, ['timeout' => 5000], 'Success');
* ```
*/
function flash(?string $message = null, string $type = Type::SUCCESS, array $options = [], ?string $title = null): Envelope|FlasherInterface
{
$factory = FlasherContainer::create('flasher');
if (0 === \func_num_args()) {
return $factory;
}
return $factory->flash($type, $message, $options, $title);
}
}