{"id":37005484,"url":"https://github.com/emmanix2002/notifier","last_synced_at":"2026-01-14T00:40:28.270Z","repository":{"id":56977403,"uuid":"88048572","full_name":"emmanix2002/notifier","owner":"emmanix2002","description":"A library for handling and processing notifications","archived":true,"fork":false,"pushed_at":"2017-10-18T14:40:48.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-09T01:21:33.192Z","etag":null,"topics":["library","messaging","notification","php-library","php7"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emmanix2002.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-12T12:21:14.000Z","updated_at":"2024-06-11T18:28:51.000Z","dependencies_parsed_at":"2022-08-21T07:30:13.498Z","dependency_job_id":null,"html_url":"https://github.com/emmanix2002/notifier","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/emmanix2002/notifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmanix2002%2Fnotifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmanix2002%2Fnotifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmanix2002%2Fnotifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmanix2002%2Fnotifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmanix2002","download_url":"https://codeload.github.com/emmanix2002/notifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmanix2002%2Fnotifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","messaging","notification","php-library","php7"],"created_at":"2026-01-14T00:40:27.554Z","updated_at":"2026-01-14T00:40:28.261Z","avatar_url":"https://github.com/emmanix2002.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Notifier\n==========\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nA library for handling and processing notifications.   \n\n* [Installation](#installation)\n* [Introduction](#introduction)\n* [Process Flow](#process-flow)\n* [Message](#message)\n* [Recipient Collection](#recipient-collection)    \n* [Handlers](#handlers)\n* [Usage](#usage)\n\n## Installation\nTo install the package, you simply run:\n\n    composer require emmanix2002/notifier\n\n## Introduction\nThe notifier works using the the following concepts:   \n\n- **Channels**: channels are named groupings of handlers which receive a _message_ and a list of _recipients_    \n- **Handlers**: handlers are instances of `Emmanix2002\\Notifier\\Handler\\HandlerInterface`, which \nare tied to _channels_, and are passed the _message_ and _recipients_ for delivery.     \n- **Processors**: processors are _callable_ that are passed the _message_ and _recipients_ for processing, \nbefore they're passed to the relevant _channels_ or _handlers_. Processors are used to filter or make \nadjustments to the _message_ or _recipients_ before they are passed down to the _channel_. Processors can \nbe added to the main `Notifier` class, or to individual _Channels_.   \n    - _Processors_ added to the `Notifier` class are called before the message and recipients are passed \n    to the _Channels_; while    \n    - _Processors_ added to a `Channel` are passed the message and recipients before they're passed to the \n     _Handlers_    \n- **Message**: a message, is an instance of `Emmanix2002\\Notifier\\Message\\MessageInterface` is the \ninformation that requires sending to _recipients_.\n- **Recipients**: by default, the `notify()` methods expect a list of recipients; even if you only need to \nsend a message to a single recipient, you still need to provide an `Collection` of one item. This \ncollection should be an instance of `Emmanix2002\\Notifier\\Recipient\\RecipientCollection`.    \n\nBy default, 2 handlers are provided to get you started:    \n- InfobipSmsHandler: for sending SMS messages using the Infobip API\n- SendgridEmailHandler: for sending email messages using the Sendgrid API \n\n## Process Flow\nThis is the expected flow for using the notifier:\n\n1. Create an instance of `Notifier` (you can use the `Notifier::instance()` to have a shared instance through the application)\n2. **(optional)** Add one or more _Processors_ to the `Notifier`\n3. Create your `Message` (for instance, you could create an `SmsMessage`)\n4. Create your `Recipient` (e.g. for SMS, we need a phone number, we could say `$recipients = new RecipientCollection(['2348123456789'], PhoneRecipient::class);`)\n5. Call your `Notifier::notify($message, $recipients)`    \n\nSo it flows like:\n\n    Notifier -\u003e (Processors) -\u003e Channels -\u003e (Processors) -\u003e Handlers\n    \nYou see `(Processors)` appear twice, here's why:\n- The first is triggered for _processors_ added to the `Notifier`; while\n- The second is triggered for _processors_ added to the `Channel`   \n\n## Message\nA message is an instance of `Emmanix2002\\Notifier\\Message\\MessageInterface`. A `MessageInterface` implementation \nencapsulates the data that is to be sent out to the recipients.    \n\nA few message types are provided by default:    \n- `Emmanix2002\\Notifier\\Message\\EmailMessage`: this is a basic email message implementation, providing this such as: \n`Bcc`, `Cc`, `Subject`, `ReplyTo`, `From` and `Body` fields. Any handler processing emails should be able to get all \ninformation required for creating the email from an instance of this class.    \n- `Emmanix2002\\Notifier\\Message\\SmsMessage`: just like the `EmailMessage` class, this class is the basic implementation \nfor an **sms** text message. It has only one field: `message`, which is the `string` containing the message.\n- `Emmanix2002\\Notifier\\Message\\InfobipSmsMessage`: this implementation is a more advanced version of the `SmsMessage` \nclass, providing special properties (or fields) unique to the Infobip system. It _extends_ `SmsMessage` providing many \nother fields like: `notifyUrl` (for delivery reports), `notifyContentType` (the content type used to represent the \ndelivery report), and `scheduleFor` (a `\\DateTime` instance representing when the message should be sent - scheduling SMS)\n- `Emmanix2002\\Notifier\\Message\\SendgridEmailMessage`: this also is an advanced implementation of the `EmailMessage` \nclass. It _extends_ it and also provides a few additional properties unique to Sendgrid like: `templateId`, `sections`, \nand even `category` (for tagging the message(s)).\n\n## Recipient Collection\nThe `RecipientCollection` represents a list/collection of `destinations` that the notification should be sent to; it \nalso tries to understand how to interpret each of these addresses (it does so from the second `__construct()` parameter).    \n\nA `recipient` is an instance of `Emmanix2002\\Notifier\\Recipient\\RecipientInterface`; all recipients are expected to \n`implement` this interface.    \n\nSome default recipient classes are provided with the package:    \n- `Emmanix2002\\Notifier\\Recipient\\PhoneRecipient`: this `recipient` is useful for addressing phone numbers; a simple \narray of strings can be passed to the `RecipientCollection` to create this. For example: \n    \n        $phones = ['2348123456789', '23481223456789'];\n        $collection = new RecipientCollection($phones, PhoneRecipient::class);\n        // see the examples/sms-notify.php file for the full example\n        \n    As you can see with this, the destination address is simply an array of `strings`.\n    \n- `Emmanix2002\\Notifier\\Recipient\\EmailRecipient`\n- `Emmanix2002\\Notifier\\Recipient\\SendgridEmailRecipient`\n    \nThe _first parameter_ of the `RecipientCollection` constructor supports 3 forms:    \n\n1. An array of strings e.g. `$collection = new RecipientCollection(['email@domain.com', ...], EmailRecipient::class);`    \nwhen looping through (or when accessing an index - `$collection[0]` - it returns an instance of the _second argument_ \nwhich is a class that implements `RecipientInterface`).      \nIt does so by passing each `string` element of the array as the first argument of the class recipient constructor.    \n \n2. An array of `RecipientInterface` instances. You can see this from the `examples/email-notify.php` example file.    \nEven though it's an array of `RecipientInterface` instances, you still need to pass the _second parameter_.    \nLike before, when looping or accessing an offset of the collection, you'll get a `RecipientInterface` instance.    \n\n3. An array with a form representing the constructor form of the desired `RecipientInterface` implementation. Take a \nlook at the `examples/email-notify-using-address-array.php` example.    \n This form is the _most flexible_ because it allows you to keep your code simple and clean, without having to create \n too many objects until you really need to.    \n  It splits the array and passes the indexes as the arguments to the `__construct()` method of the instance. For instance, \n  it passes **index 0** as the **first parameter**, **index 1** as the **second parameter**, and so forth.    \n  \nEach of the files inside the `examples` directory highlight these 2 forms. So, feel free to create your own \n`RecipientInterface` implementations.    \n\n## Handlers\n**Handlers** are instances of `HandlerInterface` (see [Introduction](#introduction)). When you create a channel, you \neither pass the handlers in the constructor, or you add them one at a time on the created `Channel`.     \n\nHandlers are the actual mechanism that send out the notifications; without handlers, a channel basically does nothing.    \nHandlers added to a channel are stored in a stack (i.e. Last-In, First-Out - **LIFO**); meaning, the last handler added \nto a channel gets executed first.     \n\nAfter a handler is called, and it completes execution, it returns either a `boolean` value or any other value as \nrequired, that informs the notifier whether or not the request (i.e. `Message` and `RecipientCollection`) should be \npassed to the next handler for processing:    \n\n- `boolean` (`true` or `false`): the request should be forwarded (`true`) to the next handler, else (`false`) it should not    \n- `mixed`: any other value besides the **boolean** (`true`) causes the notifier to stop at this handler, and return \nthis value. This is useful in scenarios where the actual response from the handler is important.     \n\nHandlers **must** define a `propagate(): bool` method on themselves to describe the propagate preference for the handler.    \nBy default, all handlers that `extend` the `AbstractHandler` class **return** `false` - meaning *they don't propagate*.         \n\n## Usage\nSee the `examples` directory for more.\n\n[ico-version]: https://img.shields.io/packagist/v/emmanix2002/notifier.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/emmanix2002/notifier/master.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/emmanix2002/notifier.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/emmanix2002/notifier\n[link-travis]: https://travis-ci.org/emmanix2002/notifier\n[link-downloads]: https://packagist.org/packages/emmanix2002/notifier\n[link-author]: https://github.com/emmanix2002","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmanix2002%2Fnotifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmanix2002%2Fnotifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmanix2002%2Fnotifier/lists"}