Ejemplo n.º 1
0
 public function __get($name)
 {
     if ($name == 'tpl') {
         if (!$this->_templateInitialized) {
             $this->initTemplate();
         }
         return $this->_template;
     }
     if ($name == 'router') {
         return Router::getInstance();
     }
     if ($name == 'session') {
         return Session::getInstance();
     }
     if ($name == 'config') {
         return Config::getInstance();
     }
     if ($name == 'log') {
         return Logger::getInstance();
     }
     if ($name == 'language') {
         return Language::getInstance();
     }
     if ($name == 'model') {
         return Model::getInstance();
     }
 }
Ejemplo n.º 2
0
 public static function getUrl($routeName, $vars = array(), $lang = null, $ssl = false, $ruleNumber = null, $varsSeparator = '/', $default = '')
 {
     $route = self::getRoute($routeName);
     if (!is_array($vars)) {
         throw new \Exception('Route : "' . $routeName . '" vars must be an array');
     }
     //no exist route
     if (!$route) {
         return $default;
     }
     //config lang and ssl
     if ($lang === null) {
         $lang = Language::getInstance()->getLanguage();
     }
     if ($route->getRequireSsl()) {
         $ssl = true;
     }
     $rules = $route->getRules();
     if (empty($rules)) {
         return self::getHost(true, $ssl);
     }
     $ruleCount = 0;
     foreach ($rules as &$rule) {
         $matchedRule = self::_matchRule($route, $rule, $lang, $vars, $varsSeparator, $ruleNumber, $ruleCount);
         if ($matchedRule !== false) {
             break;
         }
         $ruleCount++;
     }
     // no matched rule, return rule 1
     $matchedRule = self::_matchRule($route, $rule, $lang, $vars, $varsSeparator, 1, 1);
     if ($matchedRule !== false) {
         return self::getHost(true, $ssl) . $matchedRule;
     }
     return $default;
 }
Ejemplo n.º 3
0
 protected function _getErrorType($errCode)
 {
     $language = Language::getInstance();
     switch ($errCode) {
         case 'E_FATAL':
             return $language->getVar('e_fatal');
         case E_ERROR:
             return $language->getVar('e_error');
         case E_WARNING:
             return $language->getVar('e_warning');
         case E_PARSE:
             return $language->getVar('e_parse');
         case E_NOTICE:
             return $language->getVar('e_notice');
         case E_CORE_ERROR:
             return $language->getVar('e_core_error');
         case E_CORE_WARNING:
             return $language->getVar('e_core_warning');
         case E_COMPILE_ERROR:
             return $language->getVar('e_compile_error');
         case E_COMPILE_WARNING:
             return $language->getVar('e_compile_warning');
         case E_USER_ERROR:
             return $language->getVar('e_user_error');
         case E_USER_WARNING:
             return $language->getVar('e_user_warning');
         case E_USER_NOTICE:
             return $language->getVar('e_user_notice');
         case E_STRICT:
             return $language->getVar('e_strict');
         case E_RECOVERABLE_ERROR:
             return $language->getVar('e_recoverable_error');
         case E_DEPRECATED:
             return $language->getVar('e_deprecated');
         case E_USER_DEPRECATED:
             return $language->getVar('e_user_deprecated');
         default:
             return $language->getVar('e_unknown');
     }
 }
Ejemplo n.º 4
0
 public function stop()
 {
     if ($this->_isInit && $this->_isRun) {
         // run caches gc
         $caches = Cache::getCaches();
         foreach ($caches as $cache) {
             $cache->runGc();
         }
         //profiling
         if (self::getProfiler()) {
             // Caches
             foreach ($caches as $cache) {
                 Logger::getInstance()->debug('Adaptater : "' . get_class($cache) . '"', 'cache' . $cache->getName());
             }
             // Databases
             $databases = Database::getDatabases();
             foreach ($databases as $database) {
                 Logger::getInstance()->debug('Type : ' . $database->getType(), 'database' . $database->getName());
                 Logger::getInstance()->debug('Adaptater : ' . get_class($database->getAdaptater()), 'database' . $database->getName());
                 $stats = $database->getStats();
                 Logger::getInstance()->debug('Queries : ' . (string) $database->getQueryCount() . ' (Aproximately memory used  : ' . $stats['ram'] . ' KB in aproximately ' . $stats['time'] . ' ms)', 'database' . $database->getName());
                 Logger::getInstance()->debug('Servers : ' . $database->countServers() . ' (Masters : ' . $database->countServers(Server::TYPE_MASTER) . '  Slaves : ' . $database->countServers(Server::TYPE_SLAVE) . ')', 'database' . $database->getName());
             }
             // Templates
             $templates = Template::getTemplates();
             foreach ($templates as $template) {
                 Logger::getInstance()->debug('Adaptater : ' . get_class($template), 'template' . $template->getName());
             }
             // Language
             Logger::getInstance()->debug('Language default is : "' . Language::getInstance()->getDefaultLanguage() . '"', 'language');
             Logger::getInstance()->debug(Language::getInstance()->countVars() . ' vars defined', 'language');
             // Router
             Logger::getInstance()->debug('Current url : ' . Http::getCurrentUrl(), 'router');
             Logger::getInstance()->debug('Current route : ' . Router::getInstance()->getCurrentRoute(), 'router');
             Logger::getInstance()->debug('Current route rule : ' . Router::getInstance()->getCurrentRule(), 'router');
             Logger::getInstance()->debug('Ajax request : ' . (int) Http::isAjax(), 'router');
             Logger::getInstance()->debug('Ssl request : ' . (int) Http::isHttps(), 'router');
             Logger::getInstance()->debug('Request dispatched in aproximately : ' . Benchmark::getInstance('router')->stopTime()->getStatsTime() . ' ms', 'router');
             Logger::getInstance()->debug('Aproximately memory used  : ' . Benchmark::getInstance('router')->stopRam()->getStatsRam() . ' KB', 'router');
             // Logger debug informations and benchmark
             Logger::getInstance()->addGroup('logger', 'Logger Benchmark and Informations', true);
             Logger::getInstance()->debug(Logger::getInstance()->countObservers() . ' observers registered', 'logger');
             Logger::getInstance()->debug(Logger::getInstance()->countGroups() . ' groups and ' . (Logger::getInstance()->countLogs() + 3) . ' logs', 'logger');
             Logger::getInstance()->debug('In aproximately ' . Benchmark::getInstance('logger')->stopTime()->getStatsTime() . ' ms', 'logger');
             Logger::getInstance()->debug('Aproximately memory used  : ' . Benchmark::getInstance('logger')->stopRam()->getStatsRam() . ' KB', 'logger');
             // Autoloader
             Logger::getInstance()->addGroup('autoloader', 'Autoloader report', true);
             $logs = Autoloader::getLogs();
             foreach ($logs as &$log) {
                 Logger::getInstance()->debug($log, 'autoloader');
             }
             Logger::getInstance()->debug(count(Autoloader::getAutoloaders()) . ' autoloader adaptaters, ' . count(Autoloader::getDirectories()) . ' directories and ' . count(Autoloader::getNamespaces()) . ' namespaces registered', 'autoloader');
             Logger::getInstance()->debug('Loading ' . count(Autoloader::getClasses()) . ' classes (' . Autoloader::countGlobalizedClasses() . ' globalized classes)  in aproximately ' . round(Autoloader::getBenchmark('time') * 1000, 4) . ' ms', 'autoloader');
             Logger::getInstance()->debug('Aproximately memory used  : ' . round(Autoloader::getBenchmark('memory') / 1024, 4) . ' KB', 'autoloader');
             Autoloader::purgeLogs();
             Autoloader::purgeBenchmark();
             // Global informations && Benchmark
             Logger::getInstance()->addGroup('global', 'Global Benchmark and Informations', true);
             Logger::getInstance()->debug('Page generated in aproximately : ' . Benchmark::getInstance('global')->stopTime()->getStatsTime() . ' ms', 'global');
             Logger::getInstance()->debug('Aproximately memory used  : ' . Benchmark::getInstance('global')->stopRam()->getStatsRam() . ' KB - Memory allocated : ' . memory_get_peak_usage(true) / 1024 . ' KB', 'global');
         }
         //notify logger
         Logger::getInstance()->notify();
         // Stop managers
         ExceptionManager::getInstance()->stop();
         ErrorManager::getInstance()->stop();
         // avoid multi call
         $this->_isInit = false;
         $this->_isRun = false;
     }
 }
Ejemplo n.º 5
0
}
if (defined('LOGGER_MAIL') && LOGGER_MAIL && defined('LOGGER_MAIL_TO_EMAIL') && defined('LOGGER_MAIL_TO_NAME') && !static::getDebug()) {
    $mailConfig = array('fromEmail' => ADMIN_EMAIL, 'fromName' => $language->getVar('site_name'), 'toEmail' => LOGGER_MAIL_TO_EMAIL, 'toName' => LOGGER_MAIL_TO_NAME, 'mailSubject' => $language->getVar('site_name') . '  logs');
    $log->attach(new Mail($mailConfig));
}
if (defined('LOGGER_ERROR') && LOGGER_ERROR) {
    $exc->attach(new Log());
    $err->attach(new Log());
}
// Config router host
if (!defined('HOSTNAME')) {
    throw new \Exception('Miss hostname constant');
}
Router::setHost(HOSTNAME);
// Auto set language, by session
$languageLoaded = Language::getInstance()->getLanguage();
$langSession = Session::getInstance()->get('language');
if (!is_null($langSession) && $langSession != $languageLoaded) {
    $language->setLanguage($langSession);
    $languageLoaded = $langSession;
}
// Auto set language, by cookie
$langCookie = Cookie::get('language');
if (!is_null($langCookie) && $langCookie != $languageLoaded) {
    $language->setLanguage($langCookie);
    $languageLoaded = $langSession;
}
// Security
Security::autorun();
// Clean
unset($bench, $globalizer, $language, $exc, $err, $log);
Ejemplo n.º 6
0
 public function setAudioLangDirectory($path)
 {
     $path = realpath($path . Language::getInstance()->getLanguage());
     if (!is_dir($path)) {
         throw new \Exception('Invalid audio language path : "' . $path . '"');
     }
     // TODO check if have all wav files (charslist)
     $this->_audioLangDirectory = $path . DS;
 }