/**
  * Outputs the benchamrks from Scaffold to Firebug
  *
  * @return void
  */
 public static function benchmark()
 {
     $system = Scaffold_Benchmark::get('system');
     $flags = Scaffold_Benchmark::get('system.flags');
     $check = Scaffold_Benchmark::get('system.check_files');
     $table = array();
     $table[] = array('Event', 'Time');
     # The benchmark values
     $table[] = array('Total Time', $system['time']);
     $table[] = array('Set Flags', $flags['time']);
     $table[] = array('Parse Files', $check['time']);
     FB::table('Benchmark', $table);
 }
Example #2
0
 /**
  * Parse the CSS. This takes an array of files, options and configs
  * and parses the CSS, outputing the processed CSS string.
  *
  * @param array List of files
  * @param array Configuration options
  * @param string Options
  * @param boolean Return the CSS rather than displaying it
  * @return string The processed css file as a string
  */
 public static function parse($files, $config, $options = array(), $display = false)
 {
     # Benchmark will do the entire run from start to finish
     Scaffold_Benchmark::start('system');
     try {
         # Setup the cache and other variables/constants
         Scaffold::setup($config);
         self::$options = $options;
         $css = false;
         # Time it takes to get the flags
         Scaffold_Benchmark::start('system.flags');
         # Get the flags from each of the loaded modules.
         $flags = self::$flags === false ? array() : self::flags();
         # Time it takes to get the flags
         Scaffold_Benchmark::stop('system.flags');
         # The final, combined CSS file in the cache
         $combined = md5(serialize(array($files, $flags))) . '.css';
         /**
          * Check if we should use the combined cache right now and skip unneeded processing
          */
         if (SCAFFOLD_PRODUCTION === true and Scaffold_Cache::exists($combined) and Scaffold_Cache::is_fresh($combined)) {
             Scaffold::$output = Scaffold_Cache::open($combined);
         }
         if (Scaffold::$output === null) {
             # We're processing the files
             Scaffold_Benchmark::start('system.check_files');
             foreach ($files as $file) {
                 # The time to process a single file
                 Scaffold_Benchmark::start('system.file.' . basename($file));
                 # Make sure this file is allowed
                 if (substr($file, 0, 4) == "http" or substr($file, -4, 4) != ".css") {
                     Scaffold::error('Scaffold cannot the requested file - ' . $file);
                 }
                 /**
                  * If there are flags, we'll include them in the filename
                  */
                 if (!empty($flags)) {
                     # Webligo PHP5.1 compat
                     $cached_file = dirname($file) . DIRECTORY_SEPARATOR . substr(basename($file), 0, strrpos(basename($file), '.')) . '_' . implode('_', $flags) . '.css';
                     # $cached_file = dirname($file) . DIRECTORY_SEPARATOR . pathinfo($file, PATHINFO_FILENAME) . '_' . implode('_', $flags) . '.css';
                 } else {
                     $cached_file = $file;
                 }
                 $request = Scaffold::find_file($file, false, true);
                 /**
                  * While not in production, we want to to always recache, so we'll fake the time
                  */
                 $modified = SCAFFOLD_PRODUCTION ? Scaffold_Cache::modified($cached_file) : 0;
                 /**
                  * If the CSS file has been changed, or the cached version doesn't exist
                  */
                 if (!Scaffold_Cache::exists($cached_file) or $modified < filemtime($request)) {
                     Scaffold_Cache::write(Scaffold::process($request), $cached_file);
                     Scaffold_Cache::remove($combined);
                 }
                 $css .= Scaffold_Cache::open($cached_file);
                 # The time it's taken to process this file
                 Scaffold_Benchmark::stop('system.file.' . basename($file));
             }
             Scaffold::$output = $css;
             /**
              * If any of the files have changed we need to recache the combined
              */
             if (!Scaffold_Cache::exists($combined)) {
                 Scaffold_Cache::write(self::$output, $combined);
             }
             # The time it takes to process the files
             Scaffold_Benchmark::stop('system.check_files');
             /**
              * Hook to modify what is sent to the browser
              */
             if (SCAFFOLD_PRODUCTION === false) {
                 Scaffold::hook('display');
             }
         }
         /**
          * Set the HTTP headers for the request. Scaffold will set
          * all the headers required to score an A grade on YSlow. This
          * means your CSS will be sent as quickly as possible to the browser.
          */
         $length = strlen(Scaffold::$output);
         $modified = Scaffold_Cache::modified($combined);
         $lifetime = SCAFFOLD_PRODUCTION === true ? $config['cache_lifetime'] : 0;
         Scaffold::set_headers($modified, $lifetime, $length);
         /** 
          * If the user wants us to render the CSS to the browser, we run this event.
          * This will send the headers and output the processed CSS.
          */
         if ($display === true) {
             Scaffold::render(Scaffold::$output, $config['gzip_compression']);
         }
         # Benchmark will do the entire run from start to finish
         Scaffold_Benchmark::stop('system');
     } catch (Exception $e) {
         /** 
          * The message returned by the error 
          */
         $message = $e->getMessage();
         /** 
          * Load in the error view
          */
         if (SCAFFOLD_PRODUCTION === false && $display === true) {
             Scaffold::send_headers();
             require Scaffold::find_file('scaffold_error.php', 'views');
         }
     }
     # Log the final execution time
     #$benchmark = Scaffold_Benchmark::get('system');
     #Scaffold_Log::log('Total Execution - ' . $benchmark['time']);
     # Save the logs and exit
     Scaffold_Event::run('system.shutdown');
     return self::$output;
 }