/** * Return the root url which will properly format the url so it adds or not ? to make the relative link * @uses : to make links * @example : http://mysite.com/? -> http://mysite.com/?/ModuleName if htaccess is missing, or http://mysite.com/ModuleName is htaccess is here * @return string */ public function getBaseUrl() { $questionMark = Config::System()->get("useUrlQuestionMark"); return $this->getSiteUrl() . ($questionMark ? "/?" : ""); }
/** * To establish the connection based on the DBAlias provided in the DB.ini * It will only connects to the db once, then * * @param string $dbAlias * @return \PDO|dsnClient * @throws Core\Exception */ public static function connect($dbAlias) { if (!isset(self::$dbConnections[$dbAlias])) { $db = Config::DB()->get($dbAlias); if (!is_array($db)) { throw new Exception\Model("Database Alias: {$dbAlias} config doesn't exist."); } $dbType = strtolower($db["type"]); switch ($dbType) { /** * To manage RDMS connection using PDO * Also creates EXCEPTION as error mode * * @return PDO */ case "mysql": case "pgsql": case "sqlite": if ($dbType == "sqlite") { // Requires: dsn $PDO = new PDO("sqlite:{$db["dsn"]}"); } else { $port = isset($db["port"]) && $db["port"] ? ";port={$db["port"]}" : ""; $dsn = "{$dbType}:host={$db["host"]};dbname={$db["dbname"]}{$port}"; $PDO = new PDO($dsn, $db["user"], $db["password"]); } $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //@return PDO self::$dbConnections[$dbAlias] = $PDO; break; /** * DSN (Data Source Name) * To manage other connections such as MongoDB, Redis etc * It requires the 'dsn' and class to create the instance * For MongoDB * dsn = 'mongodb://localhost:27017' * dsnClient = '\MongoClient' * * For Redis * dsn = '1.0.0.1:6379' * dsnClient = '\Redisent\Redis' * * @return object dsnClient */ /** * DSN (Data Source Name) * To manage other connections such as MongoDB, Redis etc * It requires the 'dsn' and class to create the instance * For MongoDB * dsn = 'mongodb://localhost:27017' * dsnClient = '\MongoClient' * * For Redis * dsn = '1.0.0.1:6379' * dsnClient = '\Redisent\Redis' * * @return object dsnClient */ case "dsn": $dsnDependency = new ReflectionClass($db["dsnClient"]); //@return dsnDependency self::$dbConnections[$dbAlias] = $dsnDependency->newInstance($db["dsn"]); break; default: throw new Exception\Model("Invalid type for Alias: '{$dbAlias}'. Type: {$db["type"]} was provided"); break; } } return self::$dbConnections[$dbAlias]; }
define("LOAD_VOODOO_WITH_COMPOSER", true); // @var string - The directory of the composer vendor define("COMPOSER_VENDOR_DIR", APP_ROOT_DIR . "/vendor"); // @var string - The root directory which contains /Voodoo define("VOODOO_ROOT_DIR", APP_ROOT_DIR); /** * @var string * Leave blank if your config files are at the based of /App/_conf * If you create multiple environment, ie: /App/_conf/production, /App/_conf/stage, /App/_conf/dev * Set the name of the subdirectory, ie: 'production' */ define("APP_CONFIG_DIRNAME", ""); /** * To load Voodoo with composer or as self */ if (LOAD_VOODOO_WITH_COMPOSER) { include_once COMPOSER_VENDOR_DIR . "/autoload.php"; } else { include_once VOODOO_ROOT_DIR . "/Voodoo/autoload.php"; } // Autoload classes at the root Voodoo\Core\Autoloader::register(APP_ROOT_DIR); // Set the ENV path Env::setAppRootDir(APP_ROOT_DIR); // Set the config name. A sub directory name under /App/_conf/$subdirectory Env::setConfigPath(APP_CONFIG_DIRNAME); // Set the system timezone date_default_timezone_set(Config::System()->get("timezone")); // Error Reporting error_reporting(Config::System()->get("errorReporting"));