/** * env manipule les variables d'environement du server. * * @param $key * @param null $value * * @return bool|string */ function env($key, $value = null) { if ($value !== null) { return getenv(\Bow\Support\Str::upper($key)); } else { return putenv(\Bow\Support\Str::upper($key) . '=' . $value); } }
/** * connection, lance la connection sur la DB * * @param null $zone * @param null $cb * @return null|Database */ public static function connection($zone = null, $cb = null) { if (static::$db instanceof PDO) { return static::takeInstance(); } if (!static::$config instanceof StdClass) { return Util::launchCallback($cb, [new ConnectionException("Le fichier database.php est mal configurer")]); } if (is_callable($zone)) { $cb = $zone; $zone = null; } if ($zone != null) { static::$zone = $zone; } $c = isset(static::$config->connections[static::$zone]) ? static::$config->connections[static::$zone] : null; if (is_null($c)) { Util::launchCallback($cb, [new ConnectionException("La clé '" . static::$zone . "' n'est pas définir dans l'entre database.php")]); } $db = null; try { // Variable contenant les informations sur // utilisateur $username = null; $password = null; // Configuration suppelement coté PDO $pdoPostConfiguation = [PDO::ATTR_DEFAULT_FETCH_MODE => static::$config->fetch]; switch ($c["scheme"]) { case "mysql": // Construction de la dsn $dns = "mysql:host=" . $c["mysql"]['hostname'] . ($c["mysql"]['port'] !== null ? ":" . $c["mysql"]["port"] : "") . ";dbname=" . $c["mysql"]['database']; $username = $c["mysql"]["username"]; $password = $c["mysql"]["password"]; $pdoPostConfiguation[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . Str::upper($c["mysql"]["charset"]); break; case "sqlite": $dns = $c["sqlite"]["driver"] . ":" . $c["sqlite"]["database"]; break; default: throw new DatabaseException("Vérifiez la configuration de la base de donnée.", E_USER_ERROR); break; } // Connection à la base de donnée. static::$db = new PDO($dns, $username, $password, $pdoPostConfiguation); } catch (PDOException $e) { /** * Lancement d'exception */ static::$errorInfo = [$e->getCode(), true, $e->getMessage()]; Util::launchCallback($cb, [$e]); } Util::launchCallback($cb, [false]); return static::class; }