/**
  * Generate the sfDynamics html tags for a given asset type
  */
 protected function generateHtml($type, $ext)
 {
     if (!isset($this->{$type . 's'})) {
         throw new sfDynamicsException('The ' . $type . ' asset type is unknown');
     }
     $renderer = sfDynamics::getRenderer();
     $html = '';
     /* generate useable package array */
     $packages = array();
     foreach (array_keys($this->packages) as $packageName) {
         $packages[$packageName] = $this->getPackage($packageName);
     }
     $assets = $this->{$type . 's'};
     if (sfDynamicsConfig::isGroupingEnabledFor($type) && sfDynamicsConfig::isSupercacheEnabled()) {
         $url = sfDynamicsRouting::supercache_for($packages, $ext);
         $renderer->generateSupercache($url, $packages, $assets, $type);
         $url = call_user_func(array('sfDynamicsConfig', 'get' . ucfirst($ext) . 'Cdn')) . $url;
         $html .= '  ' . $this->getTag($url, $type) . "\n";
     } else {
         foreach ($assets as $asset) {
             $url = $this->controller->genUrl(sfDynamicsRouting::uri_for($asset, $ext));
             $url = call_user_func(array('sfDynamicsConfig', 'get' . ucfirst($ext) . 'Cdn')) . $url;
             $html .= '  ' . $this->getTag($url, $type) . "\n";
         }
     }
     return $html;
 }
 public function generateAssetsHtml()
 {
     $renderer = sfDynamics::getRenderer();
     $html = '';
     /* generate useable package array */
     $packages = array();
     foreach (array_keys($this->packages) as $packageName) {
         $packages[$packageName] = $this->getPackage($packageName);
     }
     foreach (array('javascript' => 'js', 'stylesheet' => 'css') as $type => $ext) {
         $assets = $this->{$type . 's'};
         if (sfDynamicsConfig::isGroupingEnabledFor($type) && sfDynamicsConfig::isSupercacheEnabled()) {
             $url = sfDynamicsRouting::supercache_for($packages, $ext);
             $renderer->generateSupercache($url, $packages, $assets, $type);
             $html .= '  ' . $this->getTag($url, $type) . "\n";
         } else {
             foreach ($assets as $asset) {
                 $url = $this->controller->genUrl(sfDynamicsRouting::uri_for($asset, $ext));
                 $html .= '  ' . $this->getTag($url, $type) . "\n";
             }
         }
     }
     return $html;
 }
 /**
  * generateSupercache - creates supercache file for given packages
  *
  * @param mixed $url
  * @param mixed $packages
  * @param mixed $assets
  * @param mixed $type
  * @return void
  */
 public function generateSupercache($url, $packages, $assets, $type)
 {
     if (!sfDynamicsConfig::isSupercacheEnabled()) {
         throw new BadMethodCallException('Supercache is disabled.');
     }
     if (!file_exists($filename = sfConfig::get('sf_web_dir') . '/' . $url)) {
         $src = '';
         foreach ($packages as $name => $package) {
             if ($renderedSrc = trim($this->getAsset($name, $package, $type))) {
                 $src .= '/* ' . $name . ' */ ' . $renderedSrc . "\n";
             }
         }
         @file_put_contents($filename, $src);
         if (!file_exists($filename)) {
             throw new sfException('Supercache could not be written: ' . $filename);
         }
     }
 }