本文整理汇总了PHP中Environment::getServiceLocator方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getServiceLocator方法的具体用法?PHP Environment::getServiceLocator怎么用?PHP Environment::getServiceLocator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::getServiceLocator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startup
public function startup()
{
parent::startup();
if (!function_exists('lcfirst')) {
function lcfirst($str)
{
$str[0] = strtolower($str[0]);
return $str;
}
}
if (Environment::getServiceLocator()->hasService('User') === false) {
Environment::getServiceLocator()->addService('User', new User());
}
$this->user = Environment::getServiceLocator()->getService('User');
$this->verifyUser();
// Nastaví aktuální identitu do template proměnné user
$this->template->user = $this->user->isLoggedIn() ? $this->user->getIdentity() : NULL;
if (!defined('ERROR_MESSAGE')) {
define('ERROR_MESSAGE', 'System exception occured.');
}
if (!defined('HASH_TYPE')) {
define('HASH_TYPE', 'sha512');
}
}
示例2: _paintBlueScreen
/**
* Paint blue screen.
* @param Exception
* @return void
* @ignore internal
*/
public static function _paintBlueScreen(Exception $exception)
{
$internals = array();
foreach (array('Object', 'ObjectMixin') as $class) {
if (class_exists($class, FALSE)) {
$rc = new ReflectionClass($class);
$internals[$rc->getFileName()] = TRUE;
}
}
if (class_exists('Environment', FALSE)) {
$application = Environment::getServiceLocator()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getServiceLocator()->getService('Nette\\Application\\Application') : NULL;
}
require dirname(__FILE__) . '/templates/bluescreen.phtml';
}
示例3: loadConfig
/**
* Loads global configuration from file and process it.
* @param string|Nette\Config\Config file name or Config object
* @param bool
* @return Nette\Config\Config
*/
public function loadConfig($file, $useCache)
{
if ($useCache === NULL) {
$useCache = Environment::isLive();
}
$cache = $useCache && $this->cacheKey ? Environment::getCache('Nette.Environment') : NULL;
$name = Environment::getName();
$cacheKey = Environment::expand($this->cacheKey);
if (isset($cache[$cacheKey])) {
Environment::swapState($cache[$cacheKey]);
$config = Environment::getConfig();
} else {
if ($file instanceof Config) {
$config = $file;
$file = NULL;
} else {
if ($file === NULL) {
$file = $this->defaultConfigFile;
}
$file = Environment::expand($file);
$config = Config::fromFile($file, $name, 0);
}
// process environment variables
if ($config->variable instanceof Config) {
foreach ($config->variable as $key => $value) {
Environment::setVariable($key, $value);
}
}
if (PATH_SEPARATOR !== ';' && isset($config->set->include_path)) {
$config->set->include_path = str_replace(';', PATH_SEPARATOR, $config->set->include_path);
}
$config->expand();
$config->setReadOnly();
// process services
$locator = Environment::getServiceLocator();
if ($config->service instanceof Config) {
foreach ($config->service as $key => $value) {
$locator->addService($value, strtr($key, '-', '\\'));
}
}
// save cache
if ($cache) {
$state = Environment::swapState(NULL);
$state[0] = $config;
// TODO: better!
$cache->save($cacheKey, $state, array(Cache::FILES => $file));
}
}
// check temporary directory - TODO: discuss
/*
$dir = Environment::getVariable('tempDir');
if ($dir && !(is_dir($dir) && is_writable($dir))) {
trigger_error("Temporary directory '$dir' is not writable", E_USER_NOTICE);
}
*/
// process ini settings
if ($config->set instanceof Config) {
foreach ($config->set as $key => $value) {
$key = strtr($key, '-', '.');
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:
throw new NotSupportedException('Required function ini_set() is disabled.');
}
}
}
}
// define constants
if ($config->const instanceof Config) {
foreach ($config->const as $key => $value) {
define($key, $value);
//.........这里部分代码省略.........
示例4: getServiceLocator
/**
* Gets the service locator (experimental).
* @return IServiceLocator
*/
public final function getServiceLocator()
{
if ($this->serviceLocator === NULL) {
$this->serviceLocator = $this->parent === NULL ? Environment::getServiceLocator() : $this->parent->getServiceLocator();
}
return $this->serviceLocator;
}
示例5: loadConfig
/**
* Loads global configuration from file and process it.
* @param string|Config file name or Config object
* @return 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, 0);
}
// process environment variables
if ($config->variable instanceof Config) {
foreach ($config->variable as $key => $value) {
Environment::setVariable($key, $value);
}
}
$config->expand();
// process services
$runServices = array();
$locator = Environment::getServiceLocator();
if ($config->service instanceof Config) {
foreach ($config->service as $key => $value) {
$key = strtr($key, '-', '\\');
// limited INI chars
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;
}
}
}
}
// 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 ($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':
error_reporting($value);
break;
case 'ignore_user_abort':
ignore_user_abort($value);
break;
case 'max_execution_time':
set_time_limit($value);
break;
//.........这里部分代码省略.........
示例6: UriScript
$config = Environment::getConfig('httpRequest');
// params can be taken from config or command line if needed
$uri = new UriScript();
$uri->scheme = 'http';
$uri->port = Uri::$defaultPorts['http'];
$uri->host = $config->host;
$uri->path = $config->path;
// $uri->path = '/';
$uri->canonicalize();
$uri->path = String::fixEncoding($uri->path);
$uri->scriptPath = '/';
$req = new HttpRequest();
$req->setUri($uri);
return $req;
}
$serviceLocator = Environment::getServiceLocator();
$httpReqServiceName = 'Nette\\Web\\IHttpRequest';
$serviceLocator->removeService($httpReqServiceName);
$serviceLocator->addService($httpReqServiceName, createHttpRequestService());
}
// Step 3: Configure application
// 3a) get and setup a front controller
$application = Environment::getApplication();
$application->errorPresenter = 'Front:Error';
if (Environment::isProduction() && Debug::$productionMode) {
$application->catchExceptions = true;
} else {
$application->catchExceptions = false;
}
dibi::connect(Environment::getConfig("database"));
// Step 4: Setup application router
示例7: onLoad
public function onLoad()
{
Environment::getServiceLocator()->addService('UserAuthenticator', new UsersModuleModel());
}
示例8: getServiceLocator
/**
* Gets the service locator (experimental).
* @return IServiceLocator
*/
public final function getServiceLocator()
{
if ($this->serviceLocator === NULL) {
$this->serviceLocator = new ServiceLocator(Environment::getServiceLocator());
foreach ($this->defaultServices as $name => $service) {
if (!$this->serviceLocator->hasService($name)) {
$this->serviceLocator->addService($name, $service);
}
}
}
return $this->serviceLocator;
}
示例9: _paintBlueScreen
public static function _paintBlueScreen(Exception $exception)
{
$internals = array();
foreach (array('Object', 'ObjectMixin') as $class) {
if (class_exists($class, FALSE)) {
$rc = new ReflectionClass($class);
$internals[$rc->getFileName()] = TRUE;
}
}
if (class_exists('Environment', FALSE)) {
$application = Environment::getServiceLocator()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getServiceLocator()->getService('Nette\\Application\\Application') : NULL;
}
if (!function_exists('_netteDebugPrintCode')) {
function _netteDebugPrintCode($file, $line, $count = 15)
{
if (function_exists('ini_set')) {
ini_set('highlight.comment', '#999; font-style: italic');
ini_set('highlight.default', '#000');
ini_set('highlight.html', '#06b');
ini_set('highlight.keyword', '#d24; font-weight: bold');
ini_set('highlight.string', '#080');
}
$start = max(1, $line - floor($count / 2));
$source = @file_get_contents($file);
if (!$source) {
return;
}
$source = explode("\n", highlight_string($source, TRUE));
$spans = 1;
echo $source[0];
$source = explode('<br />', $source[1]);
array_unshift($source, NULL);
$i = $start;
while (--$i >= 1) {
if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
if ($m[1] !== '</span>') {
$spans++;
echo $m[1];
}
break;
}
}
$source = array_slice($source, $start, $count, TRUE);
end($source);
$numWidth = strlen((string) key($source));
foreach ($source as $n => $s) {
$spans += substr_count($s, '<span') - substr_count($s, '</span');
$s = str_replace(array("\r", "\n"), array('', ''), $s);
if ($n === $line) {
printf("<span class='highlight'>Line %{$numWidth}s: %s\n</span>%s", $n, strip_tags($s), preg_replace('#[^>]*(<[^>]+>)[^<]*#', '$1', $s));
} else {
printf("<span class='line'>Line %{$numWidth}s:</span> %s\n", $n, $s);
}
}
echo str_repeat('</span>', $spans), '</code>';
}
function _netteDump($dump)
{
return '<pre class="nette-dump">' . preg_replace_callback('#(^|\\s+)?(.*)\\((\\d+)\\) <code>#', '_netteDumpCb', $dump) . '</pre>';
}
function _netteDumpCb($m)
{
return "{$m['1']}<a href='#' onclick='return !netteToggle(this)'>{$m['2']}({$m['3']}) " . (trim($m[1]) || $m[3] < 7 ? '<abbr>▼</abbr> </a><code>' : '<abbr>►</abbr> </a><code class="collapsed">');
}
function _netteOpenPanel($name, $collapsed)
{
static $id;
$id++;
?>
<div class="panel">
<h2><a href="#" onclick="return !netteToggle(this, 'pnl<?php
echo $id;
?>
')"><?php
echo htmlSpecialChars($name);
?>
<abbr><?php
echo $collapsed ? '►' : '▼';
?>
</abbr></a></h2>
<div id="pnl<?php
echo $id;
?>
" class="<?php
echo $collapsed ? 'collapsed ' : '';
?>
inner">
<?php
}
function _netteClosePanel()
{
?>
</div>
</div>
<?php
}
}
static $errorTypes = array(E_ERROR => 'Fatal Error', E_USER_ERROR => 'User Error', E_RECOVERABLE_ERROR => 'Recoverable Error', E_CORE_ERROR => 'Core Error', E_COMPILE_ERROR => 'Compile Error', E_PARSE => 'Parse Error', E_WARNING => 'Warning', E_CORE_WARNING => 'Core Warning', E_COMPILE_WARNING => 'Compile Warning', E_USER_WARNING => 'User Warning', E_NOTICE => 'Notice', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated');
$title = $exception instanceof FatalErrorException && isset($errorTypes[$exception->getSeverity()]) ? $errorTypes[$exception->getSeverity()] : get_class($exception);
//.........这里部分代码省略.........
示例10: _paintBlueScreen
/**
* Paint blue screen.
* @param Exception
* @return void
* @ignore internal
*/
public static function _paintBlueScreen(Exception $exception)
{
if (class_exists('Environment', FALSE)) {
$application = Environment::getServiceLocator()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getServiceLocator()->getService('Nette\\Application\\Application') : NULL;
}
require dirname(__FILE__) . '/templates/bluescreen.phtml';
}
示例11: loadConfig
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);
}
if ($config->variable instanceof Config) {
foreach ($config->variable as $key => $value) {
Environment::setVariable($key, $value);
}
}
$iterator = new RecursiveIteratorIterator($config);
foreach ($iterator as $key => $value) {
$tmp = $iterator->getDepth() ? $iterator->getSubIterator($iterator->getDepth() - 1)->current() : $config;
$tmp[$key] = Environment::expand($value);
}
$runServices = array();
$locator = Environment::getServiceLocator();
if ($config->service instanceof Config) {
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 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) {
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, '-', '.');
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 Config) {
//.........这里部分代码省略.........
示例12: loadConfig
/**
* Loads global configuration from file and process it.
* @param string|Nette\Config\Config file name or Config object
* @return 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, 0);
}
// process environment variables
if ($config->variable instanceof Config) {
foreach ($config->variable as $key => $value) {
Environment::setVariable($key, $value);
}
}
$config->expand();
// process services
$locator = Environment::getServiceLocator();
if ($config->service instanceof Config) {
foreach ($config->service as $key => $value) {
$locator->addService($value, strtr($key, '-', '\\'));
}
}
// check temporary directory - TODO: discuss
/*
$dir = Environment::getVariable('tempDir');
if ($dir && !(is_dir($dir) && is_writable($dir))) {
trigger_error("Temporary directory '$dir' is not writable", E_USER_NOTICE);
}
*/
// process ini settings
if ($config->set instanceof Config) {
if (PATH_SEPARATOR !== ';' && isset($config->set->include_path)) {
$config->set->include_path = str_replace(';', PATH_SEPARATOR, $config->set->include_path);
}
foreach ($config->set as $key => $value) {
$key = strtr($key, '-', '.');
// old INI compatibility
if (!is_scalar($value)) {
throw new InvalidStateException("Configuration value for directive '{$key}' is not scalar.");
}
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) {
// intentionally ==
throw new NotSupportedException('Required function ini_set() is disabled.');
}
}
}
}
}
// define constants
if ($config->const instanceof Config) {
foreach ($config->const as $key => $value) {
define($key, $value);
}
}
// set modes
if (isset($config->mode)) {
foreach ($config->mode as $mode => $state) {
Environment::setMode($mode, $state);
}
}
$config->setReadOnly();
return $config;
}