public function execute($filterChain)
 {
     // Create a function cache object for the QubitSettings method call
     $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings'));
     // Get settings (from cache if exists)
     if ($cache->has('settings')) {
         $settings = unserialize($cache->get('settings'));
     } else {
         $settings = QubitSetting::getSettingsArray();
         $cache->set('settings', serialize($settings));
     }
     // Overwrite/populate settings into sfConfig object
     sfConfig::add($settings);
     // Execute next filter
     $filterChain->execute();
 }
 protected function serve($file_info)
 {
     $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . 'cache'));
     if ($file_info->getIsCached() && $cache->has($file_info->getId(), 'uploaded_files')) {
         $file_data = new FileData();
         $file_data->setBinaryData($cache->get($file_info->getId(), 'uploaded_files'));
     } else {
         $file_data = $file_info->getFileData();
         $cache->set($file_info->getId(), 'uploaded_files', fread($file_data->getBinaryData(), $file_info->getSize()));
         $file_info->setIsCached(true);
         $file_info->save();
     }
     sfConfig::set('sf_web_debug', false);
     //              $this->getResponse()->addHttpMeta('content-type', $file_info->getMime());
     //              $this->getResponse()->addHttpMeta('content-length', $file_info->getSize());
     return $file_data;
 }
 protected function serve()
 {
     //get an instance of the file cache object. We grab the web root then get the name of the cache folder
     //we don't want to use sf_cache_dir because that is application and environment specific
     //we don't want to a path relative to sf_web_dir because the sf_root_dir can be changed, better to start from there
     $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir') . "/" . sfCombineFilter::PACK_CACHE_FOLDER));
     //Next we see if we can pull the file from the cache.
     if ($cache->has($this->cacheFileName)) {
         //Ok! We have a cached copy of the file!
         $this->data = $cache->get($this->cacheFileName);
         $this->mimeType = 'text/' . $this->type;
         $this->size = strlen($this->data);
     } else {
         //cached copy wasn't found, return 404
         $this->forward404('Cache file not found!!! ' . $this->cacheFileName);
     }
 }
 /**
  * Method to generate the final output of the collated files. It adds each
  * minified chunk to a file cache
  *
  * @param   bool  $minify             (Optional) Whether to minify output
  * @param   array $minifySkipSuffixes (Optional) if minify is allowed a
  *                                    suffix of file endings to skip
  *                                    (basically extensions like .min.js)
  * @param   array $minifySkip         (Optional) An array of filenames that
  *                                    should not be minified
  * @return  string
  */
 protected function _generateOutput($minify = false, $minifySkipSuffixes = array(), $minifySkip = array())
 {
     $minifiable = $this->_groupMinifableFiles($minify, $minifySkipSuffixes, $minifySkip, $this->getConfigOption('group_files', true));
     $cache = false;
     if ($this->getConfigOption('cache_minified_files', false)) {
         $cache = new sfFileCache(array('cache_dir' => $this->getCacheDir()));
     }
     $output = '';
     $fileNameComments = $this->getConfigOption('filename_comments', false);
     foreach ($minifiable as $files) {
         if ($fileNameComments) {
             if ($output) {
                 $output .= PHP_EOL;
             }
             $output .= $this->_addFilenameComments($files['files']);
         }
         if (!$files['minify']) {
             $output .= $files['contents'] . PHP_EOL;
         } else {
             $minifiedContents = false;
             if ($cache) {
                 $key = sha1($files['contents']);
                 if ($cache->has($key)) {
                     $minifedContents = $cache->get($key);
                 }
             }
             if ($minifiedContents === false) {
                 $minifiedContents = $this->minify($files['contents']);
             }
             $output .= $minifiedContents . PHP_EOL;
             if ($cache) {
                 if (!$cache->has($key)) {
                     $cache->set($key, $minifiedContents);
                 }
             }
         }
     }
     return $output;
 }
 /**
  * Return a hash which refers to an entry in the db describing the files
  *
  * @see getFileString
  */
 public static function getKey(array $files, $separator = ' ')
 {
     $content = self::getBase64($files, $separator);
     $key = sha1($content);
     $check = false;
     if (function_exists('apc_store') && ini_get('apc.enabled')) {
         $cache = new sfAPCCache();
         $check = $cache->has($key);
     } else {
         $cache = new sfFileCache(array('cache_dir' => sfCombineUtility::getCacheDir()));
         $check = $cache->has($key);
     }
     // Checks if key exists
     if (false === $check) {
         // now just doctrine
         if (!class_exists('sfCombine')) {
             throw new Exception('Call the task `doctrine:build-model` or use base64 url');
         }
         $keyExists = Doctrine::getTable('sfCombine')->find($key);
         if (!$keyExists) {
             $combine = new sfCombine();
             $combine->setAssetKey($key);
             $combine->setFiles($content);
             $combine->save();
         }
         $cache->set($key, $content);
     }
     return $key;
 }
 /**
  * Returns true if there is a cache for the given id and namespace.
  *
  * @param  string  The cache id
  * @param  string  The name of the cache namespace
  * @param  boolean If set to true, the cache validity won't be tested
  *
  * @return boolean true if the cache exists, false otherwise
  *
  * @see sfCache
  */
 public function has($id, $namespace = self::DEFAULT_NAMESPACE, $doNotTestCacheValidity = false)
 {
     list($path, $file) = $this->getFileName($id, $namespace);
     try {
         $std = self::$mem[$this->bucket]->get($path . $file);
         if ($std instanceof Stdclass) {
             return true;
         } else {
             throw new Exception('Could not find cache');
         }
     } catch (Exception $e) {
         return parent::has($id, $namespace, $doNotTestCacheValidity);
     }
 }
/**
 * Returns a key which combined all assets file
 *
 * @return string md5
 */
function _get_key($files)
{
    $content = base64_encode(serialize($files));
    $key = md5($content . sfConfig::get('app_sfCombinePlugin_asset_version', ''));
    if (!class_exists('DbFinder')) {
        throw new Exception('sfCombine expects DbFinder to call combined asset file');
    }
    if (function_exists('apc_store') && ini_get('apc.enabled')) {
        $cache = new sfAPCCache();
        // FIXME: APCCache "has" method doesn't work
        $checkFunction = apc_fetch($key);
    } else {
        $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir') . '/combiners'));
        $checkFunction = $cache->has($key);
    }
    // Checks if key exists
    if (false === $checkFunction) {
        $keyExists = DbFinder::from('sfCombine')->where('AssetsKey', $key)->count();
        if (!$keyExists) {
            $combine = new sfCombine();
            $combine->setAssetsKey($key);
            $combine->setFiles($content);
            $combine->save();
        }
        $cache->set($key, true);
    }
    return $key;
}
 /**
  * Return a hash which refers to an entry in the db describing the files
  *
  * Based off the sfCombine _getKey method
  *
  * @see getFileString
  */
 public static function getKey(array $files, $separator = ' ')
 {
     $content = self::getBase64($files, $separator);
     $key = sha1($content);
     $check = false;
     if (function_exists('apc_store') && ini_get('apc.enabled')) {
         $cache = new sfAPCCache();
         $check = $cache->has($key);
     } else {
         $cache = new sfFileCache(array('cache_dir' => sfCombinePlusUtility::getCacheDir()));
         $check = $cache->has($key);
     }
     // Checks if key exists
     if (false === $check) {
         // now just doctrine
         $keyExists = sfCombinePlus::hasKey($key);
         if (!$keyExists) {
             $combine = new sfCombinePlus();
             $combine->setAssetKey($key);
             $combine->setFiles($content);
             $combine->save();
         }
         $cache->set($key, $content);
     }
     return $key;
 }