public function __construct($id)
 {
     $this->dir = luminous::root() . '/cache/';
     $this->subdir = substr($id, 0, 2);
     $this->filename = substr($id, 2);
     $this->path = rtrim($this->dir, '/') . '/' . $this->subdir . '/' . $this->filename;
     parent::__construct($id);
 }
Esempio n. 2
0
 public function __construct($id)
 {
     $this->dir = luminous::root() . '/cache/';
     $this->path = $this->dir . '/' . $id;
     parent::__construct($id);
 }
Esempio n. 3
0
/**
 * \ingroup LuminousEasyAPI
 * \brief Simple call to luminous with language grammar
 * 
 * \param grammar The grammar to use to parse the string, as LuminousGrammar
 * \param src the source string to be formatted (string)
 * \param use_cache determines whether to use the caching system, 
 *    default is true. (true|false)
 * \return an HTML formatted piece of text representing the input string
 * \throw Exception if luminous encounters a fatal error (a more descriptive
 *    string will be set as its message)
 * \see Luminous
 * \see LuminousEasyAPI::$luminous_grammars
 */
function luminous_grammar(LuminousGrammar $grammar, $src, $use_cache = true)
{
    global $LUMINOUS_PERFORMANCE_LOG;
    $start = microtime(true);
    $perf_log = array();
    $perf_log['language'] = $grammar->info['language'];
    $perf_log['input_size'] = strlen($src);
    $perf_log['cache_time'] = 0.0;
    $o = false;
    $cache = null;
    if ($use_cache) {
        $c_t = microtime(true);
        // the cache's unique ID needs to be an alagamation of the input source,
        // grammar, and highlighting settings.
        $md5 = md5($src);
        $id = md5($md5 . serialize($grammar->info));
        $id = md5($id . serialize(luminous_create_settings()));
        $cache = new LuminousCache($id, $md5);
        $cache->version = $GLOBALS['LUMINOUS_VERSION'];
        $cache->cache_max_age = $GLOBALS['LUMINOUS_MAX_AGE'];
        $cache->purge_time = $GLOBALS['LUMINOUS_PURGE_TIME'];
        $cache->Purge();
        $o = $cache->ReadCache();
        $GLOBALS['LUMINOUS_WAS_CACHED'] = true;
        $perf_log['cached'] = true;
        $perf_log['parse_time'] = 0.0;
        $perf_log['format_time'] = 0.0;
        $perf_log['cache_time'] = microtime(true) - $c_t;
    }
    if ($o === false) {
        $perf_log['cached'] = false;
        $GLOBALS['LUMINOUS_WAS_CACHED'] = false;
        $p_start = microtime(true);
        $l = new Luminous();
        $l->verbosity = $GLOBALS['LUMINOUS_HIGHLIGHTING_LEVEL'];
        $l->pre_escaped = !$GLOBALS['LUMINOUS_ESCAPE_INPUT'];
        $l->separate_lines = $GLOBALS['LUMINOUS_LINE_NUMBERS'];
        $o = $l->Easy_Parse($src, $grammar);
        $p_end = microtime(true);
        $f_start = microtime(true);
        $f = luminous_get_formatter();
        //       $f = new LuminousFormatterHTML();
        $f->SetTheme(luminous_get_theme());
        $f->wrap_length = $GLOBALS['LUMINOUS_WRAP_WIDTH'];
        $f->line_numbers = $GLOBALS['LUMINOUS_LINE_NUMBERS'];
        $f->link = $GLOBALS['LUMINOUS_LINK_URIS'];
        $f->height = $GLOBALS['LUMINOUS_WIDGET_HEIGHT'];
        // this really shouldn't be here.
        if ($grammar instanceof LuminousGrammarWhitespace) {
            $f->tab_width = -1;
        }
        $o = $f->Format($o);
        $f_end = microtime(true);
        if ($use_cache) {
            $cache->WriteCache($o);
        }
        $perf_log['format_time'] = $f_end - $f_start;
        $perf_log['parse_time'] = $p_end - $p_start;
    }
    $end = microtime(true);
    $perf_log['time'] = $end - $start;
    $perf_log['output_size'] = strlen($o);
    $LUMINOUS_PERFORMANCE_LOG[] = $perf_log;
    return $o;
}