/** * Returns the items for a given page. * * @return Traversable */ public function getItemsByPage($pageNumber) { $pageNumber = $this->normalizePageNumber($pageNumber); if ($this->_cacheEnabled()) { $data = self::$_cache->load($this->_getCacheId($pageNumber)); if ($data !== false) { return $data; } } $offset = ($pageNumber - 1) * $this->getItemCountPerPage(); $items = $this->_adapter->getItems($offset, $this->getItemCountPerPage()); $filter = $this->getFilter(); if ($filter !== null) { $items = $filter->filter($items); } if (!$items instanceof \Traversable) { $items = new \ArrayIterator($items); } if ($this->_cacheEnabled()) { self::$_cache->save($items, $this->_getCacheId($pageNumber), array($this->_getCacheInternalId())); } return $items; }
/** * Initializes metadata. * * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata * information. Returns true if and only if the metadata are loaded from cache. * * @return boolean * @throws \Zend\DB\Table\Exception */ protected function _setupMetadata() { if ($this->metadataCacheInClass() && count($this->_metadata) > 0) { return true; } // Assume that metadata will be loaded from cache $isMetadataFromCache = true; // If $this has no metadata cache but the class has a default metadata cache if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) { // Make $this use the default metadata cache of the class $this->_setMetadataCache(self::$_defaultMetadataCache); } // If $this has a metadata cache if (null !== $this->_metadataCache) { // Define the cache identifier where the metadata are saved //get db configuration $dbConfig = $this->_db->getConfig(); // Define the cache identifier where the metadata are saved $cacheId = md5((isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : null) . (isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : null) . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name); } // If $this has no metadata cache or metadata cache misses if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->load($cacheId))) { // Metadata are not loaded from cache $isMetadataFromCache = false; // Fetch metadata from the adapter's describeTable() method $metadata = $this->_db->describeTable($this->_name, $this->_schema); // If $this has a metadata cache, then cache the metadata if (null !== $this->_metadataCache && !$this->_metadataCache->save($metadata, $cacheId)) { trigger_error('Failed saving metadata to metadataCache', E_USER_NOTICE); } } // Assign the metadata to $this $this->_metadata = $metadata; // Return whether the metadata were loaded from cache return $isMetadataFromCache; }
/** * Internal function for adding translation data * * It may be a new language or additional data for existing language * If $clear parameter is true, then translation data for specified * language is replaced and added otherwise * * @see Zend_Locale * @param array|string $data Translation data * @param string|\Zend\Locale\Locale $locale Locale/Language to add data for, identical with locale identifier, * @see Zend_Locale for more information * @param array $options (optional) Option for this Adapter * @throws \Zend\Translator\Exception * @return \Zend\Translator\Adapter\Adapter Provides fluent interface */ private function _addTranslationData($data, $locale, array $options = array()) { if ($data instanceof Translator\Translator || $data instanceof Adapter) { $options['usetranslateadapter'] = true; if (!empty($locale)) { $data = $data->getMessages($locale); } else { $locales = $data->getList(); foreach ($locales as $locale) { $trans = $data->getMessages($locale); $this->_addTranslationData($trans, $locale, $options); } return $this; } } try { $locale = Locale\Locale::findLocale($locale); } catch (Locale\Exception $e) { throw new Translator\Exception("The given Language '{$locale}' does not exist", 0, $e); } if ($options['clear'] || !isset($this->_translate[$locale])) { $this->_translate[$locale] = array(); } $read = true; if (isset(self::$_cache)) { $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString(); $temp = self::$_cache->load($id); if ($temp) { $read = false; } } if ($options['reload']) { $read = true; } if ($read) { if (!empty($options['usetranslateadapter'])) { $temp = array($locale => $data); } else { $temp = $this->_loadTranslationData($data, $locale, $options); } } if (empty($temp)) { $temp = array(); } $keys = array_keys($temp); foreach ($keys as $key) { if (!isset($this->_translate[$key])) { $this->_translate[$key] = array(); } if (array_key_exists($key, $temp) && is_array($temp[$key])) { $this->_translate[$key] = $temp[$key] + $this->_translate[$key]; } } if ($this->_automatic === true) { $find = new Locale\Locale($locale); $browser = $find->getEnvironment() + $find->getBrowser(); arsort($browser); foreach ($browser as $language => $quality) { if (isset($this->_translate[$language])) { $this->_options['locale'] = $language; break; } } } if ($read and isset(self::$_cache)) { $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString(); self::$_cache->save($temp, $id, array('Zend_Translate')); } return $this; }