namespace app;
require_once __DIR__."/config.php";
+require_once __DIR__."/uri_template.php";
+require_once __DIR__."/session.php";
use http\Url;
$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");
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
-//]);
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();
+
});