source: t29-www/lib/loader.php @ 269

Last change on this file since 269 was 269, checked in by sven, 12 years ago

CSS modular sauber verteilt und JS-Loading-Framework generalisiert zu einem OOP RessourceLoader, der sowohl JS als auch CSS vom Verzeichnis einlesen kann, Cachefile erzeugt und mit Hooks sowie Postprozessor verarbeiten kann (etwa fuer Minify, LESS, usw.). Noch nicht ausgiebig getestet.

File size: 1.8 KB
RevLine 
[269]1<?php
2/**
3 * t29 ressource loading system.
4 * Entry point for loading javascript and css style sheet files in a bundled and
5 * compressed manner, including caching.
6 *
7 **/
8
9$lib = dirname(__FILE__);
10$webroot = realpath("$lib/../");  # file path to root of t29 web installation
11
12if(!isset($_GET['type'])) {
13        die("Read manual.");
14}
15
16$types = array('js', 'css'); // mapping position (numeric key) => $conf array position
17$conf = array(
18        'cache_file' => array('compressed.js', 'style.css'),
19        'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"),
20        'glob_pattern' => array('*.js', '*.css'),
21        'content_types' => array('application/javascript', 'text/css'),
22        'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'),
23);
24
25$type = $_GET['type'];
26$typepos = array_search($type, $types);
27if($typepos === FALSE) {
28        die("Illegal type. Valid types are: ". implode($types));
29}
30
31array_walk($conf, function(&$val, $key) use($typepos) { $val = $val[$typepos]; });
32$conf['modules'] = glob($conf['module_dir'] . '/' . $conf['glob_pattern']);
33$conf['debug'] = isset($_GET['debug']); // skip cache and just concat everything
34extract($conf); // for saving long human reading times :D
35// alternative approach for direct extract in global namespace
36// (no more applicable because configuration is given as array to constructor):
37// foreach($conf as $var => $val) { $GLOBALS[$var] = $val[$typepos]; }
38header("Content-Type: $content_types");
39
40require "$lib/cache.php";
41$js_cache = new t29Cache();
42$js_cache->test_files = $modules;
43$js_cache->set_cache_file($webroot, $cache_file);
44if(!$debug) $js_cache->try_cache_and_exit();
45
46# so we are still in the game
47require "$lib/ressourceloader.php";
48$loader = new $class($conf);
49$js_cache->start_cache(array($loader, 'compression_filter'), true);
50$loader->run();
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License