// db error - dibiDriverException define('OPERATION_FAILED', 'Operation could NOT be performed. Please, try again in few seconds'); // 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'; require LIBS_DIR . '/Custom/utils.php'; require LIBS_DIR . '/Custom/MultiConfig.php'; // set console mode according to host name if (Environment::isConsole()) { if (php_uname('n') === 'CIKINOTAS') { $name = 'console_dev'; } else { $name = 'console_prod'; } Environment::setName($name); } //$config = Environment::loadConfig(); $config = MultiConfig::load(); //$loader = new RobotLoader(); //$loader->autoRebuild = true; // pokud nenajdu třídu, mám se znovusestavit? //dump($loader); //die(); // debug only //Environment::setMode(Environment::PRODUCTION, 1 ); // Step 2: Configure environment // 2a) enable Debug for better exception and error visualisation Debug::$strictMode = TRUE; // determines whether to consider all errors as fatal // todo: v novsej verzii sa predava uz iba adresar, nie nazov suboru Debug::enable('213.215.67.27, 127.0.0.1', Environment::getVariable('logDir') . '/err.log', '*****@*****.**');
<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());
<?php /** * DataGrid example application bootstrap file. * * @author Roman Sklenář * @package DataGrid\Example */ // Step 1: Load Nette Framework if (!is_dir(LIBS_DIR . '/Nette')) { die("Extract Nette Framework to library directory '" . realpath(LIBS_DIR) . "'."); } require_once LIBS_DIR . '/Nette/loader.php'; // Step 2: Configure environment /** 2a) load configuration from config.ini file */ Environment::setName(Environment::DEVELOPMENT); $config = Environment::loadConfig(); /** 2b) check if needed directories are writable */ if (!is_writable(Environment::getVariable('tempDir'))) { die("Make directory '" . realpath(Environment::getVariable('tempDir')) . "' writable!"); } if (!is_writable(Environment::getVariable('logDir'))) { die("Make directory '" . realpath(Environment::getVariable('logDir')) . "' writable!"); } /** 2c) Setup Nette\Debug for better exception and error visualisation */ //Debug::$productionMode = $_SERVER['REMOTE_ADDR'] !== '127.0.0.1'; // admin's computer IP $mode = !Environment::isProduction() && !Environment::getHttpRequest()->isAjax() ? Debug::DEVELOPMENT : Debug::PRODUCTION; Debug::enable($mode, NULL); Debug::$strictMode = TRUE; Debug::$showLocation = TRUE; /** 2d) enable RobotLoader - this allows load all classes automatically */
<h1>Nette\Environment name test</h1> <pre> <?php require_once '../../Nette/loader.php'; /*use Nette\Debug;*/ /*use Nette\Environment;*/ //define('ENVIRONMENT', 'lab'); echo "Name:\n"; Debug::dump(Environment::getName()); try { echo "Setting name:\n"; Environment::setName('lab2'); Debug::dump(Environment::getName()); } catch (Exception $e) { echo get_class($e), ': ', $e->getMessage(), "\n\n"; }