/** * Get class info by id * @param integer $id * @param string $lanuage * @param integer $version, optional (last localization if not set) * @return array */ protected function getClassInfo($id, $language, $vers = false) { if ($this->cache) { $cacheKey = $this->getCacheKey($id, $language, $vers); $data = $this->cache->load($cacheKey); if (!empty($data)) { return $data; } } $classModel = Model::factory('sysdocs_class'); $info = $classModel->getItem($id); if (empty($info)) { return array(); } $desc = $this->findLocale('sysdocs_class', 'description', $language, $info['hid'], $vers); if (empty($desc)) { $desc = nl2br($info['description']); } $result = array('object_id' => $info['id'], 'hid' => $info['hid'], 'name' => $info['name'], 'extends' => $info['extends'], 'itemType' => $info['itemType'], 'abstract' => $info['abstract'], 'deprecated' => $info['deprecated'], 'implements' => $info['implements'], 'hierarchy' => array(), 'description' => $desc, 'properties' => $this->getClassProperties($id, $language), 'methods' => $this->getClassMethods($id, $language)); if (!empty($info['parentId'])) { $tree = $classModel->getTree($info['vers']); $parentList = $tree->getParentsList($id); $parentList[] = $id; if (!empty($parentList)) { $classObject = new stdClass(); $classObject->id = $info['id']; $classObject->text = $info['name']; //$classObject->leaf = true; $classObject->expanded = true; $classObject->iconCls = 'emptyIcon'; foreach ($parentList as $k => $id) { $cdata = $tree->getItem($id); $object = new stdClass(); $object->id = $cdata['id']; $object->text = $cdata['data']; // $object->leaf = true; $object->expanded = true; $object->iconCls = 'emptyIcon'; $parentList[$k] = $object; } $base = false; $curObject = false; foreach ($parentList as $item) { if (!$base) { $base = $item; $curObject = $base; continue; } $tmp = $curObject; $tmp->children = $item; $curObject = $item; } } $result['hierarchy'] = $base; } if ($this->cache) { $this->cache->save($cacheKey, $result); } return $result; }
/** * Get a hash for the file list. Used to check for changes in files. * @param array $files - File paths relative to the document root directory * @return string */ protected function _getFileHash($array) { $listHash = md5(serialize($array)); /* * Checking if hash is cached * (IO operations is too expensive) */ if (self::$_cache) { $dataHash = self::$_cache->load($listHash); if ($dataHash) { return $dataHash; } } $dataHash = ''; foreach ($array as $file) { $paramsPos = strpos($file, '?', true); if ($paramsPos !== false) { $file = substr($file, 0, $paramsPos); } $dataHash .= $file . ':' . filemtime(self::$_docRoot . '/' . $file); } if (self::$_cache) { self::$_cache->save(md5($dataHash), $listHash, array('jsFilesHash'), null); } return md5($dataHash); }
/** * Template Render * @param string $path β the path to the template file * @return string */ public function render($path) { $hash = ''; if ($this->_cache && $this->_useCache) { $hash = md5('tpl_' . $path . '_' . serialize($this->_data)); $html = $this->_cache->load($hash); if ($html !== false) { return $html; } } ob_start(); include $path; $result = ob_get_clean(); if ($this->_cache && $this->_useCache) { $this->_cache->save($result, $hash); } return $result; }
/** * @param array $blockItems */ protected function _invalidateBlockList(array $blockItems) { if (!$this->_cache) { return; } if (empty($blockItems)) { return; } $blockIds = Utils::fetchCol('id', $blockItems); $blockMapping = Model::factory('Blockmapping'); $pageBlocks = $blockMapping->getList(false, array('block_id' => $blockIds), array('page_id', 'block_id')); if (empty($pageBlocks)) { return; } /* * Reset block config for pages */ $pages = array_unique(Utils::fetchCol('page_id', $pageBlocks)); foreach ($pages as $id) { if ($id == 0 || empty($id)) { $this->invalidateDefaultMap(); } $this->_cache->remove($this->hashPage($id)); $this->_cache->remove($this->_hashMap($id)); } unset($pages); $sortedPageBlocks = Utils::groupByKey('block_id', $pageBlocks); $pagesModel = Model::factory('Page'); $defaultMapped = $pagesModel->getPagesWithDefaultMap(); /* * Reset cache for all blocks with current menu on all pages */ foreach ($blockItems as $v) { if (!strlen($v['sys_name'])) { $this->_cache->remove($this->getCacheKey(self::DEFAULT_BLOCK, $v)); continue; } if (!isset($sortedPageBlocks[$v['id']]) || empty($sortedPageBlocks[$v['id']])) { continue; } foreach ($sortedPageBlocks[$v['id']] as $pageToBlock) { if ($v['sys_name']::dependsOnPage) { $v['page_id'] = $pageToBlock['page_id']; if ($v['page_id'] == 0) { foreach ($defaultMapped as $pId) { $cfg = $v; $cfg['page_id'] = $pId; $this->_cache->remove($this->getCacheKey($v['sys_name'], $cfg)); } } } $this->_cache->remove($this->getCacheKey($v['sys_name'], $v)); } } }
/** * Cache data again * @property $key - optional * @return void */ public static function cache($key = false) { if (!self::$_cache) { return; } if ($key === false) { foreach (self::$_store as $k => $v) { self::$_cache->save($v, $k); } } else { if (self::$_store->keyExists($key)) { self::$_cache->save(self::$_store->get($key), $key); } } }
/** * Get data hash (all dictionaries data) * Enter description here ... */ public function getDataHash() { if ($this->_cache && ($hash = $this->_cache->load(self::CACHE_KEY_DATA_HASH))) { return $hash; } $s = ''; $list = $this->getList(); if (!empty($list)) { foreach ($list as $name) { $s .= $name . ':' . Dictionary::getInstance($name)->__toJs(); } } $s = md5($s); if ($this->_cache) { $this->_cache->save($s, self::CACHE_KEY_DATA_HASH); } return $s; }