You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**PHPStan Compliant Developer Comments**: Added detailed PHPStan-compliant comments to improve code readability and maintainability.
6
-
-**`collection()` Method**: Introduced a new method to centralize response data collection, reducing redundancy in `json()` and `array()`.
7
-
-**Static Response Key Names**: Defined `$result_key_text`, `$error_key_text`, and `$input_key_text` as static class properties for better maintainability.
3
+
This is the official changelog for the `uxmansarwar/response` Composer package.
4
+
This PHP package helps developers return structured API responses in a simple, clean, and fluent way.
5
+
Maintained by [Uxman Sarwar](https://github.com/uxmansarwar) β a professional full-stack PHP developer since 2013.
8
6
9
-
### Changed
10
-
-**Singleton Handling**: Improved `singleton()` method for better reusability instead of initializing in multiple places.
11
-
-**Constructor Reset Behavior**: Adjusted constructor logic to ensure that each instantiation resets response states correctly.
12
-
-**JSON Parsing Validation**: Enhanced JSON request body parsing by verifying `json_last_error()`.
13
-
-**Better Result & Error Storage**: Updated result and error storage to always ensure correct structuring when using keys.
7
+
> Install via Composer:
8
+
> `composer require uxmansarwar/response`
14
9
15
-
### Fixed
16
-
-**Incorrect Singleton Reinitialization**: Ensured `singleton()` and `init()` methods correctly maintain a single instance.
17
-
-**Input Handling Edge Cases**: Addressed cases where JSON input merging could fail under certain request formats.
18
-
-**Return Consistency**: Standardized method return values to always return `self` where applicable for method chaining.
10
+
---
11
+
12
+
## π Version 4.0.0 β Major Rewrite & Powerful Improvements (May 2025)
13
+
14
+
This version is a **major upgrade** from `v3.x` to `v4.0.0`.
15
+
It is a complete rewrite with **new features**, **cleaner code**, and **more flexibility** for real-world APIs and production apps.
16
+
17
+
### β What's New
18
+
19
+
- π **Total Refactor to Singleton-based Fluent Class**
20
+
- Keeps only one instance in memory. Cleaner, faster, and easier to use.
21
+
22
+
- ποΈ **New `index()` Method**
23
+
- Add secondary keys under each primary `key()`. Useful for nesting grouped data.
24
+
25
+
- π§ **New `ttl()` Support**
26
+
- You can now attach a **TTL (time to live)** value in the response. Useful for cache-aware APIs or auto-expiring resources.
27
+
28
+
- π **New `query()` Method**
29
+
- Attach queries(Like what this response about), filter info, or any debug context directly to the response.
`Response` is a **lightweight PHP library** designed to streamline **API response handling**. It follows a **singleton-based pattern** to store and retrieve results, errors, and user input efficiently. The package is **PSR-4 compliant** and fully compatible with **PHP 7.2+ and PHP 8.2**.
10
+
**`uxmansarwar/response`** is a powerful yet lightweight PHP package that makes it easy to manage structured API responses. Built with modern PHP practices, it follows a clean singleton pattern and supports result grouping, TTL, debug queries, and more. Ideal for Laravel, Symfony, WordPress, CodeIgniter, or raw PHP projects.
10
11
11
-
### **Key Features**
12
-
- β **Singleton pattern** to prevent redundant object creation.
13
-
- β **Structured response handling** for JSON and array outputs.
14
-
- β **Collect API results & errors dynamically**.
15
-
- β **Retrieve user input** from `$_GET`, `$_POST`, and JSON payloads.
16
-
- β **Flexible data retrieval** (JSON, array, collection format).
17
-
- β **Works with Laravel, Symfony, CodeIgniter, WordPress, and Core PHP**.
12
+
Developed and maintained by [Uxman Sarwar](https://github.com/uxmansarwar), a senior PHP developer since 2013.
13
+
14
+
## β Features
15
+
16
+
- Singleton-based fluent API
17
+
- Add results, errors, queries, TTL, and input metadata
18
+
- Auto-collects `$_GET`, `$_POST`, and raw JSON input
19
+
- Customizable result/error key groups with `key()` and `index()`
20
+
- Get structured responses as JSON or array
21
+
- Great for APIs, microservices, and AJAX handlers
18
22
19
23
---
20
24
21
-
## Installation
25
+
## βοΈ Installation
22
26
23
-
### **Install via Composer**
24
-
You can install this package using Composer:
25
-
```sh
26
-
composer require uxmansarwar/response
27
-
```
27
+
### Via Composer
28
28
29
-
### **Manual Installation**
30
-
Alternatively, clone this repository and include it in your project:
0 commit comments