someniatko / whitelist-container
A PSR-11 container, wrapping existing container, but restricting access only to selected list of classes
1.0.0
2021-04-21 15:53 UTC
Requires
- php: ~7.4 || ~8.0
- psr/container: ^1.0 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- phpwatch/simple-container: ^2.0
- psalm/phar: ^4.7
This package is auto-updated.
Last update: 2024-12-22 00:29:29 UTC
README
A PSR-11 container, wrapping existing container, but restricting access only to selected list of classes.
Installation
This library requires PHP 7.4 or 8.0. You can install it via Composer:
composer install someniatko/whitelist-container
Usage
<?php class Allowed {} class Prohibited {} use Someniatko\WhitelistContainer\WhitelistContainer; /** @var \Psr\Container\ContainerInterface $innerContainer */ $whitelistContainer = new WhitelistContainer( $innerContainer, [ Allowed::class ], 'my-container-name', // optional, used only for exception message ); $whitelistContainer->has(Allowed::class); // true $whitelistContainer->has(Prohibited::class); // false $whitelistContainer->get(Allowed::class); // Allowed instance $whitelistContainer->get(Prohibited::class); // @throws NotFoundExceptionInterface