/** * Mediboard class autoloader * * @param string $class Class to be loaded * * @return bool */ function mbAutoload($class) { $file_exists = false; $time = microtime(true); // Entry already in cache if (isset(CApp::$classPaths[$class])) { // The class is known to not be in MB if (CApp::$classPaths[$class] === false) { return false; } // Load it if we can if ($file_exists = file_exists(CApp::$classPaths[$class])) { CApp::$performance["autoloadCount"]++; return include_once CApp::$classPaths[$class]; } } // File moved ? if (!$file_exists) { unset(CApp::$classPaths[$class]); } // CSetup* class if (preg_match('/^CSetup(.+)$/', $class, $matches)) { $dirs = array("modules/{$matches['1']}/setup.php"); } else { $class_file = $class; $suffix = ".class"; // Namespaced class if (strpos($class_file, "\\") !== false) { $namespace = explode("\\", $class_file); // Mediboard class if ($namespace[0] === "Mediboard") { array_shift($namespace); $class_file = implode("/", $namespace); } else { $class_file = "vendor/" . implode("/", $namespace); $suffix = ""; } } $class_file .= $suffix; $dirs = array("classes/{$class_file}.php", "classes/*/{$class_file}.php", "mobile/*/{$class_file}.php", "modules/*/classes/{$class_file}.php", "modules/*/classes/*/{$class_file}.php", "modules/*/classes/*/*/{$class_file}.php", "install/classes/{$class_file}.php"); } $rootDir = CAppUI::conf("root_dir"); $class_path = false; foreach ($dirs as $dir) { $files = glob("{$rootDir}/{$dir}"); foreach ($files as $filename) { include_once $filename; // The class was found if (class_exists($class, false) || interface_exists($class, false)) { $class_path = $filename; break 2; } } } // Class not found, it is not in MB CApp::$classPaths[$class] = $class_path; SHM::put("class-paths", CApp::$classPaths); CApp::$performance["autoload"][$class] = (microtime(true) - $time) * 1000; return $class_path !== false; }
/** * Get an instance from the code * * @param string $code Code CdARR * * @return CTypeActiviteCdARR **/ static function get($code) { if (!$code) { return new self(); } if ($type = SHM::get("type_activite_{$code}")) { return $type; } $type = new self(); $type->load($code); SHM::put("type_activite_{$code}", $type); return $type; }
/** * Get an instance from the code * * @param string $code Code * * @return CIntervenantCdARR **/ static function get($code) { if (!$code) { return new self(); } if ($intervenant = SHM::get("intervenant_{$code}")) { return $intervenant; } $intervenant = new self(); $intervenant->load($code); SHM::put("intervenant_{$code}", $intervenant); return $intervenant; }
static function setSHM($name, $config) { SHM::put($name, $config); }
/** * Get an instance from the code * * @param string $code Code * * @return self **/ static function get($code) { if (!$code) { return new self(); } if ($hierarchie = SHM::get("hierarchie_{$code}")) { return $hierarchie; } $hierarchie = new self(); $hierarchie->load($code); SHM::put("hierarchie_{$code}", $hierarchie); return $hierarchie; }
} CApp::$chrono->stop(); CApp::preparePerformance(); // Unlocalized strings if (!$suppressHeaders || $ajax) { CAppUI::$unlocalized = array_map("utf8_encode", CAppUI::$unlocalized); $unloc = new CSmartyDP("modules/system"); $unloc->display("inc_unlocalized_strings.tpl"); } // Inclusion du footer if (!$suppressHeaders) { //$address = get_remote_address(); if ($infosystem = CAppUI::pref("INFOSYSTEM")) { $latest_cache_key = "{$user->_guid}-latest_cache"; $latest_cache = array("meta" => array("module" => $m, "action" => $action, "user" => $user->_view), "totals" => Cache::$totals, "hits" => Cache::$hits); SHM::put($latest_cache_key, $latest_cache, true); } $tplFooter = new CSmartyDP("style/{$uistyle}"); $tplFooter->assign("offline", false); $tplFooter->assign("performance", CApp::$performance); $tplFooter->assign("infosystem", $infosystem); $tplFooter->assign("errorMessage", CAppUI::getMsg()); $tplFooter->assign("navigatory_history", CViewHistory::getHistory()); $tplFooter->display("footer.tpl"); } // Ajax performance if ($ajax) { $tplAjax = new CSmartyDP("modules/system"); $tplAjax->assign("performance", CApp::$performance); $tplAjax->assign("requestID", CValue::get("__requestID")); $tplAjax->display("ajax_errors.tpl");
/** * Put a value to the cache * * @param mixed $value The value to set * @param bool $compress Compress data for copy strategy layers * * @return mixed The value, for return chaining */ public function put($value, $compress = false) { $layers = $this->layers; // Inner cache if ($layers & Cache::INNER) { self::$data[$this->prefix][$this->key] = $value; } // Flat key for outer and distributed layers $key = "{$this->prefix}-{$this->key}"; // Outer cache if ($layers & Cache::OUTER) { SHM::put($key, $value, $compress); } // Distributed cache if ($layers & Cache::DISTR) { DSHM::put($key, $value, $compress); } return $value; }
/** * Refresh the data cache * * @return void */ static function refreshDataCache() { $mutex = new CMbFileMutex("config-build"); $mutex->acquire(20); // If cache was built by another thread if (self::getValuesCacheStatus() === self::STATUS_OK) { $mutex->release(); $hosts_shm = SHM::get("config-values-__HOSTS__"); $hosts = $hosts_shm["content"]; $values = array(); foreach ($hosts as $_host) { $_host_value = SHM::get("config-values-{$_host}"); $values[$_host] = $_host_value["content"]; } self::$values = $values; self::$hosts = $hosts; self::$dirty = false; mbLog("'config-values' already present, skipping regeneration"); return; } $t = microtime(true); self::buildAllConfig(); $t1 = microtime(true) - $t; $datetime = strftime(CMbDT::ISO_DATETIME); foreach (self::$values as $_host => $_configs) { SHM::put("config-values-{$_host}", array("date" => $datetime, "content" => $_configs)); } SHM::put("config-values-__HOSTS__", array("date" => $datetime, "content" => array_keys(self::$values))); $t2 = microtime(true) - $t - $t1; mbLog(sprintf("'config-values' gerenated in %f ms, written in %f ms", $t1 * 1000, $t2 * 1000)); $mutex->release(); self::$dirty = false; }
/** * Load locales from cache or build the cache * * @return void */ public static function loadLocales() { $lang = CAppUI::pref("LOCALE", "fr"); self::$lang = $lang; $shared_name = "locales-{$lang}"; $locales_prefixes = SHM::get("{$shared_name}-" . self::LOCALES_PREFIX); // Load from shared memory if possible if ($locales_prefixes) { return; } $mutex = new CMbFileMutex("locales-build"); $mutex->acquire(5); $locales_prefixes = SHM::get("{$shared_name}-" . self::LOCALES_PREFIX); // Load from shared memory if possible if ($locales_prefixes) { $mutex->release(); return; } $locales = array(); foreach (self::getLocaleFilesPaths($lang) as $_path) { include_once $_path; } $locales = CMbString::filterEmpty($locales); foreach ($locales as &$_locale) { $_locale = CMbString::unslash($_locale); } unset($_locale); // Load overwritten locales if the table exists $overwrite = new CTranslationOverwrite(); if ($overwrite->isInstalled()) { $locales = $overwrite->transformLocales($locales, $lang); } // Prefix = everything before "." and "-" $by_prefix = array(); $hashes = array(); foreach ($locales as $_key => $_value) { /** @var string $_prefix */ /** @var string $_rest */ /** @var string $_prefix_raw */ list($_prefix, $_rest, $_prefix_raw) = self::splitLocale($_key); if (!isset($by_prefix[$_prefix])) { $hashes[$_prefix] = $_prefix_raw; $by_prefix[$_prefix] = array(); } $by_prefix[$_prefix][$_rest] = $_value; } foreach ($by_prefix as $_prefix => $_locales) { self::$locales[$_prefix] = $_locales; self::$locales_loaded[$_prefix] = true; SHM::put("{$shared_name}-{$_prefix}", $_locales); } SHM::put("{$shared_name}-" . self::LOCALES_PREFIX, $hashes); $mutex->release(); }
/** * Load the list of visible modules * * @param bool $shm Use shared memory * * @return void */ static function loadModules($shm = true) { // @todo Experiment, then remove test if no problem if ($shm) { $modules = SHM::get("modules"); if (!$modules) { $module = new self(); $modules = $module->loadList(null, "mod_ui_order"); SHM::put("modules", $modules); } } else { $module = new self(); $modules = $module->loadList(null, "mod_ui_order"); } /** @var $module CModule */ foreach ($modules as &$module) { $module->checkModuleFiles(); self::$installed[$module->mod_name] =& $module; if ($module->mod_active == 1) { self::$active[$module->mod_name] =& $module; } if ($module->mod_ui_active == 1) { self::$visible[$module->mod_name] =& $module; } if ($module->_files_missing) { self::$absent[$module->mod_name] =& $module; } } }
* * @package Mediboard * @subpackage developpement * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ */ CCanDo::checkRead(); $chrono = new Chronometer(); $chrono->start(); $classes = CApp::getChildClasses("CModelObject"); //$classes = array_keys(CModelObject::$spec); foreach ($classes as $_class) { /** @var CModelObject $object */ $object = new $_class(); $object->makeAllBackSpecs(); $chrono->step("make"); } foreach ($classes as $_class) { $ballot = array("spec" => CModelObject::$spec[$_class], "props" => CModelObject::$props[$_class], "specs" => CModelObject::$specs[$_class], "backProps" => CModelObject::$backProps[$_class], "backSpecs" => CModelObject::$backSpecs[$_class]); SHM::put("ballot-{$_class}", $ballot, true); $chrono->step("put"); } foreach ($classes as $_class) { SHM::get("ballot-{$_class}"); $chrono->step("get"); } // Création du template $smarty = new CSmartyDP(); $smarty->assign("chrono", $chrono); $smarty->display("cache_tester_metamodel.tpl");
/** * Charge une activité par le code * * @param string $code Code d'activité * * @return self */ static function get($code) { if (!$code) { return new self(); } if ($activite = SHM::get("activite_cdarr_{$code}")) { return $activite; } $activite = new self(); $activite->load($code); SHM::put("activite_cdarr_{$code}", $activite); return $activite; }
* $Id: cache_tester_users.php 24615 2014-09-01 10:52:44Z phenxdesign $ * * @package Mediboard * @subpackage developpement * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: 24615 $ */ CCanDo::checkRead(); $chrono = new Chronometer(); $chrono->start(); if (CView::get("purge", "bool default|0")) { SHM::rem("mediusers"); $chrono->step("purge"); } if (!SHM::exists("mediusers")) { $chrono->step("acquire (not yet)"); $mediuser = new CMediusers(); $mediusers = $mediuser->loadListFromType(); $chrono->step("load"); SHM::put("mediusers", $mediusers, true); $chrono->step("put"); } /** @var CMediusers[] $mediusers */ $mediusers = SHM::get("mediusers"); $chrono->step("get"); // Création du template $smarty = new CSmartyDP(); $smarty->assign("mediusers", $mediusers); $smarty->assign("chrono", $chrono); $smarty->display("cache_tester_users.tpl");
/** * Charge une activité par le code * * @param string $code Code d'activité * * @return self */ static function get($code) { if (!$code) { return new self(); } if ($activite = SHM::get("activite_csarr_{$code}")) { $activite->loadRefReference(); $activite->loadRefsModulateurs(); return $activite; } $activite = new self(); $activite->load($code); SHM::put("activite_csarr_{$code}", $activite); $activite->loadRefReference(); $activite->loadRefsModulateurs(); return $activite; }