arnapou/psr-container
最新稳定版本:v1.2.0
Composer 安装命令:
composer require arnapou/psr-container
包简介
Library - PSR-11.
README 文档
README
KISS (Keep It Simple Stupid) PSR (PHP Standards Recommendations) classes.
Installation
composer require arnapou/psr-container
packagist 👉️ arnapou/psr-container
When it is worth to use this library
- you need simple decorators, proxies, adapters, ... about PSR's
- you need simple implementations covering the basics
Example PSR-11 Container
Service Locator
$container = new \Arnapou\Psr\Psr11Container\ServiceLocator();
$container->registerFactory(
'db',
static function() {
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
}
);
$container->get('db')->query('SELECT ....');
Static Services
/**
* @method static \PDO db()
*/
class Services extends \Arnapou\Psr\Psr11Container\StaticServices
{
public function getFactories(): iterable
{
yield 'db' => static function() {
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
};
}
}
Services::db()->query('SELECT ....');
Php versions
| Date | Ref | 8.5 | 8.4 | 8.3 | 8.2 |
|---|---|---|---|---|---|
| 25/10/2025 | 1.2.x, main | × | × | × | |
| 24/11/2024 | 1.1.x | × | × | × | |
| 09/09/2024 | 1.0.x | × | × |
统计信息
- 总下载量: 524
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-09