function onStartConfig() { switch ($_SERVER['SERVER_NAME']) { case "www.rafaelteixeira.com": //type //id //host //database //schema //user //password Model::setConnection('mysql', 'default', 'localhost', 'rafael_run', '', 'rafael_run', 'dev123'); break; default: //type //id //host //database //schema //user //password Model::setConnection('mysql', 'default', 'localhost', 'run', '', 'root', 'dev123'); //Model::setConnection('mysql', 'runb', 'localhost', 'runb', '', 'root', 'dev123' ); Model::setConnection('postgre', 'postgre', 'localhost', 'run', 'run', 'postgres', 'dev'); Model::setConnection('postgre', 'postgre_form1', 'localhost', 'run_form1', 'public', 'postgres', 'dev'); break; } //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debug::log("Finalizando configuraĆ§Ć£o.", __LINE__, __FUNCTION__, __CLASS__, __FILE__); }
<?php namespace Fabrico\Model; use PDO; use Exception; use Fabrico\Application; // -------------------------------------- // lasciate ogne speranza, voi ch'intrate // -------------------------------------- Application::call(function () { $key = 'db:' . getenv('APP_ENV'); // class declaration in conditional statement? yeah. I do what ever the // f**k I want, bitch switch ($this->conf->get("{$key}:type")) { case 'file': require sprintf('%s/ModelFileStorage.php', __DIR__); Model::setDirectory($this->conf->get("{$key}:flat")); break; case 'pdo': require sprintf('%s/ModelDatabaseStorage.php', __DIR__); Model::setConnection(new PDO($this->conf->get("{$key}:dsn"), null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION])); break; default: throw new Exception('Invalid db configuration'); } });