/** * @param string $node * @return array * @throws KernelException */ public function getNode(string $node) : array { if (!property_exists($this, $node) || !$this->{$node} instanceof PlainObject) { throw KernelException::badConfigNode(__METHOD__, $node); } return json_decode(json_encode($this->{$node}), true); }
/** * @param string|null $id * @return Database * @throws KernelException */ public function getDb(string $id = null) : Database { $this->isBootstrapped(__METHOD__); if (!isset($id)) { // No reference ID provided, fetch first database $db = reset($this->databases); $id = key($this->databases); if (!$db || empty($id)) { // No databases were defined throw KernelException::dbNotFound(""); } } else { if (!array_key_exists($id, $this->databases)) { // Database not found throw KernelException::dbNotFound($id); } $db = $this->databases[$id]; } // Check if database instance was created if (is_array($db)) { // Check for custom port if (!empty($db["port"])) { $db["host"] .= ":" . $db["port"]; } // SQLite Databases if ($db["driver"] === "sqlite") { // Prepend root path $db["name"] = $this->rootPath . self::DS . $db["name"]; } // Create instance on first call $persistent = array_key_exists("persistent", $db) && $db["persistent"] === true ? true : false; $db = new Database($db["driver"], $db["name"], $db["host"], $db["username"], $db["password"], $persistent); // Override with instance of Database $this->databases[$id] = $db; } // Return instance of Comely\IO\Database\Database return $db; }
/** * AppException constructor. * @param string $message * @param int $code * @param int $previous */ public function __construct(string $message, int $code = 0, $previous = null) { parent::__construct(__CLASS__, $message, $code, $previous); }