$connection = \DLModel::getConnectionResolver()->connection(); $connection->setPaginator(new Hook\Framework\Environment()); // Set application key $app_key = null; $config_keys = ROOT_DIR . '/config/keys.php'; // auto-set app_id/key if (!$app->request->headers->get('X-App-Id')) { // Create default application if it doesn't exists if (Hook\Model\AppKey::count() == 0) { $application = Hook\Model\App::create(array('name' => "Application")); $hook_config = $application->keys[0]->toArray(); $hook_config['endpoint'] = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; file_put_contents($app->config('paths')['root'] . '.hook-config', json_encode($hook_config)); // Migrate application tables Hook\Application\Context::setKey($application->keys[0]); Hook\Application\Context::migrate(); Hook\Application\Context::setTablePrefix(''); } if ($app->request->isAjax()) { $app_key = Hook\Model\AppKey::where('type', Hook\Model\AppKey::TYPE_BROWSER)->first(); } else { $app_key = Hook\Model\AppKey::where('type', Hook\Model\AppKey::TYPE_SERVER)->first(); } $app->request->headers->set('X-App-Id', $app_key->app_id); $app->request->headers->set('X-App-Key', $app_key->key); } foreach ($app->config('aliases') as $alias => $source) { class_alias($source, $alias); } // configure view/template library (lightncandy) $app->config("templates.path", $app->config('paths')['root'] . "app/views");