{"id":24475576,"url":"https://github.com/nassiry/flash-messages","last_synced_at":"2025-05-07T06:06:36.495Z","repository":{"id":270820573,"uuid":"911533719","full_name":"nassiry/flash-messages","owner":"nassiry","description":"A lightweight PHP library for handling flash messages with session storage \u0026 rendering.","archived":false,"fork":false,"pushed_at":"2025-04-19T06:07:08.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T06:06:31.628Z","etag":null,"topics":["flash-messages","flash-rendering","notifications","php-flash","php-notifications","php-sessions","php-simple-flashes","php-simple-notifications","session-messages"],"latest_commit_sha":null,"homepage":"https://github.com/nassiry/flash-messages","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/nassiry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-03T08:42:22.000Z","updated_at":"2025-04-22T05:02:41.000Z","dependencies_parsed_at":"2025-01-03T10:33:22.833Z","dependency_job_id":"f08fc705-a134-4dc2-9e94-bb76fb707292","html_url":"https://github.com/nassiry/flash-messages","commit_stats":null,"previous_names":["nassiry/flash-messages"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nassiry%2Fflash-messages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nassiry%2Fflash-messages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nassiry%2Fflash-messages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nassiry%2Fflash-messages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nassiry","download_url":"https://codeload.github.com/nassiry/flash-messages/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823918,"owners_count":21809713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["flash-messages","flash-rendering","notifications","php-flash","php-notifications","php-sessions","php-simple-flashes","php-simple-notifications","session-messages"],"created_at":"2025-01-21T09:15:17.293Z","updated_at":"2025-05-07T06:06:36.484Z","avatar_url":"https://github.com/nassiry.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Flash Messages\n\n![Tests](https://github.com/nassiry/flash-messages/actions/workflows/tests.yml/badge.svg)\n![Packagist Downloads](https://img.shields.io/packagist/dt/nassiry/flash-messages)\n![Packagist Version](https://img.shields.io/packagist/v/nassiry/flash-messages)\n![PHP](https://img.shields.io/badge/PHP-%5E7.4-blue)\n![License](https://img.shields.io/github/license/nassiry/flash-messages)\n\n\u003c/div\u003e\n\nA lightweight PHP library for handling flash messages with **session storage** \u0026 simple **HTML** rendering. This package does not depend on any framework, but it can be integrated with frameworks like **Laravel**, **Symfony**, **CakePHP**, and **CodeIgniter** if needed.\n\n### Features\n- Session-based flash message storage.\n- Instant message rendering.\n- Custom message types.\n- Fully framework-agnostic.\n\n## Table Of Contents\n1. [Installation](#installation)\n2. [Usage](#usage)\n    - [Default Usage (Display on Next Page Load)](#1-default-usage-display-on-next-page-load)\n    - [Current Page Usage (Display Immediately)](#2-current-page-usage-display-immediately)\n    - [Checking for Messages](#3-checking-for-messages)\n    - [Retrieving Messages](#4-retrieving-messages)\n    - [Rendering Messages](#5-rendering-messages)\n    - [Clearing Messages](#6-clearing-messages)\n3. [Adding Different Types of Messages](#adding-different-types-of-messages)\n    - [Adding a custom type message](#adding-a-custom-type-message)\n4. [Adding a custom type message](#custom-rendering-logic)\n5. [Testing](#testing)\n    - [Prerequisites](#1-prerequisites)\n    - [Running Tests](#2-running-tests)\n6. [License](#license)\n7. [Contributing](#contributing)\n\n## Installation\n\nThe recommended way use Composer to install the package:\n\n```\ncomposer require nassiry/flash-messages\n```\n\n## Usage\n\nBy default, the package stores messages in sessions to be displayed on the next page load.\n### 1. Default Usage (Display on Next Page Load)\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Nassiry\\FlashMessages\\FlashMessages;\n\n// Create an instance\n$flash = FlashMessages::create();\n\n// Add flash messages to be displayed on the next page load\n$flash-\u003esuccess('Operation successful!');\n$flash-\u003eerror('An error occurred.');\n\n// Render messages on the next page template file\n$flash-\u003erender();\n```\n\u003e **Note**: Ensure that `session_start();` has been called in your script before using.\n### 2. Current Page Usage (Display Immediately)\n\nTo display a message on the current page, set the second argument to `true` (default is `false`):\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Nassiry\\FlashMessages\\FlashMessages;\n\n// Create an instance\n$flash = FlashMessages::create();\n\n// Add flash messages to be displayed immediately\n$flash-\u003eerror('An error occurred.', true);\n\n// Render messages instantly in the same page\n$flash-\u003erender();\n```\n\n### 3. Checking for Messages\n\nYou can check if there are any stored messages:\n\n```php\n// Check if ANY messages exist\nif ($flash-\u003ehasMessages()) {\n    echo \"There are flash messages available.\";\n}\n\n// Check if SPECIFIC TYPE messages exist\nif ($flash-\u003ehasMessages('info')) {\n    echo \"There are info messages available.\";\n}\n```\n\n### 4. Retrieving Messages\n\nYou can retrieve all stored messages as an array:\n\n```php\n// Get ALL messages\n$allMessages = $flash-\u003egetMessages();\nforeach ($allMessages as $message) {\n    echo $message['type'] . ': ' . $message['message'] . \"\u003cbr\u003e\";\n}\n\n// Get messages of SPECIFIC TYPE\n$infoMessages = $flash-\u003egetMessages('info');\nif (!empty($infoMessages)) {\n    foreach ($infoMessages as $message) {\n        echo 'Info: ' . $message['message'] . \"\u003cbr\u003e\";\n    }\n} else {\n    echo \"No info messages found.\";\n}\n```\n\n### 5. Rendering Messages\nOutputs all flash messages with default HTML structure\n\n```php\n$flash-\u003erender();\n```\n```html\n\u003cdiv class=\"flash flash-success\"\u003eOperation successful!\u003c/div\u003e\n\u003cdiv class=\"flash flash-error\"\u003eAn error occurred!\u003c/div\u003e\n```\n\n### 6. Clearing Messages\n\nTo clear all stored messages:\n\n```php\n$flash-\u003eclear();\n```\n\n### Adding Different Types of Messages\nCurrently, the package support following message types.\n - `$flash-\u003esuccess('Success message!');`\n - `$flash-\u003eerror('Error message!');`\n - `$flash-\u003einfo('Informational message!');`\n - `$flash-\u003ewarning('Warning message!');`\n#### Adding a custom type message\n - `addCustomType(string $type, string $message, bool $instant = false)`\n```php\n$flash-\u003eaddCustomType('notification',\n 'This is a custom notification message!',\n  true\n );\n$flash-\u003eaddCustomType('alert',\n 'This is an alert message!',\n  false\n);\n```\n\n### Custom Rendering Logic\n\nIf you need to customize the way messages are displayed, extend the `FlashMessageRenderer` class:\n\n```php\nuse Nassiry\\FlashMessages\\FlashMessageRenderer;\n\nclass CustomRenderer extends FlashMessageRenderer\n{\n    public function renderMessage(string $type, string $message): void\n    {\n        echo sprintf('\u003cdiv class=\"custom-%s\"\u003e%s\u003c/div\u003e', htmlspecialchars($type), htmlspecialchars($message));\n    }\n}\n\n$renderer = new CustomRenderer();\n$flash = new FlashMessages(new FlashMessageStorage(), $renderer);\n$flash-\u003esuccess('Custom rendered message!');\n$flash-\u003erender();\n```\n\n### Testing\n\nRun the unit tests to ensure the package works as expected:\n#### 1. Prerequisites\nEnsure you have all dependencies installed by running:\n```\ncomposer install\n```\n#### 2. Running Tests\nExecute the following command to run the test suite:\n\n```\ncomposer test\n```\n\n### License\n\nThis package is open-source software licensed under the [MIT license](LICENSE).\n\n### Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request or open an issue.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnassiry%2Fflash-messages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnassiry%2Fflash-messages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnassiry%2Fflash-messages/lists"}