phil / announcement-bar
Show visitors one dated, targeted site announcement at a time, closed until it changes: levels, paths, roles, languages and cache expiry.
Package info
github.com/parler-haut-interagir-librement/announcement-bar
pkg:composer/phil/announcement-bar
Requires
- php: >=8.5
- ext-mbstring: *
- phil/url: ^0.1.2@dev
Requires (Dev)
- phpunit/phpunit: ^13.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 03:12:47 UTC
README
Show visitors the one announcement that matters to them, at the right time and on the right pages, and let them close it until it changes.
phil/announcement-bar is a plain PHP library for the bar across the top of a site: "Doors open at 9 on Saturday", "Payments are down, we are on it", "Members: the new schedule is out". Editors write announcements with a period, a level and an audience; on each page, the library picks the one announcement the visitor should see, and remembers the ones they closed. The application stores the announcements, renders the bar and keeps the visitor's dismissals.
- One announcement at a time: the most pressing level first — urgent, then warning, then news —, and within a level the order the editors set by placing each announcement before or after another. No carousel.
- Dated: shown from a start, included, to an end, excluded;
nextChange()gives the next instant the bar may change, for a page cached with it to expire then. - Targeted: signed-in visitors or guests, the holders of some roles, the pages under some paths and not under others, the visitors reading in some languages.
- Closed until it changes: a dismissal is kept under the announcement's identifier and a fingerprint of its text, link and level, so an edited announcement shows again. An announcement that must stay in view, such as an outage notice, is not dismissible.
- Dismissals without tracking: a short text of at most 50 keys, for a functional cookie, the browser's storage or the member's settings, read back within a size limit and never failing on a damaged value.
- Accessible: each level gives the ARIA role of the bar,
alertfor an urgent announcement only,regionfor the others. - Safe text and links: one line of plain text without control or bidirectional override characters; a link goes
to a path of the site or to an
httporhttpsaddress, never tojavascript:. - Worker-safe: nothing is kept outside the values the application passes, so one long-running worker serves any number of sites.
Status
| Part | State |
|---|---|
| Announcements, links, levels and periods | Implemented and tested |
| Audiences: sign-in, roles, paths, languages | Implemented and tested |
| The board: order by before and after, selection, next change | Implemented and tested |
| Dismissals and their stored text | Implemented and tested, fuzzed |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements, installing, a first bar. |
| Announcements | The message, the link, the level, the period and the fingerprint. |
| Audiences | Who sees an announcement: sign-in, roles, paths and languages. |
| The board | The editors' order, which announcement is shown, and caching. |
| Dismissals | Closing an announcement, the stored text and where to keep it. |
| Rendering | Markup, roles and layout for an accessible bar. |
| Extension points | What an application may replace or add, and what is stable. |
| Testing | The tests, the fuzz target and the benchmark. |
| Reference | Every public type, with its role. |
Quick start
composer require phil/announcement-bar
use Phil\AnnouncementBar\Announcement; use Phil\AnnouncementBar\AnnouncementLink; use Phil\AnnouncementBar\Board; use Phil\AnnouncementBar\Dismissals; use Phil\AnnouncementBar\Level; use Phil\AnnouncementBar\Visitor; $board = new Board([ new Announcement('doors', 'Doors open at 9 on Saturday.', link: new AnnouncementLink('/schedule', 'See the schedule')), new Announcement('outage', 'Payments are down; we are on it.', Level::Urgent, dismissible: false), ]); $visitor = new Visitor( $request->getPathInfo(), signedIn: null !== $user, roles: $user?->getRoles() ?? [], locale: $request->getLocale(), dismissals: Dismissals::fromString($request->cookies->getString('announcements')), ); $announcement = $board->select($visitor, $clock->now()); // the outage: urgent comes first
Requirements
PHP 8.5 or later with ext-mbstring, and phil/url, which reads the absolute addresses of links.
Contributing
Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.
License
MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.