PHPackages                             rnr1721/le7-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. [Framework](/categories/framework)
4. /
5. rnr1721/le7-messages

ActiveLibrary[Framework](/categories/framework)

rnr1721/le7-messages
====================

Messages for le7 PHP MVC framework

1.0.3(2y ago)0841MITPHPPHP &gt;=8.1

Since Mar 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rnr1721/le7-messages)[ Packagist](https://packagist.org/packages/rnr1721/le7-messages)[ RSS](/packages/rnr1721-le7-messages/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (1)

le7-messages
============

[](#le7-messages)

This package is probably easy and convenient to implement flash messages using cookies or session or use without storage as message collection.

It is also possible to make simple, standardized messages for a web page or API response. Messages can be grouped by source and type. It is possible to apply your own set of sources or types.

This package use only one dependency - rnr1721/le7-cookie-wrapper for managing sessions and cookies

Message types (can not set own):

- info
- error
- question
- alert
- warning

predefined sources (can set own):

- core
- application
- user
- event
- system

Requirements
------------

[](#requirements)

- PHP 8.1 or higher.
- Composer 2.0 or higher.

What it can?
------------

[](#what-it-can)

- Add new messages to collection
- get messages by source or type
- get messages in full formar (with type and source or as plain array)
- Store messages in session or cookies or get it from these sources

Installation
------------

[](#installation)

```
composer require rnr1721/le7-messages
```

Testing
-------

[](#testing)

```
composer test
```

How use?
--------

[](#how-use)

```
use Core\Session\SessionNative;
use Core\Cookies\CookiesNative;
use Core\Messages\MessageFactoryGeneric;

    $session = new SessionNative();
    $cookies = new CookiesNative();
    $factory = new MessageFactoryGeneric($cookies, $session);

    $messages = $factory->getMessagesSession();
    // $messages = $factory->getMessagesCookie(); // If need cookies storage
    // $messages = $factory->getMessageCollection(); // if no need storage

    $messages->alert("Alert message");
    $messages->info("Info message");
    $messages->warning("Warning messages");
    $messages->question("Question message");
    $messages->error("error message");

    // And when we need to output all:
    $message->getAll(); //return messages array

    $messages->getErrors(); // Get all errors
    $messages->getErrors(true); // Get all errors as plain array
    $messages->getAlerts(); // Get all alerts
    $messages->getWarnings();
    $messages->getQuestions();
    $messages->getInfos();
    $messages->getErrors();

    // You can use a message contexts.
    // For example:
    $messages->alert('My message','application');
    $messages->warning('my message','core');
    $messages->error('error message','core');

    $messages->getBySource('core'); // Get all with core context
    $messages->getBySource('core', true); // Plain output

    // Put messages to session or to cookies
    $messages->putToDestination();

    // Get messages from session or from cookies as array
    $messages->getFromSource;

    // Load messages from session or from cookies
    $messages->loadMessages();

    // Clear all messages
    $messages->clear();

    // Return if empty messages
    $messages->isEmpty();
```

### What implemented?

[](#what-implemented)

```
