/**
  * @return  void
  *
  * @see     sfAction
  */
 public function preExecute()
 {
     sfConfig::set('sf_web_debug', false);
     $this->setTemplate('asset');
     // cache
     sfCombinePlusUtility::setCacheHeaders($this->getResponse());
     // gzip
     sfCombinePlusUtility::setGzip();
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     // initialize database manager
     $databaseManager = new sfDatabaseManager($this->configuration);
     $flag = true;
     if (function_exists('apc_store') && ini_get('apc.enabled')) {
         $cache = new sfAPCCache();
         if (!ini_get('apc.enable_cli')) {
             $this->logSection('combine', 'Check apc.enabled_cli in your ini file', null, 'ERROR');
             $flag = false;
         }
     } else {
         $cache = new sfFileCache(array('cache_dir' => sfCombinePlusUtility::getCacheDir()));
     }
     if ($flag) {
         $results = sfCombinePlus::getAll();
         foreach ($results as $result) {
             $cache->remove($result->getAssetKey());
         }
         $this->logSection('combine', 'Cleanup cache complete', null, 'INFO');
         $deleted = sfCombinePlus::deleteAll();
         $this->logSection('combine', sprintf('Cleanup database complete (%d rows deleted)', $deleted), null, 'INFO');
     }
 }
 /**
  * @see sfCombinePlusUtility::getCacheDir()
  */
 public static function getCacheDir()
 {
     return sfCombinePlusUtility::getCacheDir();
 }
 /**
  * Group the various assets together into an array. Determines which files
  * can be grouped together and the ordering.
  *
  * @param   array $assets           An array of file names
  * @param   bool  $combine          (Optional) Whether to allow combining or
  *                                  not. Default true.
  * @param   mixed $groupsUse        (Optional) A string or array of groups to
  *                                  include or exclude. Null for this to be
  *                                  ignored. Default null.
  * @param   int   $groupsUseType    (Optional) The type of grouping either
  *                                  sfCombinePlusManager::GROUP_INCLUDE or
  *                                  sfCombinePlusManager::GROUP_EXCLUDE.
  *                                  These dictate whether the group(s) in
  *                                  the previous argument should be marked
  *                                  as used or every group marked as used.
  *                                  Default sfCombinePlusManager::GROUP_INCLUDE
  * @param   bool  $onlyUnusedGroups (Optional) Only use unused groups. Default
  *                                  true.
  * @param   bool  $markGroupsUsed   (Optional) Mark the groups that are used
  *                                  as used. Default true.
  * @return  array An array of grouped files ready for combining. Array is in
  *                the form of files => array of file names, options => array
  *                of options for that grouping, combinable => bool (whether
  *                to put the file through sfCombinePlus (otherwise links
  *                outside of sfCombinePlus))
  */
 public function getAssetsByGroup($assets, $combine = true, $groupsUse = null, $groupsUseType = self::GROUP_INCLUDE, $onlyUnusedGroups = true, $markGroupsUsed = true)
 {
     $groupData = $this->getGroups();
     $return = array();
     foreach ($assets as $file => $options) {
         // check asset still needs to be added
         if (!array_key_exists($file, $assets)) {
             continue;
         }
         // get the group this file is in
         $group = array_key_exists($file, $groupData) ? $groupData[$file] : '';
         // work out
         if ($groupsUse !== null) {
             if (is_string($groupsUse)) {
                 $groupsUse = array($groupsUse);
             }
             if ($groupsUseType === self::GROUP_INCLUDE) {
                 // only allow specific groups
                 if (!is_array($groupsUse) || !in_array($group, $groupsUse)) {
                     // don't include this group
                     continue;
                 }
             } else {
                 if ($groupsUseType === self::GROUP_EXCLUDE) {
                     // only exclude specific groups
                     if (is_array($groupsUse) && in_array($group, $groupsUse)) {
                         // don't include this group
                         continue;
                     }
                 }
             }
         }
         // don't output a used group
         if (in_array($group, $this->getUsedGroups())) {
             continue;
         }
         if (!$combine || !sfCombinePlusUtility::combinableFile($file, $this->getSkips())) {
             // file not combinable
             $return[] = array('files' => $file, 'options' => $options, 'combinable' => false);
             unset($assets[$file]);
         } else {
             // get the group this file is in
             $group = array_key_exists($file, $groupData) ? $groupData[$file] : '';
             $combinedFiles = array($file);
             unset($assets[$file]);
             foreach ($assets as $groupedFile => $groupedOptions) {
                 if (!sfCombinePlusUtility::combinableFile($groupedFile, $this->getSkips()) || $options != $groupedOptions) {
                     continue;
                 }
                 $groupedFileGroup = array_key_exists($groupedFile, $groupData) ? $groupData[$groupedFile] : '';
                 // add this file to this combine
                 if ($group == $groupedFileGroup) {
                     $combinedFiles[] = $groupedFile;
                     unset($assets[$groupedFile]);
                 }
             }
             $return[] = array('files' => $combinedFiles, 'options' => $options, 'combinable' => true);
         }
     }
     if ($markGroupsUsed) {
         $this->updateUsedGroups($groupsUse, $groupsUseType);
     }
     return $return;
 }
 /**
  * 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;
 }