Ejemplo n.º 1
0
 /**
  * Write all packages specified in $configFile to $outputDir.
  * The default $configFile is "$STUDIP_BASE_PATH/config/assets.yml"
  *
  * @param string $configFile  path to the config file
  * @param string $outputDir   path to the output directory
  */
 function packageAll($configFile = NULL, $outputDir = NULL)
 {
     global $STUDIP_BASE_PATH;
     $configFile = $configFile ?: "{$STUDIP_BASE_PATH}/config/assets.yml";
     $configuration = Configuration::load($configFile, $forced = TRUE);
     $packager = new Packager($configuration);
     $packager->cacheAll($outputDir);
     $compressor = new Compressor($configuration);
     if (is_array($configuration['css'])) {
         $compress = $compressor->shouldCompress();
         if ($compress && !$compressor->hasJava()) {
             $compress = false;
             error_log('CSS could not be compressed, since Java is missing.');
         }
         $config_time = filemtime($configFile);
         foreach ($configuration['css'] as $package => $files) {
             foreach (array_keys($files) as $file) {
                 $src = $configuration['assets_root'] . '/stylesheets/' . $file;
                 $dest = $configuration['package_path'] . '/' . $package . '-' . $file;
                 if (!file_exists($dest) || max($config_time, filemtime($src)) > filemtime($dest)) {
                     $contents = file_get_contents($src);
                     if ($compress) {
                         $contents = $compressor->callCompressor($contents, 'css');
                     }
                     file_put_contents($dest, $contents);
                 }
             }
         }
     }
 }