/** * Starts a new session * Name of the session is specified in config file by SESSION_ID */ public static function start() { //Get the session identifier from config file $sessionId = Pokelio_Global::getConfig('SESSION_ID', 'Pokelio'); //Start session session_name($sessionId); @session_start(); }
/** * Construct method where configuration is applied * @param string $dbIdent Identifier of connection parameters section in config file */ public function __construct($dbIdent) { $connData = Pokelio_Global::getConfig('DATABASES', 'Pokelio')->{$dbIdent}; $this->connection = oci_connect($connData->USER, $connData->PASSWORD, $connData->DSN); if (!$this->connection) { $e = oci_error(); trigger_error("Error connecting to database." . NL . htmlentities($e['message'], ENT_QUOTES) . NL); } }
/** * Construct method where configuration is applied * @param string $dbIdent Identifier of connection parameters section in config file */ public function __construct($dbIdent) { $connData = Pokelio_Global::getConfig('DATABASES', 'Pokelio')->{$dbIdent}; try { $this->connection = new PDO("mssql:host=" . $connData->HOST . ";port=" . $connData->PORT . ";dbname=" . $connData->SCHEMA, $connData->USER, $connData->PASSWORD); $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { trigger_error("Error connecting to database. (" . $e->getMessage() . ")"); } }
/** * Writes a new line in log file with specified message * If requested, the source file and code line number is informed * * @param string $msg Message to be writen * @param boolean $source Indicate the invoking file/line */ public static function writeInfo($msg, $source = false) { if (Pokelio_Global::getConfig('LOG_INFO')) { $dbt = debug_backtrace(); $dbt = $dbt[0]; $level = "Info."; $msg = date('Y-m-d H:i:s') . " ({$level}): " . $msg; if ($source === true) { $msg .= "(from file " . $dbt['file'] . " at line " . $dbt['line'] . ")"; } $msg .= "\n"; file_put_contents(Pokelio_Global::getConfig('LOG_FILE'), $msg, FILE_APPEND); } }
/** * Set up the environment according to configuration file specifications * * @param string $configPath The path of the folder containing Pokelio.json configuration file * @param string $appRealPath Where the consumer app is */ public function __construct($configPath, $appRealPath) { //Config define('APP_CONFIG_PATH', $configPath); //Check if config file exists $configFile = APP_CONFIG_PATH . '/Pokelio.json'; if (!file_exists($configFile)) { //Can´t use Pokelio_Error class to raise error here die("Pokelio config file [{$configFile}] not found. Can´t continue."); } //Set Pokelio path constants $this->setPokelioPaths(); //Set loader function for Pokelio classes require POKELIO_CLASSES_PATH . '/Loader/Loader.php'; Pokelio_Loader::setLoader(); //Load special classes require POKELIO_CLASSES_PATH . '/ShortCuts.php'; //Register Pokelio Modules //Pokelio_Module::registerModules(POKELIO_MODULES_PATH); //Set consumer application path constants $this->setAppPaths($appRealPath); //Register App Modules //Pokelio_Module::registerModules(APP_MODULES_PATH,true); //Load configuration file Pokelio_Global::loadConfigFile($configFile, 'Pokelio'); //Set error manager Pokelio_Error::setErrorHandler(); //Set fatal error manager Pokelio_Error::setFatalErrorHandler(); //Disable error reporting as we are managing that $phpErrorReport = Pokelio_Global::getConfig('PHP_ERROR_REPORTING', 'Pokelio'); ini_set('error_reporting', $phpErrorReport); //Set exception manager Pokelio_Exception::setExceptionHandler(); //Set timezone date_default_timezone_set(Pokelio_Global::getConfig('TIMEZONE')); //CallBack //Pokelio_Callback::invokeCallback('Pokelio', 'Application', 'endConfiguration'); $this->cliManager(); }
public static function copyDir($srcDir, $trgDir, $cleanFirst = false) { $permissions = Pokelio_Global::getConfig('CREATED_FILE_PERMISSIONS', 'Pokelio'); $permissions = intval($permissions, 8); if ($cleanFirst == true && file_exists($trgDir)) { self::rmDir($trgDir); } Pokelio_File::makedir($trgDir); $entries = scandir($srcDir); foreach ($entries as $entry) { if (substr($entry, 0, 1) != '.') { $pathEntry = $srcDir . '/' . $entry; if (is_file($pathEntry)) { copy($pathEntry, $trgDir . '/' . $entry); } if (is_dir($pathEntry)) { Pokelio_File::copyDir($pathEntry, $trgDir . '/' . $entry); } chmod($trgDir . '/' . $entry, $permissions); } } }
public static function getValue($name, $mandatory = false, $default = null) { $value = null; if (SESSION_TYPE == 'WEB') { //check first POST parameters if (isset($_POST[$name])) { $value = $_POST[$name]; } elseif (isset($_GET[$name])) { $value = $_GET[$name]; } elseif (Pokelio_Global::getConfig('ALLOW_URL_PARAMS', 'Pokelio')) { $value = self::getUrlParamValue($name); } } else { $value = self::getCliParamValue($name); } if ($value === null) { if ($mandatory == false) { $value = $default; } else { trigger_error("Mandatory parameter " . $name . " is missing."); } } return $value; }
/** * Based on a file and a line number, it gets the code before and after * and returns a formatted string with the surrounding code of the error line * * @param string $file File where the error happened * @param integer $line Line of file where the error happened */ private static function showCodeLines($file, $line) { //Get a partial list of code where the error has ocurred $text = ""; $fileContent = file_get_contents($file); $lines = explode("\n", $fileContent); $nLines = Pokelio_Global::getConfig("ERROR_SHOW_CODE_LINES", 'Pokelio'); $startLine = $line - $nLines; if ($startLine < 1) { $startLine = 1; } $endLine = $line + $nLines; if ($endLine > sizeof($lines)) { $endLine = sizeof($lines); } $text .= " Code:" . "\n"; for ($iLine = $startLine; $iLine <= $endLine; $iLine++) { if ($iLine == $line) { $text .= " !!!----> "; } else { $text .= " "; } $text .= substr(" " . $iLine, -4); $text .= " "; $text .= str_replace("\n", "", $lines[$iLine - 1]) . "\n"; } return $text; }
/** * Invokes App starting point */ private function start() { $startClass = Pokelio_Global::getConfig('START_CLASS', 'Pokelio'); $startMethod = Pokelio_Global::getConfig('START_METHOD', 'Pokelio'); if ($startClass == "" || $startMethod == "") { echo NL . 'Everything went OK.' . NL . NL . 'Now, change the START_CLASS and START_METHOD of config file and start using Pokelio PHP Framework' . NL; exit; } else { $class = new $startClass(); $class->{$startMethod}(); } }
public function __construct() { $connName = Pokelio_Global::getConfig('CONNECTION_ID', 'MySQLManager'); parent::__construct($connName); $this->schema = Pokelio_Global::getConfig('DATABASES', 'Pokelio')->{$connName}->SCHEMA; }
public static function getConfig($param) { return Pokelio_Global::getConfig($param); }
/** * Invokes the parent __construct method passing connection id * */ public function __construct() { $connName = Pokelio_Global::getConfig("CONNECTION_ID", "Bsm"); parent::__construct($connName); }