link(Container::class), // Routing 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; }), // Badge generator Poser::class => object() ->constructor(link(SvgRender::class)), // Twig 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 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; }), // GitHub API Client::class => factory(function (ContainerInterface $c) { $cacheDirectory = $c->get('directory.cache') . '/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; }), ];