public function __construct() { // automatically define table name (if not defined) if (!isset($this->_name)) { // delete prefix $className = preg_replace('`^.*Model_Table_`', '', get_class($this)); // add slash after upper case letters $name = preg_replace('`[^_]([A-Z])`', '_$1', $className); // table name in lower case $this->_name = strtolower($name); } // load tables structure if (is_null(self::$_structure)) { self::$_structure = Days_Config::load('database')->get(); } // check table definition if (!array_key_exists($this->_name, self::$_structure)) { throw new Days_Exception("Not defined table structure for `{$this->_name}`"); } // set adapter for all tables if (!$this->_db) { $this->_db = Days_Db::factory(); $this->_select = $this->_db->select(); } }
protected static function _postFilter($content) { // add base path after all url adresses $basePath = Days_Config::load()->get('url/base', ''); if ('' != $basePath) { $content = preg_replace('`(= *[\'"]/)`', "\$1{$basePath}/", $content); } return $content; }
public function __construct() { $appPath = Days_Engine::appPath(); if (0 == strcmp($appPath, self::$_appDir)) { return; } self::$_appDir = $appPath; if (DIRECTORY_SEPARATOR != substr(self::$_appDir, -1)) { self::$_appDir .= DIRECTORY_SEPARATOR; } self::$_templateDir = self::$_appDir . self::TEMPLATE_DIR; self::$_compileDir = self::$_appDir . self::COMPILE_DIR; self::$_cacheDir = self::$_appDir . self::CACHE_DIR; self::$_caching = Days_Config::load()->get('cache/lifetime', 0); }
public static function save() { if (!empty(self::$_errors)) { // prepare data $sErrorFile = str_replace(':', '.', $_SERVER['HTTP_HOST']); $sLogDir = Days_Engine::appPath() . 'system/log/'; // get current application error levels $level = Days_Config::load()->get('log/level'); // save log if (Days_Config::load()->get('engine/debug', false)) { $messages = self::getMessages($level); if (count($messages) == 0) { return; } switch (strtolower(Days_Config::load()->get('log/type', 'file'))) { // save to SQLite case 'sqlite': self::logtoSqlite($messages, $sErrorFile, $sLogDir); break; //send to browser //send to browser case 'browser': self::logtoBrowser($messages); break; // send to FirePHP // send to FirePHP case 'fb': case 'firebug': case 'firephp': self::logtoFirephp($messages); break; // save to FILE // save to FILE case 'file': default: self::logtoFile($messages, $sErrorFile, $sLogDir); } } // clear saved errors self::$_errors = array(); } }
private function __construct() { // set global variables global $_SERVER; // get site settings $sDefaultLang = Days_Config::load()->get('url/lang', 'en'); $sDefaultExt = Days_Config::load()->get('url/ext', 'html'); $basePath = Days_Config::load()->get('url/base', ''); // get url path, start from base path $basePath = trim($basePath, '/'); $urlAdress = (string) substr(trim($_SERVER['REQUEST_URI'], '/'), strlen($basePath)); // parse path if (0 == preg_match('`^(.+)\\.([a-z]{2})\\.([a-z]{3,5})/?$`', $urlAdress, $aMatches)) { $aMatches = array(1 => $urlAdress, 2 => $sDefaultLang, 3 => $sDefaultExt); } // explode path to variables $aPath = explode('/', trim($aMatches[1], '/')); // set system variables $this->_specParams['protocol'] = empty($_SERVER['HTTPS']) ? 'http' : 'https'; $this->_specParams['host'] = $_SERVER['HTTP_HOST']; $this->_specParams['controller'] = !empty($aPath[0]) ? $aPath[0] : 'index'; $this->_specParams['action'] = !empty($aPath[1]) ? $aPath[1] : 'index'; $this->_specParams['lang'] = $aMatches[2]; $this->_specParams['ext'] = $aMatches[3]; // set user variables foreach ($aPath as $iNum => $sValue) { // not handle first two parameters (servise and action name) if ($iNum <= 1) { continue; } // parse parameter as "name:value" $aParams = explode(':', $sValue, 2); $sName = $aParams[0]; $sValue = isset($aParams[1]) ? $aParams[1] : ''; // set value if ('' != $sValue) { $this->_params[$sName] = $sValue; } else { $this->_params[] = $sName; } } }
/** * Return new database object. * * @param $schema string: Name of database schema in config * @return Days_Db */ public static function factory($schema = 'default', $dbtype = 'Zend') { // recive databace configuration $aConfig = Days_Config::load()->get("db/{$schema}", array()); // check schema in configuration if (empty($aConfig)) { throw new Days_Exception("Not defined database configuration section 'db/{$schema}'"); } // set correct type of database driver $aConfig['adapter'] = 'PDO_' . strtoupper($aConfig['adapter']); // buffering data only for mysql driver if ('PDO_MYSQL' == $aConfig['adapter']) { $aConfig[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true; } // create Zend_Db object $_db = Zend_Db::factory($aConfig['adapter'], $aConfig); // prepare object to work with correct character encoding $_db->query('SET CHARACTER SET utf8'); $_db->query('SET NAMES utf8'); // set objects in result set $_db->setFetchMode(Zend_Db::FETCH_OBJ); return $_db; }
/** * Run application. * * @param string $appPath Path to application * @param string $mode Name of configuration file used in work */ private function __construct($appPath, $mode) { // set pathes self::$_libPath = realpath(dirname(__FILE__) . '/..') . '/'; self::$_appPath = realpath($appPath) . '/'; self::$_publicPath = getcwd() . '/'; set_include_path(get_include_path() . PATH_SEPARATOR . self::$_libPath); spl_autoload_register(array(__CLASS__, 'autoload')); Days_Session::init(); // set config main file if (!empty($mode)) { Days_Config::setDefaultConfig($mode); } // set path for config Days_Config::setConfigPath(self::$_appPath . 'config/'); // set debug mode self::$_isDebug = (bool) Days_Config::load()->get('engine/debug', false); // set error level and handler $iErrorLevel = self::isDebug() ? E_ALL | E_STRICT : E_ALL ^ E_NOTICE; error_reporting($iErrorLevel); setlocale(LC_ALL, 'ru_RU.UTF-8', 'RUS', 'RU'); //set timezone if ($timezone = Days_Config::load()->get('engine/timezone', false)) { date_default_timezone_set($timezone); } else { date_default_timezone_set('Europe/Helsinki'); } // not send execution errors to user ob_start(); try { if (Days_Config::load()->get('engine/autorun', 1)) { $autorunClass = "Controller_System_Autorun"; // run predefined class if (class_exists($autorunClass) and is_callable(array($autorunClass, 'run'))) { call_user_func(array($autorunClass, 'run')); } } Days_Event::run('engine.start'); // get url info $controller = Days_Url::getSpec('controller'); $action = Days_Url::getSpec('action'); $ext = Days_Url::getSpec('ext'); Days_Event::run('controller.start'); // set module path Days_Model::setPath(self::appPath() . 'Model/'); // set controller params $controllerClass = "Controller_" . ucfirst($controller); // use index controller for non-exists controllers if (!class_exists($controllerClass) and Days_Config::load()->get('url/virtual')) { $controllerClass = "Controller_Index"; $controller = 'index'; } // set action name $actionMethod = Days_Request::isAjax() ? "{$action}AjaxAction" : "{$action}Action"; // set template path $template = "content/{$controller}/{$action}.{$ext}"; // create controller if (!class_exists($controllerClass)) { throw new Days_Exception("Controller '{$controllerClass}' not found"); } $controllerObj = new $controllerClass($template); if (!$controllerObj instanceof Days_Controller) { throw new Days_Exception("Controller '{$controllerClass}' should be extended from 'Days_Controller'"); } // call init() method for prepare object $controllerObj->init(); Days_Event::run('controller.post.init'); // execute PostAction before call specified action if (Days_Request::isPost()) { $actionPost = "{$action}PostAction"; if (method_exists($controllerObj, $actionPost)) { call_user_func(array($controllerObj, $actionPost)); } } // call specified action if (!method_exists($controllerObj, $actionMethod)) { throw new Days_Exception("Action {$actionMethod} in controller {$controllerClass} not defined"); } $actionResult = call_user_func(array($controllerObj, $actionMethod)); // ajax query if (Days_Request::isAjax()) { if (is_null($actionResult)) { $actionResult = array(); } $content = $actionResult; } else { $controllerObj->setLayout($controller, false); $content = call_user_func(array($controllerObj, 'getContent')); Days_Response::addHeader($ext); } Days_Event::run('controller.end'); // set data to response Days_Response::addContent($content); } catch (Exception $oEx) { // save error message about this query Days_Log::add($oEx->getMessage()); // page not found Days_Response::addHeader(Days_Response::NOT_FOUND); } // save runtime errors for ($iObLevel = ob_get_level(); $iObLevel > 0; $iObLevel--) { $sError = ob_get_contents(); if ('' != $sError) { Days_Log::add("This data printed in scripts: '{$sError}'"); } // close output handler ob_end_clean(); } // save errors Days_Log::save(); Days_Event::run('engine.end'); // send headers to user Days_Event::run('response.send.headers'); Days_Response::sendHeaders(); // send content to user Days_Event::run('response.send.content'); Days_Response::sendContent(); }
public static function setConfigPath($path) { self::$_confPath = $path; }