Beispiel #1
0
 /**
  * @return DF_Web_Environment
  */
 public static function singleton()
 {
     if (self::$_singleton == NULL) {
         self::$_singleton = new DF_Web_Environment();
     }
     return self::$_singleton;
 }
Beispiel #2
0
 /**
  * Sets up the Smarty template engine.
  */
 public function initialize($c)
 {
     $config = $this->config();
     $smarty = new Smarty();
     $env = DF_Web_Environment::singleton();
     $app_root = $env->app_root;
     $smarty->template_dir = "{$app_root}/templates";
     $smarty->compile_dir = "{$app_root}/templates_c";
     $smarty->cache_dir = "{$app_root}/smarty/cache";
     if ($tmp = $config['templates_dir']) {
         $smarty->templates_dir = $tmp;
     }
     if ($tmp = $config['compile_dir']) {
         $smarty->compile_dir = $tmp;
     }
     if ($tmp = $config['cache_dir']) {
         $smarty->cache_dir = $tmp;
     }
     if ($tmp = $config['plugins_dir']) {
         if (!is_array($tmp)) {
             $tmp = array($tmp);
         }
         foreach ($tmp as $dir) {
             $smarty->plugins_dir[] = $dir;
         }
     } else {
         $smarty->plugins_dir[] = "{$app_root}/smarty/plugins";
     }
     $smarty->debugging = $config['debugging'];
     $smarty->debugging_ctrl = $config['debugging_ctrl'];
     $smarty->caching = $config['caching'];
     $this->_smarty = $smarty;
 }
Beispiel #3
0
 function testBasePathRoot()
 {
     $env = DF_Web_Environment::singleton();
     $env->base_path = '/utenlandsbolig';
     $c = $this->c;
     $c->setup_base_path('/utenlandsbolig');
     $this->assertEqual('http://localhost/utenlandsbolig/', $c->uri_for('/'));
 }
 function test_madcow_uri_for()
 {
     $env = DF_Web_Environment::singleton();
     $env->base_path = '/utenlandsbolig';
     $c = $this->c;
     $c->setup_base_path('/utenlandsbolig');
     $uri = "madcow:uri_for:/";
     $this->assertEqual($c->resolve_uri($uri), "http://localhost/utenlandsbolig/");
 }
Beispiel #5
0
 private function read_config()
 {
     $env = DF_Web_Environment::singleton();
     $environment = $env->environment;
     $app_root = $env->app_root;
     $basename = self::$basename;
     if ($env->debug) {
         self::$LOGGER->debug("Looking up configuration files in '{$app_root}'");
     }
     # TODO configurable and detect changes by timestamp
     $compiled_file = File::buildPath(array($app_root, "cache", "{$basename}-compiled.php"));
     if (file_exists($compiled_file)) {
         global $config;
         require_once "{$compiled_file}";
         return $config;
     }
     $file = File::buildPath(array($app_root, "{$basename}.yaml"));
     $fileenv = File::buildPath(array($app_root, "{$basename}-{$environment}.yaml"));
     $config = array();
     if (file_exists($file)) {
         if ($env->debug) {
             self::$LOGGER->debug("Loading configuration file: {$file}");
         }
         $loader = new DF_Web_Config_Loader($file);
         $config = array_merge($config, $loader->getConfig());
     }
     if (file_exists($fileenv)) {
         if ($env->debug) {
             self::$LOGGER->log("Loading configuration file: {$fileenv}");
         }
         $loader = DF_Web_Config_Loader($fileenv);
         $config = array_merge($config, $loader->getConfig());
     }
     $struct = "<?php\n \$config = " . var_export($config, 1) . ";";
     file_put_contents($compiled_file, $struct);
     return $config;
 }
Beispiel #6
0
 public static function path_to()
 {
     // app_root should already be suffixed with /
     $home = DF_Web_Environment::singleton()->app_root;
     if (!preg_match('#/$#', $home)) {
         $home .= "/";
     }
     $args = func_get_args();
     if ($args) {
         $home .= join('/', $args);
         if (is_dir($home)) {
             $home .= '/';
         }
     }
     return $home;
 }
Beispiel #7
0
<?php

# index.php
$DIR_SCRIPT = dirname(__FILE__);
$DIR_ROOT = "{$DIR_SCRIPT}/..";
$DIR_LIB = "{$DIR_ROOT}/lib";
set_include_path($DIR_LIB . ':' . get_include_path());
require_once 'DF/Web/Logger.php';
DF_Web_Logger::setActiveLogger('error_log');
require_once 'DF/Scrum.php';
$environment = DF_Web_Environment::singleton();
$environment->app_root = $DIR_ROOT;
$environment->trusted_proxies = 0;
$environment->base_path = dirname($_SERVER['SCRIPT_NAME']);
if (getenv('ENVIRONMENT')) {
    $environment->environment = getenv('ENVIRONMENT');
}
$environment->debug = 1;
# for production
$environment->environment = 'production';
$environment->debug = 0;
$context = new DF_Scrum();
$context->execute();
$context->finalize();
$context = NULL;
#error_log("Memory usage: ".memory_get_peak_usage());
DF_Web_Logger::shutdown();