1
0
mirror of https://github.com/danog/dns.git synced 2024-12-11 17:09:50 +01:00
dns/test/bootstrap.php
2014-09-24 13:35:10 -04:00

84 lines
2.3 KiB
PHP

<?php
use Auryn\Provider;
error_reporting(E_ALL);
function createProvider($implementations = [], $shareClasses = []) {
$provider = new Provider();
$standardImplementations = [
];
$standardShares = [
];
$redisParameters = [
'connection_timeout' => 2,
'read_write_timeout' => 2,
];
$provider->define(
'Predis\Client',
[
':parameters' => $redisParameters,
':options' => [],
]
);
$provider->share('Predis\Client');
setImplementations($provider, $standardImplementations, $implementations);
setShares($provider, $standardShares, $shareClasses);
$provider->share($provider); //YOLO
return $provider;
}
function setImplementations(Provider $provider, $standardImplementations, $implementations) {
foreach ($standardImplementations as $interface => $implementation) {
if (array_key_exists($interface, $implementations)) {
if (is_object($implementations[$interface]) == true) {
$provider->alias($interface, get_class($implementations[$interface]));
$provider->share($implementations[$interface]);
}
else {
$provider->alias($interface, $implementations[$interface]);
}
unset($implementations[$interface]);
}
else {
if (is_object($implementation)) {
$implementation = get_class($implementation);
}
$provider->alias($interface, $implementation);
}
}
foreach ($implementations as $class => $implementation) {
if (is_object($implementation) == true) {
$provider->alias($class, get_class($implementation));
$provider->share($implementation);
}
else {
$provider->alias($class, $implementation);
}
}
}
function setShares(Provider $provider, $standardShares, $shareClasses) {
foreach ($standardShares as $class => $share) {
if (array_key_exists($class, $shareClasses)) {
$provider->share($shareClasses[$class]);
unset($shareClasses[$class]);
}
else {
$provider->share($share);
}
}
foreach ($shareClasses as $class => $share) {
$provider->share($share);
}
}