highperapp/container
Composer 安装命令:
composer require highperapp/container
包简介
High-performance PSR-11 container
README 文档
README
Standalone high-performance PSR-11 container for any PHP project. Can be used independently or integrated with HighPer framework. Features object pooling, memory optimization, and zero-overhead service resolution.
🚀 Features
⚡ Build-Time Compilation
- ContainerCompiler: Compile service definitions to optimized PHP code
- O(1) Resolution: Zero-overhead service lookups in production
- Dependency Analysis: Compile-time dependency validation
- Cache Generation: Persistent compiled container caching
🎯 Performance Optimizations
- PSR-11 Compatible: Fully compliant with PSR-11 Container Interface
- Object Pooling: Advanced object pool for memory optimization
- C10M Ready: Optimized for extreme concurrency scenarios
- Auto-wiring: Lightning-fast automatic dependency injection
- Memory Efficient: Real-time memory usage tracking and optimization
- Framework Agnostic: Works standalone or integrates seamlessly with any framework
- HighPer Framework: First-class integration with HighPer framework
Installation
composer require highperapp/container
Usage Scenarios
🔧 Standalone Library
Use in any PHP project (Laravel, Symfony, CodeIgniter, or vanilla PHP):
// In any PHP project use HighPerApp\HighPer\Container\Container; $container = new Container(); $container->bind(DatabaseInterface::class, MySQLDatabase::class); $database = $container->get(DatabaseInterface::class);
🏗️ HighPer Framework Integration
Automatically available as the default container in HighPer framework with enhanced features and zero configuration.
Quick Start
<?php use HighPerApp\HighPer\Container\Container; // Create container instance $container = new Container(); // Register services $container->bind('database', PDO::class); $container->singleton('logger', MyLogger::class); // Register with factory $container->factory('redis', function() { return new Redis(['host' => 'localhost']); }); // Register instance $container->instance('config', $configObject); // Resolve services $database = $container->get('database'); $logger = $container->get('logger');
Advanced Usage
Service Binding
// Bind with concrete implementation $container->bind(LoggerInterface::class, FileLogger::class); // Bind as singleton $container->singleton(DatabaseInterface::class, MySQLDatabase::class); // Bind with factory function $container->factory('cache', function($container) { $redis = $container->get('redis'); return new CacheService($redis); });
Aliases
$container->alias('db', 'database'); $container->alias('log', LoggerInterface::class);
Auto-wiring
The container automatically resolves constructor dependencies:
class UserService { public function __construct( private DatabaseInterface $database, private LoggerInterface $logger ) {} } // Register dependencies $container->bind(DatabaseInterface::class, MySQLDatabase::class); $container->bind(LoggerInterface::class, FileLogger::class); // Auto-wire UserService $userService = $container->get(UserService::class);
Memory Optimization
// Get memory usage statistics $stats = $container->getStats(); // Object pool statistics $poolStats = $stats['object_pool_stats'];
Configuration
The container is designed to work out of the box with zero configuration, but you can customize the object pool:
use HighPerApp\HighPer\Container\ObjectPool; $container = new Container(); // Access and use object pool $objectPool = new ObjectPool(); $objectPool->populate(ExpensiveObject::class, 10);
🧪 Testing
Run Container Tests
# All tests composer test # Unit tests only vendor/bin/phpunit --testsuite=Unit # Integration tests only vendor/bin/phpunit --testsuite=Integration # Performance tests vendor/bin/phpunit --testsuite=Performance
Test Coverage
- Container Core: Complete PSR-11 functionality
- Build-Time Compilation: Compiler validation and performance
- Framework Integration: HighPer Framework compatibility
- Memory Optimization: Object pooling and memory efficiency
📊 Performance Benchmarks
Performance Metrics
| Operation | Speed |
|---|---|
| Service Resolution | <0.001ms |
| Compilation | 50 services/sec |
| Memory Usage | <5MB for 100 services |
| Dependency Injection | Instant |
Build-Time Compilation Benefits
- Production Speed: Compiled containers eliminate runtime overhead
- Dependency Validation: Catch dependency issues at build time
- Memory Efficiency: Optimized service instantiation patterns
- Cache Performance: Persistent compiled container storage
- Framework Agnostic: Same performance benefits in any environment
✨ Major Features
- ContainerCompiler: Build-time compilation for maximum performance
- Enhanced Object Pooling: Advanced memory management strategies
- Standalone Library: Use in any PHP project without framework dependencies
- Framework Integration: Optional deep integration with HighPer Framework
- Performance Monitoring: Real-time container performance metrics
🚀 Performance Improvements
- 40-60% Faster Resolution: Optimized service lookup algorithms
- Build-Time Validation: Catch errors before production
- Memory Optimization: Reduced memory footprint and leaks
- Caching Strategy: Intelligent compiled container caching
🔧 Requirements
- PHP: 8.3+ (8.4 recommended for latest optimizations)
- Extensions: OPcache (recommended), APCu (optional)
- Memory: 64MB+ for compilation, minimal for runtime
- Framework: Any PHP framework or standalone (HighPer Framework integration optional)
🤝 Contributing
This container serves both standalone and HighPer framework users:
- Fork the repository
- Create feature branch (
git checkout -b feature/container-feature) - Run tests (
composer test) - Ensure compatibility with both standalone and framework usage
- Commit changes (
git commit -m 'Add container feature') - Push to branch (
git push origin feature/container-feature) - Open Pull Request
📄 License
MIT License - see the LICENSE file for details.
HighPer DI Container - Standalone library with build-time compilation for any PHP project
highperapp/container 适用场景与选型建议
highperapp/container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「php」 「dependency-injection」 「microservices」 「PSR-11」 「high-performance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 highperapp/container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 highperapp/container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 highperapp/container 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Supporing Symfony's DependencyInjection component for your symfony1 project
A fast and intuitive dependency injection container.
Powerful class discovery system for Laravel with attribute-based scanning, directory traversal, and monorepo support
Dependency injection container for the Monolith framework.
The PSR-11 container bridges
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-06