PHP code example of someniatko / whitelist-container
1. Go to this page and download the library: Download someniatko/whitelist-container library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
someniatko / whitelist-container example snippets
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