예제 #1
0
파일: di.php 프로젝트: bigwhoop/trumpet
    $hbs->addHelper('count', function (HbsTemplate $template, HbsContext $context, $args, $source) {
        return count($context->get($args));
    });
    $hbs->addHelper('join', function (HbsTemplate $template, HbsContext $context, $args, $source) {
        $matches = [];
        if (preg_match("#'([^']+)' (.+)#", $args, $matches)) {
            list(, $separator, $input) = $matches;
            $out = [];
            foreach ((array) $context->get($input) as $value) {
                $context->push($value);
                $out[] = $template->render($context);
                $context->pop();
            }
            return implode($separator, $out);
        }
        return '';
    });
    return $hbs;
}), 'Bigwhoop\\Trumpet\\Commands\\CommandExecutionContext' => DI\object(), 'Bigwhoop\\Trumpet\\Commands\\CommandHandler' => DI\factory(function (DIC $c) {
    $handler = new CommandHandler();
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\CodeCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\ExecCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\IncludeCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\ImageCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\WikiCommand'));
    return $handler;
}), 'PhpParser\\PrettyPrinterAbstract' => DI\object('\\PhpParser\\PrettyPrinter\\Standard'), 'PhpParser\\Lexer' => DI\object('PhpParser\\Lexer\\Emulative'), 'PhpParser\\ParserAbstract' => DI\object('PhpParser\\Parser')->constructor(DI\link('PhpParser\\Lexer')), 'PhpParser\\NodeTraverserInterface' => DI\object('PhpParser\\NodeTraverser')->method('addVisitor', DI\link('PhpParser\\NodeVisitor\\NameResolver'))];
$builder = new DI\ContainerBuilder();
$builder->addDefinitions(new DI\Definition\Source\ArrayDefinitionSource($definitions));
//$builder->useAnnotations(false);
return $builder->build();
예제 #2
0
<?php

use Maintained\Application\Command\ClearCacheCommand;
use Maintained\Application\Command\ShowStatisticsCommand;
use Maintained\Application\Command\UpdateStatisticsCommand;
use Maintained\Application\Command\WarmupCacheCommand;
use Maintained\Statistics\CachedStatisticsProvider;
use Maintained\Statistics\StatisticsComputer;
use Maintained\Statistics\StatisticsProvider;
use Maintained\Statistics\StatisticsProviderLogger;
use function DI\factory;
use function DI\link;
use function DI\object;
return ['baseUrl' => 'http://isitmaintained.com', 'maintenance' => false, 'directory.cache' => __DIR__ . '/../../app/cache', 'directory.data' => __DIR__ . '/../../app/data', 'directory.logs' => __DIR__ . '/../../app/logs', 'routes' => require __DIR__ . '/routes.php', 'piwik.enabled' => false, 'piwik.host' => null, 'piwik.site_id' => null, 'github.auth_token' => null, StatisticsProvider::class => link(CachedStatisticsProvider::class), CachedStatisticsProvider::class => object()->constructorParameter('cache', link('storage.statistics'))->constructorParameter('wrapped', link(StatisticsProviderLogger::class)), StatisticsProviderLogger::class => object()->constructorParameter('wrapped', link(StatisticsComputer::class))->constructorParameter('repositoryStorage', link('storage.repositories')), ClearCacheCommand::class => object()->constructorParameter('cacheDirectory', link('directory.cache'))->constructorParameter('dataDirectory', link('directory.data')), ShowStatisticsCommand::class => object(), WarmupCacheCommand::class => object()->constructorParameter('repositoryStorage', link('storage.repositories')), UpdateStatisticsCommand::class => object()->constructorParameter('repositoryStorage', link('storage.repositories'))->constructorParameter('statisticsCache', link('storage.statistics'))];
예제 #3
0
    foreach ($routes as $routeName => $route) {
        $router->add($routeName, $route['pattern'])->addValues(['controller' => $route['controller']]);
    }
    return $router;
}), LoggerInterface::class => factory(function (ContainerInterface $c) {
    $logger = new Logger('main');
    $file = $c->get('directory.logs') . '/app.log';
    $logger->pushHandler(new StreamHandler($file, Logger::WARNING));
    return $logger;
}), Poser::class => object()->constructor(link(SvgFlatRender::class)), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    $twig->addExtension($c->get(PiwikTwigExtension::class));
    return $twig;
}), PiwikTwigExtension::class => object()->constructor(link('piwik.host'), link('piwik.site_id'), link('piwik.enabled')), Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('directory.cache') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'storage.repositories' => factory(function (ContainerInterface $c) {
    $backend = new StorageWithTransformers(new FileStorage($c->get('directory.data') . '/repositories.json'));
    $backend->addTransformer(new JsonEncoder(true));
    $storage = new MapWithTransformers(new MapAdapter($backend));
    $storage->addTransformer(new ObjectArrayMapper(Repository::class));
    return $storage;
}), 'storage.statistics' => factory(function (ContainerInterface $c) {
    $storage = new MapWithTransformers(new MultipleFileStorage($c->get('directory.data') . '/statistics'));
    $storage->addTransformer(new PhpSerializeEncoder());
    return $storage;
}), Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('directory.cache') . '/github';
예제 #4
0
use function DI\link;
use function DI\object;
return [ContainerInterface::class => link(Container::class), 'baseUrl' => 'http://isitmaintained.com', 'routes' => require __DIR__ . '/routes.php', Router::class => factory(function (ContainerInterface $c) {
    $router = (new RouterFactory())->newInstance();
    // Add the routes from the array config (Aura router doesn't seem to accept routes as array)
    $routes = $c->get('routes');
    foreach ($routes as $routeName => $route) {
        $router->add($routeName, $route['pattern'])->addValues(['controller' => $route['controller']]);
    }
    return $router;
}), Poser::class => factory(function () {
    return new Poser([new SvgRender()]);
}), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    return $twig;
}), 'cache.directory' => __DIR__ . '/../../app/cache', Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('cache.directory') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'github.auth_token' => null, Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('cache.directory') . '/github';
    $client = new Client(new CachedHttpClient(['cache_dir' => $cacheDirectory]));
    $authToken = $c->get('github.auth_token');
    if ($authToken) {
        $client->authenticate($authToken, null, Client::AUTH_HTTP_TOKEN);
    }
    return $client;
}), StatisticsProvider::class => object(CachedStatisticsProvider::class)->constructorParameter('wrapped', link(StatisticsComputer::class)), ClearCacheCommand::class => object()->lazy()->constructorParameter('cacheDirectory', link('cache.directory'))];