Esempio n. 1
0
 /**
  * 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();
 }
Esempio n. 2
0
 /**
  * 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);
     }
 }
Esempio n. 3
0
 /**
  * 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() . ")");
     }
 }
Esempio n. 4
0
 /**
  * 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);
     }
 }
Esempio n. 5
0
 /**
  * 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();
 }
Esempio n. 6
0
 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);
         }
     }
 }
Esempio n. 7
0
 /**
  * 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;
 }
Esempio n. 8
0
 public static function setCliParams()
 {
     //Process $_SERVER['argv'] array
     $parts = $_SERVER['argv'];
     //0 element is the name of the script itself, so we start at 1
     $params = array();
     for ($i = 1; $i < sizeof($parts); $i++) {
         $subParts = explode("=", $parts[$i]);
         if (isset($subParts[1])) {
             $params[$subParts[0]] = $subParts[1];
         } else {
             $params[$subParts[0]] = '';
         }
     }
     //Initialize the global array to store params/values
     Pokelio_Global::setVar('CLI_PARAMS', $params);
 }
Esempio n. 9
0
 /**
  * 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}();
     }
 }
Esempio n. 10
0
 public function __construct()
 {
     $connName = Pokelio_Global::getConfig('CONNECTION_ID', 'MySQLManager');
     parent::__construct($connName);
     $this->schema = Pokelio_Global::getConfig('DATABASES', 'Pokelio')->{$connName}->SCHEMA;
 }
Esempio n. 11
0
 public static function setVar($var, $value)
 {
     Pokelio_Global::setVar($var, $value);
 }
Esempio n. 12
0
 /**
  * 
  * 
  * @param string   $modulesPath  Path to folder containing the module
  * @param string   $module         
  * @param boolean  $callback       
  * 
  */
 private static function registerModule($modulePath, $module, $callback = false)
 {
     //Load configuration of the module and callBack to notify
     $configFile = APP_CONFIG_PATH . '/' . $module . '.json';
     Pokelio_Global::loadConfigFile($configFile, $module);
     //Does the module contain a class loader?
     $loaderClassFile = $modulePath . '/' . $module . '/Classes/Loader/Loader.php';
     if (file_exists($loaderClassFile)) {
         require $loaderClassFile;
         if (is_callable($module . '_Loader::setLoader')) {
             call_user_func($module . '_Loader::setLoader');
         }
     }
     //CallBack
     if ($callback == true) {
         Pokelio_Callback::invokeCallback($module, 'Module', 'moduleRegistered');
     }
 }
 /** 
  * Invokes the parent __construct method passing connection id 
  *  
  */
 public function __construct()
 {
     $connName = Pokelio_Global::getConfig("CONNECTION_ID", "Bsm");
     parent::__construct($connName);
 }