mirror of
https://github.com/danog/dns.git
synced 2024-11-27 04:24:48 +01:00
a30ead4952
I am anal. I am also sorry. Deal with it.
91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
use Auryn\Provider;
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
$autoloader = require __DIR__.'/../vendor/autoload.php';
|
|
|
|
$autoloader->add('AddrTest', [realpath(__DIR__)."/"]);
|
|
|
|
|
|
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);
|
|
}
|
|
}
|