Download the PHP package vaibhavpandeyvpz/phlash without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/phlash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/phlash
More information about vaibhavpandeyvpz/phlash
Files in vaibhavpandeyvpz/phlash
Package phlash
Short Description Package for flashing data now or later (in next request) for use in any micro/full-stack framework.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/phlash
Informations about the package phlash
Phlash
A lightweight PHP library for managing flash messages that can be made available either immediately (in the current request) or in the next request. Perfect for use with any micro or full-stack framework.
Features
- Simple API: Easy-to-use interface for flashing messages
- Two Flash Types: Flash messages for current request or next request
- Framework Agnostic: Works with any PHP framework or vanilla PHP
- Type Safe: Built with PHP 8.2+ features including strict types, enums, and type hints
- Flexible Storage: Uses
$_SESSIONby default, but accepts custom storage arrays - Zero Dependencies: No external dependencies required
- Fully Tested: 100% code coverage with comprehensive test suite
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
Quick Start
Usage
Basic Usage
Flash Messages for Current Request
Messages flashed with flashNow() are immediately available in the same request:
Flash Messages for Next Request
Messages flashed with flashLater() are not available in the current request, but will be available when a new instance is created (simulating the next request):
Retrieving Messages
Get All Messages
Get Specific Message
Custom Storage
By default, ArrayFlash uses $_SESSION for storage. You can provide a custom array for storage:
Common Use Cases
Form Validation Errors
Success Messages
Mixed Messages
Data Types
Phlash supports any data type for flash messages:
API Reference
ArrayFlash
The main implementation class for flash message storage.
Constructor
- Parameters:
$storage(array|null): Optional array reference for storage. Ifnull, uses$_SESSION.
- Behavior: On construction, messages from the "later" bag (previous request) are moved to "now" bag, and "later" is cleared.
Methods
flashNow(string $key, mixed $message): void
Flash a message to be available in the current request.
- Parameters:
$key(string): The key to store the message under$message(mixed): The message data (any type)
- Returns:
void
flashLater(string $key, mixed $message): void
Flash a message to be available in the next request.
- Parameters:
$key(string): The key to store the message under$message(mixed): The message data (any type)
- Returns:
void
get(?string $key = null): mixed
Retrieve flashed messages.
- Parameters:
$key(string|null): Optional key to retrieve a specific message. Ifnull, returns all messages.
- Returns:
array<string, mixed>when$keyisnull(all messages)mixedwhen$keyis provided and exists (the message value)nullwhen$keyis provided but doesn't exist
Architecture
Phlash uses a simple but effective architecture:
- FlashInterface: Defines the contract for flash implementations
- FlashAbstract: Base class providing common functionality
- ArrayFlash: Concrete implementation using array storage
- FlashBag: Enum defining the two flash types (NOW and LATER)
The library uses a "bag" system where messages are stored in either the "now" bag (current request) or "later" bag (next request). When a new ArrayFlash instance is created, messages from "later" are automatically moved to "now", simulating the transition between requests.
Testing
The library includes a comprehensive test suite with 100% code coverage:
License
This project is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Vaibhav Pandey
- Email: [email protected]
- GitHub: @vaibhavpandeyvpz