예제 #1
0
 /**
  * merges config files of each module imported via config.ini[modules] to one file and loads it
  * considering current environment [dev, production, ...] - separate config file for each
  * uses Nette/Cache for invalidation when one (or more) of config files changed
  *
  * @param string|null  filepath
  * @return Config
  */
 public static function load($baseConfigFile = null)
 {
     if ($baseConfigFile === null) {
         $baseConfigFile = Environment::expand(Environment::getConfigurator()->defaultConfigFile);
     }
     $envName = Environment::getName();
     Environment::setVariable('tempDir', VAR_DIR . '/cache');
     $cache = Environment::getCache('config');
     $key = "config[{$envName}]";
     if (!isset($cache[$key])) {
         // najviac casu zabera load, tak az tu, ked ho je treba
         $appConfig = Environment::loadConfig($baseConfigFile);
         $configs = array(Config::fromFile($baseConfigFile, $envName)->toArray());
         $configPaths = array($baseConfigFile);
         foreach ($appConfig->modules as $c) {
             $configPaths[] = $path = MODULES_DIR . "/{$c}Module/config.ini";
             if (file_exists($path)) {
                 $configs[] = Config::fromFile($path, $envName)->toArray();
             }
         }
         $arrayConfig = call_user_func_array('array_merge_recursive', $configs);
         $cache->save($key, $arrayConfig, array('files' => $configPaths));
     }
     return Environment::loadConfig(new Config($cache[$key]));
 }
예제 #2
0
파일: bootstrap.php 프로젝트: bazo/Mokuji
<?php

require LIBS_DIR . '/nette-dev/loader.php';
require LIBS_DIR . '/debug.php';
require LIBS_DIR . '/Mokuji/Mokuji.php';
//enable Debugging
//Environment::setMode(Environment::DEVELOPMENT);
//Debug::enable(Debug::DEVELOPMENT);
//load configuration
Environment::loadConfig(APP_DIR . '/config/config.ini');
Environment::setVariable('website', WEBSITE);
db::connect(Environment::getConfig('database'));
//get Application
Environment::getSession()->start();
$app = Environment::getApplication();
$app->catchExceptions = FALSE;
$app->run();
예제 #3
0
<?php

/**
 * Nette TreeView example bootstrap file.
 *
 * @copyright  Copyright (c) 2010 Roman Novák
 * @package    nette-treeview
 */
// Step 1: Load Nette Framework
// this allows load Nette Framework classes automatically so that
// you don't have to litter your code with 'require' statements
require LIBS_DIR . '/Nette/loader.php';
// Step 2: Configure environment
// 2a) enable Nette\Debug for better exception and error visualisation
Debug::enable(false);
Debug::enableProfiler();
// 2b) load configuration from config.ini file
Environment::loadConfig();
Environment::getSession()->start();
dibi::connect(Environment::getConfig('database'));
// Step 3: Configure application
// 3a) get and setup a front controller
$application = Environment::getApplication();
//$application->errorPresenter = 'Error';
$application->catchExceptions = false;
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new Route('index.php', array('presenter' => 'Homepage', 'action' => 'default'), Route::ONE_WAY);
$router[] = new Route('<presenter>/<action>/<id>', array('presenter' => 'Homepage', 'action' => 'default', 'id' => NULL));
// Step 5: Run the application!
$application->run();
예제 #4
0
파일: test.config.php 프로젝트: vrana/nette
<h1>Nette\Environment config test</h1>

<pre>
<?php 
require_once '../../Nette/loader.php';
/*use Nette\Debug;*/
/*use Nette\Environment;*/
class Factory
{
    static function createService($options)
    {
        Debug::dump(__METHOD__);
        Debug::dump($options);
        return (object) NULL;
    }
}
echo "Loading config:\n";
Environment::setName(Environment::PRODUCTION);
Environment::loadConfig('config.ini');
echo "Variable foo:\n";
Debug::dump(Environment::getVariable('foo'));
echo "Constant HELLO_WORLD:\n";
Debug::dump(constant('HELLO_WORLD'));
echo "php.ini config:\n";
Debug::dump(Environment::getConfig('php'));
echo "Database config:\n";
Debug::dump(Environment::getConfig('database'));
echo "is production mode?\n";
Debug::dump(Environment::isProduction());