some-niatko /whitelist-container
一个PSR-11容器,封装现有容器,但仅允许访问所选类列表
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-09-21 23:53:09 UTC
README
一个PSR-11容器,封装现有容器,但仅允许访问所选类列表。
安装
此库需要PHP 7.4或8.0。您可以通过Composer安装它
composer install someniatko/whitelist-container
用法
<?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