Example #1
0
 /**
  * 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);
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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);
         }
     }
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * Init and render Block object
  * @param array $config
  * @return string
  */
 protected function _renderBlock(array $config)
 {
     $class = self::DEFAULT_BLOCK;
     if ($config['is_system'] && strlen($config['sys_name']) && class_exists($config['sys_name'])) {
         $class = $config['sys_name'];
     }
     /*
      * Check for rendered block cache 
      */
     if ($this->_cache) {
         if ($class::cacheable) {
             if ($class::dependsOnPage) {
                 $config['page_id'] = Page::getInstance()->id;
             }
             $cacheKey = $this->getCacheKey($class, $config);
             $data = $this->_cache->load($cacheKey);
             if ($data) {
                 return $data;
             }
         } else {
             $this->_hasNoCacheBblock = true;
         }
     }
     $blockObject = new $class($config);
     if (!$blockObject instanceof Block) {
         trigger_error('Invalid block class');
     }
     $html = $blockObject->render();
     if ($class::cacheable && $this->_cache) {
         if (self::$_useHardCacheLifetime) {
             $this->_cache->save($html, $cacheKey, Registry::get('main', 'config')->get('frontend_hardcache'));
         } else {
             $this->_cache->save($html, $cacheKey);
         }
     }
     return $html;
 }