bootstrap: more logging
[pharext/pharext.org] / app / bootstrap / github.php
index 55a49a7298034c614976be6340a4df296d7f0f6c..2f1bbaade700144a7e83a6f361a1ca883833a535 100644 (file)
@@ -3,15 +3,35 @@
 namespace app;
 
 require_once __DIR__."/config.php";
+require_once __DIR__."/uri_template.php";
+require_once __DIR__."/session.php";
 
-use merry\Config;
+use http\Url;
 
 $injector->share(Github\API::class)
        ->delegate(Github\API::class, function() use($injector) {
+               $config = $injector->make(Config::class);
+               if (isset($config->github->hook->use_basic_auth)) {
+                       $basic = $config->github->hook->use_basic_auth;
+                       $config->github->hook->url = (string) new Url(
+                               $config->github->hook->url,
+                               $config->$basic->auth->toArray(),
+                               0);
+               }
+               $logger = new Logger($config, $config->github->log);
+
+               // FIXME: configure through app.ini
+               try {
+                       $cache = new Github\Storage\Redis("gh-cache");
+               } catch (\Exception $ex) {
+                       /* Memcached won't throw an exception */
+                       $cache = new Github\Storage\Memcache("gh-cache");
+               }
                return new Github\API(
-                       $injector->make(Config::class)->github
-                  ,new Github\Storage\Session("gh-tokens")
-                  #,new Github\Storage\Memcache("gh-cache")
+                        $config->github
+                       ,$logger
+                       ,new Github\Storage\Session("gh-tokens")
+                       ,$cache
           );
        });