示例#1
0
    static function createApplication()
    {
        if (NEnvironment::getVariable('baseUri', NULL) === NULL) {
            NEnvironment::setVariable('baseUri', NEnvironment::getHttpRequest()->getUri()->getBaseUri());
        }
        $context = clone NEnvironment::getContext();
        $context->addService('Nette\\Application\\IRouter', 'NMultiRouter');
        if (!$context->hasService('Nette\\Application\\IPresenterLoader')) {
            $context->addService('Nette\\Application\\IPresenterLoader', callback(create_function('', '
				return new NPresenterLoader(NEnvironment::getVariable(\'appDir\'));
			')));
        }
        $application = new NApplication();
        $application->setContext($context);
        $application->catchExceptions = NEnvironment::isProduction();
        return $application;
    }
示例#2
0
文件: loader.php 项目: GE3/GE3
 function loadConfig($file)
 {
     $name = NEnvironment::getName();
     if ($file instanceof NConfig) {
         $config = $file;
         $file = NULL;
     } else {
         if ($file === NULL) {
             $file = $this->defaultConfigFile;
         }
         $file = NEnvironment::expand($file);
         $config = NConfig::fromFile($file, $name);
     }
     if ($config->variable instanceof NConfig) {
         foreach ($config->variable as $key => $value) {
             NEnvironment::setVariable($key, $value);
         }
     }
     $iterator = new RecursiveIteratorIterator($config);
     foreach ($iterator as $key => $value) {
         $tmp = $iterator->getDepth() ? $iterator->getSubIterator($iterator->getDepth() - 1)->current() : $config;
         $tmp[$key] = NEnvironment::expand($value);
     }
     $runServices = array();
     $locator = NEnvironment::getServiceLocator();
     if ($config->service instanceof NConfig) {
         foreach ($config->service as $key => $value) {
             $key = strtr($key, '-', '\\');
             if (is_string($value)) {
                 $locator->removeService($key);
                 $locator->addService($key, $value);
             } else {
                 if ($value->factory) {
                     $locator->removeService($key);
                     $locator->addService($key, $value->factory, isset($value->singleton) ? $value->singleton : TRUE, (array) $value->option);
                 }
                 if ($value->run) {
                     $runServices[] = $key;
                 }
             }
         }
     }
     if (!$config->php) {
         $config->php = $config->set;
         unset($config->set);
     }
     if ($config->php instanceof NConfig) {
         if (PATH_SEPARATOR !== ';' && isset($config->php->include_path)) {
             $config->php->include_path = str_replace(';', PATH_SEPARATOR, $config->php->include_path);
         }
         foreach (clone $config->php as $key => $value) {
             if ($value instanceof NConfig) {
                 unset($config->php->{$key});
                 foreach ($value as $k => $v) {
                     $config->php->{"{$key}.{$k}"} = $v;
                 }
             }
         }
         foreach ($config->php as $key => $value) {
             $key = strtr($key, '-', '.');
             if (!is_scalar($value)) {
                 throw new InvalidStateException("Configuration value for directive '{$key}' is not scalar.");
             }
             if ($key === 'date.timezone') {
                 date_default_timezone_set($value);
             }
             if (function_exists('ini_set')) {
                 ini_set($key, $value);
             } else {
                 switch ($key) {
                     case 'include_path':
                         set_include_path($value);
                         break;
                     case 'iconv.internal_encoding':
                         iconv_set_encoding('internal_encoding', $value);
                         break;
                     case 'mbstring.internal_encoding':
                         mb_internal_encoding($value);
                         break;
                     case 'date.timezone':
                         date_default_timezone_set($value);
                         break;
                     case 'error_reporting':
                         error_reporting($value);
                         break;
                     case 'ignore_user_abort':
                         ignore_user_abort($value);
                         break;
                     case 'max_execution_time':
                         set_time_limit($value);
                         break;
                     default:
                         if (ini_get($key) != $value) {
                             throw new NotSupportedException('Required function ini_set() is disabled.');
                         }
                 }
             }
         }
     }
     if ($config->const instanceof NConfig) {
         foreach ($config->const as $key => $value) {
             define($key, $value);
         }
     }
     if (isset($config->mode)) {
         foreach ($config->mode as $mode => $state) {
             NEnvironment::setMode($mode, $state);
         }
     }
     foreach ($runServices as $name) {
         $locator->getService($name);
     }
     return $config;
 }
示例#3
0
$loader = new NRobotLoader();
$loader->setCacheStorage(new NFileStorage(TEMP_DIR));
$loader->addDirectory(APP_NETTE_DIR);
$loader->addDirectory(LIBS_DIR);
$loader->addDirectory(WWW_DIR . '/require_modules');
$loader->addDirectory(WWW_DIR . '/classes');
//$loader->addDirectory ( WWW_DIR.'/app/models' );
//$loader->addDirectory ( WWW_DIR.'/app/components' );
$loader->register();
// 2b) load configuration from config.ini file
$config = NEnvironment::loadConfig(APP_NETTE_DIR . '/config/config.neon');
$neon = new NConfigNeonAdapter();
$n = $neon->load(APP_NETTE_DIR . '/config/config.db.neon');
$database = $n['common']['parameters'];
foreach ($database as $k => $p) {
    NEnvironment::setVariable($k, $p);
}
//var_dump($d);exit;
//$config = NEnvironment::loadConfig(APP_NETTE_DIR.'/config/config.db.neon');
$session = NEnvironment::getSession();
//$session->setSavePath(APP_NETTE_DIR . '/sessions');
//$session->setExpiration("1 day");
$session->start();
try {
    dibi::connect(NEnvironment::getConfig()->database);
} catch (Exception $e) {
    // echo $e->getMessage();
    echo "Nepodarilo sa pripojit";
    exit;
}
$cache = NEnvironment::getCache();
示例#4
0
 * @copyright  Copyright (c) 2010 John Doe
 * @package    MyApplication
 */
// 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 NDebug for better exception and error visualisation
NDebug::enable(NDebug::DETECT, APP_DIR . '/log/php_error.log', '*****@*****.**');
NEnvironment::getHttpResponse()->enableCompression();
// Load dibi
dibi::connect(NEnvironment::getConfig('database'));
dibi::addSubst('graweb', 'gw2010__');
// Step 3: Configure application
NEnvironment::setVariable("sizes", array(0 => array(880, 330), 1 => array(263, 174), 2 => array(600, 510)));
// 3a) get and setup a front controller
$application = NEnvironment::getApplication();
$application->errorPresenter = 'Front:Error';
$application->catchExceptions = TRUE;
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new NRoute('index.php', array('module' => 'Front', 'presenter' => 'Default'), NRoute::ONE_WAY);
$router[] = new NRoute('', array('module' => 'Front', 'presenter' => 'Default', 'action' => 'default'));
// Presmerovani starych URL
$router[] = new NRoute('internet/<? ceny|postup|sluzby|vyroba>', array('module' => 'Front', 'presenter' => 'Page', 'action' => 'webdesign'), NRoute::ONE_WAY);
$router[] = new NRoute('graficke-navrhy', array('module' => 'Front', 'presenter' => 'Reklama', 'action' => 'grafikaDesign'), NRoute::ONE_WAY);
$router[] = new NRoute('<? venkovni-reklama|reklama/reference/>', array('module' => 'Front', 'presenter' => 'Reklama', 'action' => 'reklama'), NRoute::ONE_WAY);
$router[] = new NRoute('internet/reference/', array('module' => 'Front', 'presenter' => 'Reference', 'action' => 'default'), NRoute::ONE_WAY);
$router[] = new NRoute('<? kontakty|objednavka>', array('module' => 'Front', 'presenter' => 'Page', 'action' => 'kontakt'), NRoute::ONE_WAY);
$router[] = new NRoute('o-nas/kariera.php', array('module' => 'Front', 'presenter' => 'Default', 'action' => 'default'), NRoute::ONE_WAY);