File: 02-notification.md

package info (click to toggle)
php-jolicode-jolinotif 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772 kB
  • sloc: php: 1,815; makefile: 19; ansic: 11
file content (84 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download
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
# Notification

`Notification` is the main model of JoliNotif. It contains all the options
that should be applied - if possible - by the driver.

> **Note**
> Drivers are designed to handle the options they support and discard not
> supported ones gracefully without throwing any exception.

Currently, only three options are supported but new ones could be added later.
Each option can be set via a setter on the `Notification` class.

## Body

The body is the main message of the notification that you want to display.

> **Note**
> This is the only required option. Drivers will throw an`InvalidNotificationException`
> if the body is empty or null.

## Title

You can also optionally provide a title. Drivers will certainly display the
title above the body, in bold.

## Icon

An icon can also be displayed inside the notification. You will need to set an
**absolute path**.

```php
$notification->setIcon(__DIR__.'/Resources/icons/success.png');
```

> **Note**
> If you use JoliNotif from a phar and add a notification icon, we will take
> care to extract this icon in your system temp directory to make it accessible
> from command line executable.

Not all drivers support icon but again, you can safely add an icon to your
notification since the driver will simply discard it if not supported.

## Options with restricted support

Some options are available only on few drivers. They can be configured
through the `addOption` method.

### Subtitle

Only works with AppleScriptDriver at the moment.

```php
$notification->addOption('subtitle', 'This is a subtitle');
```

### Sound

Only works with AppleScriptDriver and TerminalNotifierDriver at the moment.

Non-exhaustive list of sounds: Basso, Frog, Hero, Pop, Submarine, Blow, Funk,
Morse, Purr, Tink, Bottle, Glass, Ping, Sosumi.

```php
$notification->addOption('sound', 'Frog');
```

### Url

Only works with TerminalNotifierDriver at the moment.

```php
$notification->addOption('url', 'https://google.com');
```

## Next readings

* [Drivers](03-drivers.md)
* [CRON usage](04-cron-usage.md)
* [CLI usage](05-cli-usage.md)

Previous pages:

* [Basic usage](01-basic-usage.md)
* [README](../README.md)