lfvcodes/microbridge-php
Composer 安装命令:
composer require lfvcodes/microbridge-php
包简介
PHP's lightweight microservice communicator
README 文档
README
MicroBridge-PHP
PHP's lightweight microservices/API communicator
MicroBridge-PHP is a lightweight (less than 500 lines of code) PHP 7.1+ tool for issuing internal API requests without network overhead.
Features
- Lightweight: Less than 500 lines of code
- Zero Dependencies: No external dependencies required
- PHP 7.1+ Compatible: Works with modern PHP versions
- Multiple HTTP Methods: Supports GET, POST, PUT, PATCH, DELETE
- State Management: Preserves and restores PHP superglobals
- Error Handling: Comprehensive error handling and validation
- Stream Simulation: Mock php://input stream for request body handling
Requirements
- PHP 7.1 or higher
- Composer (recommended) or manual installation
Installation
Using Composer (Recommended)
Install by running:
composer require lfvcodes/microbridge-php
Manual Installation
If you're not using Composer, you can manually integrate MicroBridge into your project by following these steps:
1. Copy the Files
Download or clone the repository and copy the src/ folder into your project:
your-project/
├── src/
│ ├── MicroBridge.php
│ ├── RequestContext.php
│ └── MockPhpStream.php
└── your-code.php
2. Manually Include the Classes
In your main file (index.php or similar), include the class file and use the namespace:
<?php require_once 'src/MicroBridge.php'; require_once 'src/RequestContext.php'; require_once 'src/MockPhpStream.php'; use MicroBridge\MicroBridge; // Your code here... ?>
Usage
Basic POST Request
<?php require 'vendor/autoload.php'; use MicroBridge\MicroBridge; try { // Create client with POST method $client = new MicroBridge('POST'); // Make request with data payload $response = $client->request('./api/users.php', [ 'name' => 'John Doe', 'email' => 'john@example.com' ]); print_r($response); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?>
GET Request with URL Parameters
<?php require 'vendor/autoload.php'; use MicroBridge\MicroBridge; try { $client = new MicroBridge('GET'); // Method 1: URL with query string $response = $client->request('./api/users.php?id=4'); // Method 2: Separate parameters $response = $client->request('./api/users.php', ['id' => 4]); print_r($response); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?>
Advanced Usage with Headers
<?php require 'vendor/autoload.php'; use MicroBridge\MicroBridge; try { $client = new MicroBridge('PUT'); $response = $client->request('./api/users.php', ['id' => 1, 'name' => 'Updated Name'], ['Authorization' => 'Bearer token123'] ); print_r($response); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?>
Running Examples
The examples/ directory contains working demonstrations of MicroBridge functionality. These examples are fully runnable and show real-world usage patterns.
Available Examples
basic-usage.php- Demonstrates fundamental GET, POST, PUT requestschained-requests.php- Shows how to chain multiple API calls togethererror-handling.php- Illustrates comprehensive error handling scenarios
Running Examples via Command Line
Navigate to the project root directory and run any example:
# Run basic usage examples php examples/basic-usage.php # Run chained requests demonstration php examples/chained-requests.php # Run error handling examples php examples/error-handling.php
Running Examples via Web Server
If you have a local web server (Apache, Nginx, or PHP's built-in server) configured to serve PHP files:
# Start PHP's built-in development server php -S localhost:8000 # Then visit in your browser: # http://localhost:8000/examples/basic-usage.php # http://localhost:8000/examples/chained-requests.php # http://localhost:8000/examples/error-handling.php
Example Output
When running basic-usage.php, you should see clean HTML output demonstrating:
- Successful GET requests with chained API calls
- POST request handling with JSON payloads
- PUT requests with custom headers
- Proper error handling for invalid methods
All examples include the working API endpoints (api/api1.php and api/api2.php) that demonstrate real internal API communication without network overhead.
API Methods
| Method | Description | Use Case |
|---|---|---|
GET |
Retrieve data | Fetching resources |
POST |
Create new resource | Creating new records |
PUT |
Update entire resource | Full resource updates |
PATCH |
Partial update | Updating specific fields |
DELETE |
Remove resource | Deleting records |
Development
Running Tests
composer test
Code Style Checking
# Check code style composer cs-check # Fix code style issues composer cs-fix
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built for modern PHP microservice architectures
- Inspired by the need for lightweight internal API communication
- Designed with simplicity and performance in mind
lfvcodes/microbridge-php 适用场景与选型建议
lfvcodes/microbridge-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「library」 「encryption」 「secure」 「microservices」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lfvcodes/microbridge-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lfvcodes/microbridge-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lfvcodes/microbridge-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Inbox pattern process implementation for your Laravel Applications
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
Provides command to manage a web library directory
Alfabank REST API integration
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-13