PHPackages                             kusabi/messages - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kusabi/messages

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kusabi/messages
===============

A library implementing a response message manager

1.0.1(6y ago)032mitPHPPHP ~7.2CI failing

Since Mar 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/kusabi/messages)[ Packagist](https://packagist.org/packages/kusabi/messages)[ RSS](/packages/kusabi-messages/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

[![Release Badge](https://camo.githubusercontent.com/a5acf3f745097087941cd9c2cb034725bf8335015e5f2bf2f78808fe9a874e14/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6b75736162692f6d657373616765732e737667)](https://img.shields.io/github/release/kusabi/messages.svg)[![Tag Badge](https://camo.githubusercontent.com/01718825e55357b2b96bec811a7869bdffa5a489f5f43b964e1056bacecfd9ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6b75736162692f6d657373616765732e737667)](https://img.shields.io/github/tag/kusabi/messages.svg)[![Licence Badge](https://camo.githubusercontent.com/5673af2131cb523bdc3d3f30665e5654636d0fc70078a4e39582348bc609c46a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b75736162692f6d657373616765732e737667)](https://img.shields.io/github/license/kusabi/messages.svg)[![Issues Badge](https://camo.githubusercontent.com/60206f0c9efc2128cddafc554c8509c34fab4bed93f65647fa47bdcceee7ed84/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6b75736162692f6d657373616765732e737667)](https://img.shields.io/github/issues/kusabi/messages.svg)[![Codacy Badge](https://camo.githubusercontent.com/d1b19a3830b94289437a1b5cb9ac7d4d30c5a5e6dcc1b467516f02d349d5d526/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f37656334643936343138396634646133383435623830633030396638643866652e737667)](https://img.shields.io/codacy/grade/7ec4d964189f4da3845b80c009f8d8fe.svg)[![Code Size](https://camo.githubusercontent.com/edbdc9ad91a61da6079a1dcee25de852e1a06373e958776d0ad76084c00ad428/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6b75736162692f6d657373616765732e737667)](https://img.shields.io/github/languages/code-size/kusabi/messages.svg)

A message collection library for responses.

It is compatible with the PSR LoggerInterface.

How to use Messages
===================

[](#how-to-use-messages)

A message is the smallest unit in the library.

It contains a message and a context.

The message is a `string` and the context is an `array`.

All manipulator methods return the instance of Message for fluid chaining.

`$message->setMessage('Success')->setContext([1, 2, 3]);`

```
use Kusabi\Messages\Message;

// Creating a blank message
$message = new Message();

// Creating a message with a simple success string
$message = new Message('Successfully retrieved users');

// Creating a message with context.
// Here the context suggests we are only retriving recent users.
$message = new Message('Successfully retrieved users', [
    'created' => 'recent'
]);

// Updating the message after creation
$message->setMessage('Changed the message');
$message->setContext([
    'created' => 'recent',
    'changed_at' => date('Y-m-d H:i:s')
]);

// Merging more context data into the context array
$message->mergeContext([
    'changed_at' => date('Y-m-d H:i:s'),
    'reason' => 'merged'
]);

// Add more entries to the context using a key and value
$message->addContext('php', '7.2');

// Retrieving the values
$message->getMessage();
$message->getContext();

// Json encode the message
echo json_encode($message); // {"message":"Changed the message", "context":{...}}

// Cast as string just returns the message
echo (string) $message; // "Changed the message"
```

How to use Message Groups
=========================

[](#how-to-use-message-groups)

A message group is a collection of messages.

It is an array wrapper around this collection of message.

All manipulator methods return the instance of MessageGroup for fluid chaining.

```
$messageGroup->addMessage('Success', [])->clearMessages()->count();
```

```
// Creating a Message Group
$messageGroup = new MessageGroup();
$messageGroup->addMessage('Test Message', [
    'context' => 1
]);
$messageGroup->addMessageInstance(
    new Message('Test message')
);
$messageGroup[] = new Message('Test');

// Clearing the message group
$messageGroup->setMessages([]);
$messageGroup->clearMessages();

// Accessing Message Group properties
if (count($messageGroup) > 0) {
    foreach($messageGroup as $message) {
        echo $message->getMessage();
    }
    $messageGroup->clearMessages();
}

// Json encode the message group
echo json_encode($messageGroup); // [{"message":"First Message", "context":{...}},{"message":"Second Message", "context":{...}}]

// Cast as string just returns the messages
echo (string) $messageGroup; // "First Message, Second Message"
```

How to use Message Collections
==============================

[](#how-to-use-message-collections)

A message collection is a collection of message groups.

It has one for each verbosity level.

It acts as an array wrapper around this collection of message groups.

All manipulator methods return the instance of MessageCollection for fluid chaining.

```
$messageCollection
    ->success('It worked')
    ->notice('We will be experiencing down time shortly', [
        'start' => '1970-01-01 12:00:00'
    ]);
```

```
// Creating a Message Collection
$messageCollection = new MessageCollection();
$messageCollection->info('We will be experiencing downtime next Sunday', [
    'timestamp' => $nextWeek->getTimestamp()
]);
$messageCollection->error('Failed to connect to database', [
    'host' => '127.0.0.1',
    'password' => 'secret'
]);

// Accessing Message Collection properties
$messageCollection->getMessageGroups();
$messageCollection->getMessages();
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~210 days

Total

2

Last Release

2399d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62f4942978644437b5ff3d7bd3f6411580413d327b001104acd4914f43ab63b6?d=identicon)[kusabi](/maintainers/kusabi)

---

Top Contributors

[![kusabi](https://avatars.githubusercontent.com/u/22000941?v=4)](https://github.com/kusabi "kusabi (3 commits)")

---

Tags

messagespsr-3response

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/kusabi-messages/health.svg)

```
[![Health](https://phpackages.com/badges/kusabi-messages/health.svg)](https://phpackages.com/packages/kusabi-messages)
```

###  Alternatives

[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[j0k3r/php-readability

Automatic article extraction from HTML

186808.8k6](/packages/j0k3r-php-readability)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
