/**
  * Combines and compresses all inline scripts at the specified position. 
  * The combined contents is stored as a file in the assets folder so that 
  * the combination only happens when the contents change.
  * @param int $position the position of the scripts
  * @throws Exception if the combined script file can't be created
  */
 private function combineInlineScripts($position)
 {
     if (!isset($this->scripts[$position])) {
         return;
     }
     $scriptHash = md5(serialize(array_values($this->scripts[$position])));
     $combinedScript = \Yii::app()->assetManager->basePath . '/' . $this->combinedScriptPrefix . '-' . $scriptHash . '.js';
     // Create a compressed version of the scripts if it doesn't exist
     if (!file_exists($combinedScript)) {
         $combiner = new Combiner();
         $contents = $combiner->compress(\YUI\Compressor::TYPE_JS, $this->scripts[$position]);
         if (@file_put_contents($combinedScript, $contents) === false) {
             throw new Exception('Failed to compress inline scripts: Could not write to file ' . $combinedScript);
         }
     }
     // Replace the originals
     $this->scripts[$position] = array($scriptHash => file_get_contents($combinedScript));
 }
 /**
  * Class constructor
  * @param string $filePrefix the prefix for combined files
  * @param PathResolver $pathResolver path resolver
  */
 public function __construct($filePrefix, PathResolver $pathResolver)
 {
     $this->filePrefix = $filePrefix;
     $this->pathResolver = $pathResolver;
     parent::__construct();
 }