Changeset 516 in t29-www for lib/host.php


Ignore:
Timestamp:
Feb 19, 2014, 12:39:35 PM (5 years ago)
Author:
sven
Message:

Bug #51 gefixt (http://labs.technikum29.de/ticket/51).
Jetzt sollten neue Pagestyles gleich beim Erstellen erkannt werden.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/host.php

    r362 r516  
    4949        /// This value is computed by setup().
    5050        public $script_filename;
    51        
     51
     52        /// $ressources: CSS and JavaScript file paths ("Assets"), as used by the RessourceLoader,
     53        ///              the loader.php and technikum29.php entry points and the Template.
     54        private function ressources_array($webroot='') {
     55                // this is implemented as method, because of
     56                // 1. "$webbroot/..." like strings. This isn't a good idea anyway (e.g. in ressourceloader: $module_dir_rel2webroot
     57                // 2. Closures: function($conf){...} doesn't work as class attribute.
     58                // This is rather dirty, but anyway the supposed way to access these data is the public get_ressources().
     59                $ressources = array(
     60                        'cache_file' => array('compressed.js', 'style.css'),
     61                        'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"),
     62                        'page_dir' => array("$webroot/shared/js-v6/pagescripts", "$webroot/shared/css-v6/pagestyles"),
     63                        'glob_pattern' => array('*.js', '*.css'),
     64                        'content_types' => array('application/javascript', 'text/css'),
     65                        'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'),
     66                        'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); },
     67                );
     68                return $ressources;
     69        }
     70
     71        /// $ressources_types: The Ressources array above consists of numeric arrays. This array
     72        ///                    maps those positions (numeric keys) to $conf array positions.
     73        ///                    Use get_ressources() to resolve this mapping.
     74        private $ressources_types = array('js', 'css');
     75
     76        public function get_ressources($type, $webroot, $debug_flag=false) {
     77                $typepos = array_search($type, $this->ressources_types);
     78                if($typepos === FALSE) return null;
     79                $conf = array_map(function($val) use($typepos)
     80                        { return is_array($val) ? $val[$typepos] : $val; },
     81                        $this->ressources_array($webroot));
     82                $conf['type'] = $type;
     83                // callback functions need the $conf we built.
     84                $conf['modules'] = call_user_func($conf['modules'], $conf);
     85                $conf['debug'] = $debug_flag; // skip cache and just concat everything
     86                return $conf;
     87        }
     88
     89        /**
     90         * A special helper class, used by t29Template and technikum29.php entry point.
     91         * The general (clean) way would be querying get_ressources().
     92         * There is also t29RessourceLoader::get_page_specific_urls() which basically does
     93         * the same, just using the global conf array.
     94         **/
     95        public function ressources_get_pagestyle($seiten_id) {
     96                // We address the css property directly with the [1] index. Bad!
     97                return $this->ressources_array()['page_dir'][1] . '/' . $seiten_id . '.css';
     98        }
     99
     100        /// Singleton fun for detect()
     101        private static $instance;
     102        private static function new_singleton($classname) {
     103                if(!isset(self::$instance))
     104                        self::$instance = new $classname;
     105                return self::$instance;
     106        }
     107
    52108        /**
    53109         * Factory for creating a t29Host instance automatically
    54110         * from the current host. This method will decide which
    55111         * subclass has to be taken.
     112         * This function als implements the Singleton pattern, so
     113         * you can call it frequently.
    56114         **/
    57115        static function detect() {
     
    64122                        if(class_exists(self::webroot_local_host_classname)) {
    65123                                $x = self::webroot_local_host_classname;
    66                                 $host = new $x;
     124                                $host = self::new_singleton($x);
    67125                                $host->setup();
    68126                                return $host;
     
    76134                        case 'heribert':
    77135                        case 'localhost':
    78                                 $localhost = new t29HeribertHost;
     136                                $localhost = self::new_singleton('t29HeribertHost');
    79137                                $localhost->setup();
    80138                                return $localhost;
    81139                }
    82140               
    83                 $publichost = new t29PublicHost;
     141                $publichost = self::new_singleton('t29PublicHost');
    84142                $publichost->setup();
    85143                return $publichost;
     
    96154         *   2. if this host is *not* installed in its own virtualhost (i.e. on docroot).
    97155         **/
    98         function setup() {
     156        private function setup() {
    99157                $this->is_rewriting_host = isset($_SERVER[self::env_hidesuffix_name]);
    100158               
Note: See TracChangeset for help on using the changeset viewer.
© 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