context = $context; } /** * generates the library string (core:caja:etc.js) including a checksum of all the * javascript content (?v=) for cache busting * * @param array $features * @return string the list of libraries in core:caja:etc.js?v=checksum> format */ protected function getJsUrl($features) { if (! is_array($features) || ! count($features)) { return 'null'; } $registry = $this->context->getRegistry(); // Given the JsServlet automatically expends the js library, we just need // to include the "leaf" nodes of the features. $ret = $features; foreach ($features as $feature) { $depFeatures = $registry->features[$feature]['deps']; $ret = array_diff($ret, $depFeatures); } $ret = implode(':', $ret); $cache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache'); if (($md5 = $cache->get(md5('getJsUrlMD5'))) === false) { $features = $registry->features; // Build a version string from the md5() checksum of all included javascript // to ensure the client always has the right version $inlineJs = ''; foreach ($features as $feature => $content) { $inlineJs .= $registry->getFeatureContent($feature, $this->context, true); } $md5 = md5($inlineJs); $cache->set(md5('getJsUrlMD5'), $md5); } $ret .= ".js?v=" . $md5; return $ret; } /** * @param Gadget $gadget * @param array $view */ abstract function renderGadget(Gadget $gadget, $view); }