bootstrap: more logging
authorMichael Wallner <mike@php.net>
Fri, 16 Dec 2016 09:13:44 +0000 (10:13 +0100)
committerMichael Wallner <mike@php.net>
Fri, 20 Dec 2019 12:21:59 +0000 (13:21 +0100)
app/bootstrap/github.php
app/bootstrap/model.php
app/bootstrap/session.php

index e03cba099fd16717fe1c4b09911e2c5be263e1ae..2f1bbaade700144a7e83a6f361a1ca883833a535 100644 (file)
@@ -3,6 +3,8 @@
 namespace app;
 
 require_once __DIR__."/config.php";
+require_once __DIR__."/uri_template.php";
+require_once __DIR__."/session.php";
 
 use http\Url;
 
@@ -16,8 +18,8 @@ $injector->share(Github\API::class)
                                $config->$basic->auth->toArray(),
                                0);
                }
-               $logger = new Github\Logger($config);
-               
+               $logger = new Logger($config, $config->github->log);
+
                // FIXME: configure through app.ini
                try {
                        $cache = new Github\Storage\Redis("gh-cache");
index f9f729b6a5ae2a9cff158d5f9202f839a151440f..30554c8cb4def73d864b7fb6ddb3a5dc768dbbc9 100644 (file)
@@ -5,33 +5,36 @@ namespace app;
 require_once __DIR__."/config.php";
 require_once __DIR__."/pq.php";
 
-use pq\Connection;
+use Auryn\Injector;
+use pq\Query\Executor;
+use pq\Gateway\Table;
+use SplSubject, SplObserver;
+
+class QueryLogger extends Logger implements SplObserver
+{
+       function update(SplSubject $executor) {
+               if (($result = $executor->getResult())) {
+                       $query = $executor->getQuery();
+                       $this->debug($query, [
+                               "params" => $query->getParams(),
+                               "result" => $result
+                       ]);
+               }
+       }
+}
 
 /* @var $injector \Auryn\Injector */
 
-$injector->define(Model\Accounts::class, [
-               "conn" => Connection::class,
-       ])
-       ->define(Model\Tokens::class, [
-               "conn" => Connection::class,
-       ])
-       ->define(Model\Authorities::class, [
-               "conn" => Connection::class,
-       ])
-       ->define(Model\Owners::class, [
-               "conn" => Connection::class,
-       ]);
+$injector->prepare(Executor::class, function(Executor $executor, Injector $injector) {
+       $executor->attach(new QueryLogger($injector->make(Config::class), "query"));
+});
+
+foreach ([Model\Accounts::class, Model\Tokens::class, Model\Authorities::class, Model\Owners::class] as $class) {
+       $injector->prepare($class, function(Table $table, Injector $injector) {
+               $table->setQueryExecutor($injector->make(Executor::class));
+       });
+}
 
 \pq\Gateway\Table::$defaultResolver = function($table) use($injector) {
        return $injector->make("app\\Model\\" . ucfirst($table));
 };
-
-//$modelconf = function($key, $injector) {
-//     return new Table($key, $injector->make(Connection::class));
-//};
-//
-//$injector->define(Model\Account::class, [
-//     "+accounts" => $modelconf,
-//     "+owners" => $modelconf,
-//     "+tokens" => $modelconf
-//]);
index 55e6b2a34dbc8532a0f91e73932b9139a893d2e1..af1d5c2bf2fcd7b9f3a6f0a780374d4e2357f21a 100644 (file)
@@ -8,10 +8,16 @@ use Auryn\Injector;
 use http\Env\Request;
 
 $injector->share(Session::class)
+       ->define(Session::class, [
+               "+logger" => function($key, $injector) {
+                       return new Logger($injector->make(Config::class), "session");
+               }
+       ])
        ->prepare(Session::class, function(Session $session, Injector $injector) {
                if (isset($session->current) && (!isset($session->previous) || strcmp($session->current, $session->previous))) {
                        $session->previous = $session->current;
                        $session->current = $injector->make(Request::class)->getRequestUrl();
                }
                $session->current = $injector->make(Request::class)->getRequestUrl();
+
        });