/** * Create a new table object. * * @method __construct * * @param string $name The table name * @param string|null $alias An alias for use in queries * @param Instance|null $instance The instance the table belongs to */ public function __construct($name, $alias = null, Instance $instance = null) { $this->name = $name; if ($alias === null) { $alias = $name; } $this->alias = $alias; $instance = $instance ?: Database::instance('default'); $this->instance = $instance; $this->primaryKey = $this->instance->primaryKeyForTable($this); $this->fields = $this->instance->fieldsForTable($this); $this->relationships = $this->instance->relationshipsForTable($this); $instance::$tableCache[$name . '.' . $alias] = $this; }
/** * Create a new application instance. */ public function __construct() { // Store the instance statically static::$instance = $this; // Load the app's config $this->loadConfig(); // Register the error handler $this->registerErrorHandler(); // Create our request and response objects $this->request = new Request(); $this->response = new Response(); // Bootstrap the database Database::bootstrap($this->config->db->toArray()); // Convert relative store paths to absolute, and bootstrap the cache foreach ($this->config->cache as $instance => $config) { $cacheStorePath = $config->store_path; if ($cacheStorePath !== null) { if (!is_dir($cacheStorePath) && is_dir(APP_ROOT . $cacheStorePath)) { $this->config->cache->{$instance}->store_path = APP_ROOT . $cacheStorePath; } } } Cache::bootstrap($this->config->cache->toArray()); // Convert relative store paths to absolute, and bootstrap the session $sessionStorePath = $this->config->session->store_path; if ($sessionStorePath !== null) { if (!is_dir($sessionStorePath) && is_dir(APP_ROOT . $sessionStorePath)) { $this->config->session->store_path = APP_ROOT . $sessionStorePath; } } Session::bootstrap($this->config->session); // Include the app routes require APP_ROOT . 'routes.php'; // Register global view variables View::addGlobal('appName', $this->config->app->name); View::addGlobal('app', $this); View::addGlobal('input', $this->request->input); $this->compileAssets(); // Execute routes Router::execute(); if (PHP_SAPI !== 'cli') { $this->checkRoute(); } }
/** * Set a config value. * * @param string $path The path of the value to set * @param mixed $value The value to set * * @return mixed The value */ public static function set($key, $value = null) { return Database::config()->setValueForPath($key, $value); }
/** * Create a new query. * * @param Table|string $table The table to query * @param string|null $alias An alias to use * @param Instance|null $instance The instance to use */ public function __construct($table, $alias = null, Instance $instance = null) { // If a table name is passed, rather than an instance of Table, // then create the table object here if (!$table instanceof Table) { $table = Table::find($table, $alias); } $this->table = $table; $this->instance = $instance ?: Database::instance('default'); }