// 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"); $app->config("templates.helpers_path", ROOT_DIR . '/app/helpers'); $app->config("view", new Hook\Framework\View()); // bind application routes require ROOT_DIR . 'config/routes.php'; $app->run();