本文整理汇总了PHP中Environment::loadConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::loadConfig方法的具体用法?PHP Environment::loadConfig怎么用?PHP Environment::loadConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::loadConfig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* 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:
<?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: Route
<?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: createService
<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());