承接 uxmansarwar/response 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uxmansarwar/response

最新稳定版本:v4.0.0

Composer 安装命令:

composer require uxmansarwar/response

包简介

Elegant and lightweight PHP Composer Package for standardized API responses with error, ttl, query and result handling. Package developed by UxmanSarwar a Senior PHP Developer since 2013

README 文档

README

Packagist PHP Version License GitHub Stars

🔍 Overview

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.

Developed and maintained by Uxman Sarwar, a senior PHP developer since 2013.

✅ Features

  • Singleton-based fluent API
  • Add results, errors, queries, TTL, and input metadata
  • Auto-collects $_GET, $_POST, and raw JSON input
  • Customizable result/error key groups with key() and index()
  • Get structured responses as JSON or array
  • Great for APIs, microservices, and AJAX handlers

⚙️ Installation

Via Composer

composer require uxmansarwar/response

🚀 Quick Start

Initialize

use UxmanSarwar\Response;

Response::init();

Add Result

Response::result(['id' => 1, 'name' => 'Alice']);

Add Error

Response::error('Invalid request type');

Grouped Result with Key/Index

Response::key('user')->index('info')->result(['email' => 'user@example.com']);

Set Time-To-Live (TTL)

Response::ttl(60);

Attach Debug Query

Response::query('SELECT * FROM users WHERE id = 1');

Include Input Data

Response::input(true);

Output as JSON

echo Response::json();

Output as Array

print_r(Response::array());

💡 Example Use Case: API Endpoint

Response::init();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    Response::error("Only POST requests are allowed");
} else {
    $data = Response::$_INPUT;
    if (empty($data['username'])) {
        Response::error("Username is required");
    } else {
        Response::result("User registered successfully");
    }
}

echo Response::json();

🧪 Testing

composer install
vendor/bin/phpstan analyse src --level=max
vendor/bin/pest

🌐 Use Cases

  • Laravel: Replace default response()->json() with a fluent helper
  • WordPress: Handle AJAX with structured output
  • Symfony: Wrap controller responses with grouped structure
  • REST APIs: Make consistent error/result formatting
  • Microservices: Inject debug info and TTL for downstream caching

👨‍💻 About the Author

This package is created by Uxman Sarwar, a full-stack PHP Laravel developer.

If you found this package useful, consider ⭐ starring the repo and sharing it with other developers.

🔗 SEO & GitHub Keywords

PHP API response library, structured API output PHP, response formatter, Laravel response helper, singleton response PHP, uxmansarwar response composer, REST API output PHP, error handler class PHP, api response json PHP, PHP response class Laravel

📥 Composer Install Reminder

composer require uxmansarwar/response

Happy coding! 🚀

统计信息

  • 总下载量: 154
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固