arnapou / psr-container
Library - PSR-11.
v1.0.2
2024-09-24 21:21 UTC
Requires
- php: ~8.2.0 || ~8.3.0
- psr/container: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.52
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/php-code-coverage: ^11.0
- phpunit/phpunit: ^11.0
Provides
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.3 | 8.2 |
---|---|---|---|
09/09/2024 | 1.0.x, main | × | × |