public function __construct(array $options) { $default_options = array('database' => '', 'user' => '', 'password' => '', 'class_path' => '', 'dialect' => 'MySQL', 'port' => 3306, 'host' => 'localhost', 'packages' => array()); $options = array_merge($default_options, $options); /* * Fatal Errors */ if (empty($options['database'])) { PhpBURN_Message::output('[!Empty database into configuration!]', PhpBURN_Message::ERROR); } if (empty($options['user'])) { PhpBURN_Message::output('[!Empty database user into configuration!]', PhpBURN_Message::ERROR); } if (empty($options['password'])) { PhpBURN_Message::output('[!Empty password into configuration!]', PhpBURN_Message::ERROR); } if (empty($options['class_path'])) { PhpBURN_Message::output('[!Empty class_path into configuration!]', PhpBURN_Message::ERROR); } /** * Search for all package in that Driver Connection/Configuration and * create specific configurations for them. * * Specific configurations * database - package can use same database conection and use another database * class_path - package can be into another class_path ( full path ) */ foreach ($options['packages'] as $key => $value) { $key = is_array($value) ? $key : $value; self::$options[$key] = new phpBURN_ConfigurationItem($key, $value, $options); } }
public function connect() { if ($this->conn_id && $this->state == self::OPEN) { $this->conn_id->selectDB($this->getDatabase()); return true; } //TODO preConnect actions should be called from here //Build the Connection String Prefix ( username:password@ ) $connPrefix = $this->getConnPrefix(); //Build the Connection String Host $hostString = $this->getHost(); //Build the Connection String Sulfix ( :port/database or /database ) and select database $connSulfix = $this->getConnSulfix(); $connString = sprintf("mongodb://%s%s%s", $connPrefix, $hostString, $connSulfix); $this->conn_id = new Mongo($connString); if (!$this->conn_id) { $this->state = self::CLOSED; $msg = '[!Database connection error!]: ' . $this->getDatabase() . ' - ' . $this->getErrorMsg(); PhpBURN_Message::output($msg, PhpBURN_Message::ERROR); return false; } else { $this->state = self::OPEN; } //TODO onConnectSucess actions should be called from here return true; }
/** * Creates a new Dialect or retreive the existing one based on the Model and Configuration. * * @param PhpBURN_ConfigurationItem $config * @param PhpBURN_Core $obj * @return PhpBURN_Dialect */ public static function create(PhpBURN_ConfigurationItem $config, PhpBURN_Core $obj) { $dialect = self::getDialect($config->dialect); if (!$dialect) { //Loads the interface for dialect uses PhpBURN::load('Dialect.IDialect'); // Loads the correspondent dialect based on config if (PhpBURN::load("Dialect.{$config->dialect}") != "error") { $className = self::getDialectClass($config->dialect); // Instance the dialect $dialectClass = new $className($obj); $dialect = self::$dialects[$config->package] = $dialectClass; unset($dialectClass); } else { PhpBURN_Message::output('[!Cannot find dialect!]: ' . $config->dialect, PhpBURN_Message::EXCEPTION); } } return $dialect; }
/** * This method loads model(s) from packages * * @example * <code> * PhpBURN::import('package.Model'); * </code> * @example * <code> * PhpBURN::import('package.subpackage.SubModel'); * </code> * * @access public */ public static function import() { $args = func_get_args(); foreach ($args as $libName) { // @TODO DEPRECATED WAY, WILL BE REMOVED AT Version 2 $lines = explode('.', $libName); $config = PhpBURN_Configuration::getConfig($lines[0]); $baseDir = $config->class_path; $libName = preg_replace('@^PhpBURN_@', '', $libName); // GENERIC FOR SPL_AUTOLOAD USAGE $libName = preg_replace('([^.]*\\.)', $replacement, $libName); $newFile = count($lines) > 1 ? $baseDir . $config->package . DS . $libName . SYS_MODEL_EXT : $libName . SYS_MODEL_EXT; if (require_once $newFile) { PhpBURN_Message::output('[!Loading Model!]: ' . $newFile, null, PhpBURN_Message::LOW); // require_once($newFile); } else { return false; } } }
/** * Executes functions settedUp on STATIC $onCallActionAfter * @param String $action * @param Array $parms */ public static function callActionAfter($controllerName, $action, array $parms) { if (array_search('PhpBURN_ControllerConfig', get_declared_classes()) == true) { if (is_array(PhpBURN_ControllerConfig::getOnCallActionAfter()) && count(PhpBURN_ControllerConfig::getOnCallActionAfter()) > 0) { foreach (PhpBURN_ControllerConfig::getOnCallActionAfter() as $function) { $function($controllerName, $action, $parms); } } } else { PhpBURN_Message::output('[!onCallActionBefore cannot be loaded because PhpBURN_ControllerConfig is not instanced - Please add PhpBURN::load("Tools.Controller.ControllerConfig"); to your config/controller.php Configurations!]', PhpBURN_Message::WARNING); } }
/** * Works like order() but for getRelationship() calls * * @param String $linkName * @param String $field * @param String $orderType * @param Boolean $override * * @return PhpBURN_Core */ public function relationshipOrder($linkName, $field, $orderType = "ASC", $override = false) { if ($this->getMap()->getRelationShip($linkName) == true) { $infos = $this->getMap()->fields[$linkName]; if (!$this->{$linkName} instanceof $infos['isRelationship']['foreignClass'] && $this->modelExist($infos['isRelationship']['foreignClass'])) { $this->{$linkName} = new $infos['isRelationship']['foreignClass'](); } $this->{$linkName}->order($field, $orderType, $override); return $this; } else { PhpBURN_Message::output($linkName . ' [!is not a valid relationship of!] ' . get_class($this), PhpBURN_Message::ERROR); return false; } }
/** * Validate a field based in its rules in Dialect Type * @param String $fieldName * @return unknown_type */ public function validateField($fieldName) { $keyExist = array_key_exists($fieldName, $this->fields); if ($keyExist == true && $this->fields[$fieldName]['isRelationship'] == false) { return $this->modelObj->_dialectObj->validateValue($this->fields[$fieldName]['#value'], $this->fields[$fieldName]['type'], $this->fields[$fieldName]['length']); } else { PhpBURN_Message::output("[!This field doesn't exist or is a Relationship!]: <strong>" . get_class($this->modelObj) . "->{$fieldName} </strong>", PhpBURN_Message::WARNING); return false; } return false; }
public function executeSQL($sql) { //$this->dispatchEvent('preExecute', $this, $sql); $this->connect(); $rs = @mysql_query($sql, $this->conn_id); if (!$rs) { $msg = "[!Database error:!] " . $this->getErrorMsg(); PhpBURN_Message::output($msg, PhpBURN_Message::ERROR); return false; //$this->dispatchEvent('onExecuteError', $this, $sql, $msg); } //$this->close(); //$this->dispatchEvent('posExecute', $this, $sql); return $rs; }
<?php ################################ # Hooks ################################ define('SYS_USE_FIREPHP', true, true); ################################ # Including required files ################################ require_once 'app/phpBurn.php'; require_once 'config.php'; ################################ # Starting application ################################ PhpBURN::startApplication(); ################################ # Sending a End of File ################################ PhpBURN_Message::output('[!EOF!]');
/** * Call error page located at SYS_VIEW_PATH/_errorPages just like a view * and then exit the application. * * @param String $page */ public function callErrorPage($page = '404') { PhpBURN_Message::output('[!Calling error page:!] ' . $page, PhpBURN_Message::ERROR); require_once SYS_VIEW_PATH . DS . '_errorPages' . DS . $page . '.php'; exit; }
public function constructModelFiles($package = null, $tableName = null) { if (is_writable(SYS_MODEL_PATH)) { foreach (self::$rawFields as $fullName => $arrContent) { preg_match_all("((([a-z,A-Z,0-9,_]+)\\.)?([a-z,A-Z,0-9\\.,_]+))", $fullName, $separation); PhpBURN_Views::setViewMethod('default'); $viewData['package'] = $separation[2][0]; $viewData['tableName'] = $separation[3][0]; $viewData['className'] = ucwords(str_replace('.', '_', $separation[3][0])); $viewData['rawFields'] = $arrContent; $viewData['fields'] = self::$fields[$fullName]; $viewData['rawFks'] = isset(self::$rawFks[strtolower($separation[3][0])]) ? self::$rawFks[strtolower($separation[3][0])] : self::$rawFks[$separation[3][0]]; $viewData['fks'] = isset(self::$fks[strtolower($separation[3][0])]) ? self::$fks[strtolower($separation[3][0])] : self::$fks[$separation[3][0]]; $content = "<?php\r\n"; $content .= PhpBURN_Views::loadViewFile(self::$thisPath . DS . 'modelTemplate.html', $viewData, true); $content .= "\r\n?>\r\n"; if (!is_dir(SYS_MODEL_PATH . $viewData['package'])) { SYS_MODEL_PATH . $viewData['package']; mkdir(SYS_MODEL_PATH . $viewData['package'], 0777, true); } $file = $viewData['className']; $fileName = sprintf("%s%s", $file, SYS_MODEL_EXT); $filePath = SYS_MODEL_PATH . $viewData['package']; $file = fopen($filePath . DS . $fileName, 'w+'); fwrite($file, $content); fclose($file); $outputMessage = sprintf("[!Creating Model!]: %s", $filePath . DS . $fileName); PhpBURN_Message::output($outputMessage); unset($content); } } else { $outputMessage = sprintf("%s [!is not writable!]", SYS_MODEL_PATH); PhpBURN_Message::output($outputMessage); } }
public function delete($pk = null) { // Getting the DELETE QUERY $sql = $this->prepareDelete($pk); if ($sql != null) { return $this->execute($sql); } else { $modelName = get_class($this->getModel()); PhpBURN_Message::output("[!Nothing to delete!] - <b>{$modelName}</b>"); return false; } }
public static function loadViewFile($path, $data, $toVar = false) { if (file_exists($path)) { PhpBURN_Message::output('[!Loading view file:!] ' . $path); $output = self::processViewData($path, $data); unset($path, $path); return $toVar == false ? print $output : $output; } else { return false; } }
public function setMessageLevel($level = self::NOTICE) { self::$messageLevel = $level; }
<?php ################################ # Hooks ################################ define('SYS_USE_FIREPHP', false, true); ################################ # Including required files ################################ require_once 'app/phpBurn.php'; require_once 'config.php'; ################################ # Start PhpBURN needed resources ################################ PhpBURN::enableAutoload(); PhpBURN_Message::setMode(PhpBURN_Message::CONSOLE); //Migrations tool PhpBURN::load('Migrations.Reverse'); ################################ # Starting application ################################ PhpBURN_Reverse::init();
* * @author Kléderson Bueno <*****@*****.**> * @version 1.0 */ @ob_start(); @session_start(); ################################ # System Settings ################################ require_once 'sysConfig.php'; ################################ # Error and Message System ################################ error_reporting(E_ALL & ~E_NOTICE); //Turn the Messages and Logs and Erros ON PhpBURN_Message::setMode(PhpBURN_Message::FIREBUG); //You can Choose FIREPHP, BROWSER OR FILE for now than more can came latter ################################ # Internacionalization Settings ################################ setlocale(LC_ALL, 'en_US'); date_default_timezone_set('America/Sao_Paulo'); ################################ # Modules ################################ # To load the module just remove the # comment from the line # Views #PhpBURN::loadModule('View'); # Controller #PhpBURN::loadModule('Controller'); # To load the module just remove the # comment from the line
public function loadView($viewName, $data, $toVar = false) { //Getting the path view $viewPath = SYS_VIEW_PATH . DS . $viewName . '.' . SYS_VIEW_EXT; if (file_exists($viewPath)) { PhpBURN_Message::output('[!Loading view:!] ' . $viewPath); $output = self::processViewData($viewPath, $data); unset($viewFile, $viewName, $viewPath); return $toVar == false ? print $output : $output; } else { return false; } }