someniatko / whitelist-container
A PSR-11 container, wrapping existing container, but restricting access only to selected list of classes
Installs: 273
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/someniatko/whitelist-container
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: 2025-09-22 02:11:06 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