當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Environment::getName方法代碼示例

本文整理匯總了PHP中Nette\Environment::getName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Environment::getName方法的具體用法?PHP Environment::getName怎麽用?PHP Environment::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\Environment的用法示例。


在下文中一共展示了Environment::getName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadConfig

 /**
  * Loads global configuration from file and process it.
  * @param  string|Nette\Config\Config  file name or Config object
  * @return Nette\Config\Config
  */
 public function loadConfig($file)
 {
     $name = Environment::getName();
     if ($file instanceof Config) {
         $config = $file;
         $file = NULL;
     } else {
         if ($file === NULL) {
             $file = $this->defaultConfigFile;
         }
         $file = Environment::expand($file);
         $config = Config::fromFile($file, $name);
     }
     // process environment variables
     if ($config->variable instanceof Config) {
         foreach ($config->variable as $key => $value) {
             Environment::setVariable($key, $value);
         }
     }
     // expand variables
     $iterator = new \RecursiveIteratorIterator($config);
     foreach ($iterator as $key => $value) {
         $tmp = $iterator->getDepth() ? $iterator->getSubIterator($iterator->getDepth() - 1)->current() : $config;
         $tmp[$key] = Environment::expand($value);
     }
     // process services
     $runServices = array();
     $context = Environment::getContext();
     if ($config->service instanceof Config) {
         foreach ($config->service as $key => $value) {
             $key = strtr($key, '-', '\\');
             // limited INI chars
             if (is_string($value)) {
                 $context->removeService($key);
                 $context->addService($key, $value);
             } else {
                 if ($value->factory) {
                     $context->removeService($key);
                     $context->addService($key, $value->factory, isset($value->singleton) ? $value->singleton : TRUE, (array) $value->option);
                 } elseif (isset($this->defaultServices[$key])) {
                     $context->removeService($key);
                     $context->addService($key, $this->defaultServices[$key], isset($value->singleton) ? $value->singleton : TRUE, (array) $value->option);
                 }
                 if ($value->run) {
                     $runServices[] = $key;
                 }
             }
         }
     }
     // process ini settings
     if (!$config->php) {
         // backcompatibility
         $config->php = $config->set;
         unset($config->set);
     }
     if ($config->php instanceof Config) {
         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) {
             // flatten INI dots
             if ($value instanceof Config) {
                 unset($config->php->{$key});
                 foreach ($value as $k => $v) {
                     $config->php->{"{$key}.{$k}"} = $v;
                 }
             }
         }
         foreach ($config->php as $key => $value) {
             $key = strtr($key, '-', '.');
             // backcompatibility
             if (!is_scalar($value)) {
                 throw new \InvalidStateException("Configuration value for directive '{$key}' is not scalar.");
             }
             if ($key === 'date.timezone') {
                 // PHP bug #47466
                 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':
//.........這裏部分代碼省略.........
開發者ID:JPalounek,項目名稱:IconStore,代碼行數:101,代碼來源:Configurator.php

示例2: Route

<?php

use Nette\Debug;
use Nette\Environment;
use Nette\Application\Route;
use Ormion\Ormion;
require LIBS_DIR . '/Nette/loader.php';
Debug::enable();
Environment::loadConfig();
$application = Environment::getApplication();
Ormion::connect(Environment::getConfig("database"));
$router = $application->getRouter();
$router[] = new Route('<presenter>/<action>/<id>', array('presenter' => 'Homepage', 'action' => 'default', 'id' => NULL));
if (Environment::getName() !== "console") {
    $application->run();
}
開發者ID:janmarek,項目名稱:Ormion,代碼行數:16,代碼來源:bootstrap.php


注:本文中的Nette\Environment::getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。