Пример #1
0
 /**
  * @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.enable_cli in your ini file', null, 'ERROR');
             $flag = false;
         }
     } else {
         $cache = new sfFileCache(array('cache_dir' => sfCombineUtility::getCacheDir()));
     }
     if ($flag) {
         if (!class_exists('sfCombine')) {
             $this->logSection('combine', 'Call the task `doctrine:build-model`', null, 'ERROR');
             return false;
         }
         $results = Doctrine::getTable('sfCombine')->findAll();
         foreach ($results as $result) {
             $cache->remove($result->getAssetKey());
         }
         $this->logSection('combine', 'Cleanup cache complete', null, 'INFO');
         $deleted = Doctrine::getTable('sfCombine')->deleteAll();
         $this->logSection('combine', sprintf('Cleanup database complete (%d rows deleted)', $deleted), null, 'INFO');
     }
 }
Пример #2
0
 /**
  * @return  void
  *
  * @see     sfAction
  */
 public function preExecute()
 {
     sfConfig::set('sf_web_debug', false);
     $this->setTemplate('asset');
     // cache
     sfCombineUtility::setCacheHeaders($this->getResponse());
     // gzip
     sfCombineUtility::setGzip();
 }
Пример #3
0
/**
 * @see     javascript_tag_minified
 * @param   string $content
 * @return  string
 */
function style_tag_minified($content = null, array $elementOptions = array())
{
    use_helper('Tag');
    if (null === $content) {
        ob_start();
    } else {
        // minify content
        $content = sfCombineUtility::minifyInlineCss($content);
        if (!isset($elementOptions['type'])) {
            $elementOptions['type'] = 'text/css';
        }
        return content_tag('style', "\n/*" . cdata_section("*/\n{$content}\n/*") . "*/\n", $elementOptions);
    }
}
 /**
  * Get the last modified timestamp for the files in this collection, will
  * return 0 if there are no files or all failed to get last modified timestamp
  *
  * @return  int
  */
 public function getLastModifiedTimestamp()
 {
     $newestTimestamp = 0;
     foreach ($this->getFiles() as $file) {
         $timestamp = sfCombineUtility::getModifiedTimestamp($file, array($this, 'getAssetPath'));
         if ($timestamp > $newestTimestamp) {
             $newestTimestamp = $timestamp;
         }
     }
     return $newestTimestamp;
 }
Пример #5
0
 /**
  * Take a db hash and convert it into an array of files
  *
  * @see getFiles
  */
 public static function getFilesByKey($key, $separator = ' ')
 {
     $base64 = false;
     // try get base64 from cache
     if (function_exists('apc_store') && ini_get('apc.enabled')) {
         $cache = new sfAPCCache();
         $base64 = $cache->get($key);
     }
     if (!$base64) {
         $cache = new sfFileCache(array('cache_dir' => sfCombineUtility::getCacheDir()));
         $base64 = $cache->get($key);
     }
     // check db
     if (!$base64 && class_exists('sfCombine')) {
         $combine = Doctrine::getTable('sfCombine')->find($key);
         $base64 = $combine ? $combine->getFiles() : false;
     }
     return self::getFilesByBase64($base64, $separator);
 }
Пример #6
0
 /**
  * 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
  *                                  sfCombineManager::GROUP_INCLUDE or
  *                                  sfCombineManager::GROUP_EXCLUDE.
  *                                  These dictate whether the group(s) in
  *                                  the previous argument should be marked
  *                                  as used or every group marked as used.
  *                                  Default sfCombineManager::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 sfCombine (otherwise links
  *                outside of sfCombine))
  */
 public function getAssetsByGroup($assets, $combine = true, $groupsUse = null, $groupsUseType = self::GROUP_INCLUDE, $onlyUnusedGroups = true, $markGroupsUsed = true, $assetPathMethod = null)
 {
     $groupData = $this->getGroups();
     $notCombined = $combined = 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] : '';
         if ($groupsUse !== null) {
             if (is_string($groupsUse)) {
                 $groupsUse = array($groupsUse);
             }
             if ($groupsUseType === self::GROUP_INCLUDE) {
                 // only allow specific groups
                 if (!in_array($group, $groupsUse)) {
                     // don't include this group
                     continue;
                 }
             } else {
                 if ($groupsUseType === self::GROUP_EXCLUDE) {
                     // only exclude specific groups
                     if (in_array($group, $groupsUse)) {
                         // don't include this group
                         continue;
                     }
                 }
             }
         }
         // don't output a used group
         if ($onlyUnusedGroups && in_array($group, $this->getUsedGroups())) {
             continue;
         }
         $timestampConfig = sfConfig::get('app_sfCombinePlugin_timestamp', array());
         $timestampEnabled = isset($timestampConfig['enabled']) && $timestampConfig['enabled'];
         if (!$combine || !sfCombineUtility::combinableFile($file, $this->getSkips())) {
             if ($timestampEnabled) {
                 $timestamp = sfCombineUtility::getModifiedTimestamp($file, $assetPathMethod);
             } else {
                 $timestamp = 0;
             }
             // file not combinable
             $notCombined[] = array('files' => $file, 'options' => $options, 'combinable' => false, 'timestamp' => $timestamp);
             unset($assets[$file]);
         } else {
             // get the group this file is in
             $group = array_key_exists($file, $groupData) ? $groupData[$file] : '';
             $combinedFiles = array($file);
             // get timestamp
             if ($timestampEnabled) {
                 $timestamp = sfCombineUtility::getModifiedTimestamp($file, $assetPathMethod);
             } else {
                 $timestamp = 0;
             }
             unset($assets[$file]);
             foreach ($assets as $groupedFile => $groupedOptions) {
                 if (!sfCombineUtility::combinableFile($groupedFile, $this->getSkips()) || $options != $groupedOptions) {
                     continue;
                 }
                 $groupedFileGroup = array_key_exists($groupedFile, $groupData) ? $groupData[$groupedFile] : '';
                 // add this file to this combine
                 if ($group == $groupedFileGroup) {
                     if ($timestampEnabled) {
                         $groupedTimestamp = sfCombineUtility::getModifiedTimestamp($groupedFile, $assetPathMethod);
                         if ($groupedTimestamp > $timestamp) {
                             $timestamp = $groupedTimestamp;
                         }
                     }
                     $combinedFiles[] = $groupedFile;
                     unset($assets[$groupedFile]);
                 }
             }
             $combined[] = array('files' => $combinedFiles, 'options' => $options, 'combinable' => true, 'timestamp' => $timestamp);
         }
     }
     if ($markGroupsUsed) {
         $this->updateUsedGroups($groupsUse, $groupsUseType);
     }
     return array_merge($notCombined, $combined);
 }