From: Michael Wallner Date: Fri, 16 Dec 2016 09:13:44 +0000 (+0100) Subject: bootstrap: more logging X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a695aed9c383974a31116c4d4d4a949bd5bd6803;p=pharext%2Fpharext.org bootstrap: more logging --- diff --git a/app/bootstrap/github.php b/app/bootstrap/github.php index e03cba0..2f1bbaa 100644 --- a/app/bootstrap/github.php +++ b/app/bootstrap/github.php @@ -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"); diff --git a/app/bootstrap/model.php b/app/bootstrap/model.php index f9f729b..30554c8 100644 --- a/app/bootstrap/model.php +++ b/app/bootstrap/model.php @@ -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 -//]); diff --git a/app/bootstrap/session.php b/app/bootstrap/session.php index 55e6b2a..af1d5c2 100644 --- a/app/bootstrap/session.php +++ b/app/bootstrap/session.php @@ -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(); + });