本文整理汇总了PHP中Nette\Environment::setVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::setVariable方法的具体用法?PHP Environment::setVariable怎么用?PHP Environment::setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Environment
的用法示例。
在下文中一共展示了Environment::setVariable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
<?php
namespace ActiveMapperTests;
require_once __DIR__ . "/../libs/Nette/loader.php";
\Nette\Debug::enable(\Nette\Debug::DEVELOPMENT);
\Nette\Environment::setVariable("tempDir", __DIR__ . "/_temp");
$loader = new \Nette\Loaders\RobotLoader();
$loader->addDirectory(__DIR__ . "/../libs");
$loader->addDirectory(__DIR__ . "/../ActiveMapper");
$loader->addDirectory(__DIR__ . "/../examples/Models");
$loader->register();
\dibi::connect(array('driver' => "sqlite3", 'database' => ":memory:", 'formatDateTime' => "'Y-m-d H:i:s'", 'lazy' => TRUE, 'profiler' => TRUE));
\dibi::loadFile(__DIR__ . "/db.structure.sql");
\dibi::loadFile(__DIR__ . "/db.data.sql");
示例2: createApplication
/**
* @return Nette\Application\Application
*/
public static function createApplication()
{
if (Environment::getVariable('baseUri', NULL) === NULL) {
Environment::setVariable('baseUri', Environment::getHttpRequest()->getUri()->getBasePath());
}
$context = clone Environment::getContext();
$context->addService('Nette\\Application\\IRouter', 'Nette\\Application\\MultiRouter');
if (!$context->hasService('Nette\\Application\\IPresenterLoader')) {
$context->addService('Nette\\Application\\IPresenterLoader', function () {
return new Nette\Application\PresenterLoader(Environment::getVariable('appDir'));
});
}
$application = new Nette\Application\Application();
$application->setContext($context);
$application->catchExceptions = Environment::isProduction();
return $application;
}
示例3: RobotLoader
<?php
define('LIBS_DIR', __DIR__ . '/../libs');
require_once LIBS_DIR . '/Nette/loader.php';
require_once LIBS_DIR . '/dump.php';
use Nette\Diagnostics\Debugger as Debug;
use Nette\Environment;
use Nette\Loaders\RobotLoader;
Debug::enable(false);
Debug::$strictMode = true;
Environment::setVariable('tempDir', __DIR__ . '/tmp');
$r = new RobotLoader();
$r->setCacheStorage(Environment::getContext()->cacheStorage);
$r->addDirectory(LIBS_DIR);
$r->addDirectory(__DIR__ . '/cases');
$r->register();
require_once __DIR__ . '/TestCase.php';
示例4: 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 Nette\Config\Config) {
$config = $file;
$file = NULL;
} else {
if ($file === NULL) {
$file = $this->defaultConfigFile;
}
$file = Environment::expand($file);
$config = Nette\Config\Config::fromFile($file, $name);
}
// process environment variables
if ($config->variable instanceof Nette\Config\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();
$locator = Environment::getServiceLocator();
if ($config->service instanceof Nette\Config\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 Nette\Config\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 Nette\Config\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':
//.........这里部分代码省略.........
示例5: createApplication
/**
* @return Nette\Application\Application
*/
public static function createApplication(array $options = NULL)
{
if (Environment::getVariable('baseUri', NULL) === NULL) {
Environment::setVariable('baseUri', Environment::getHttpRequest()->getUri()->getBaseUri());
}
$context = clone Environment::getContext();
$context->addService('Nette\\Application\\IRouter', 'Nette\Application\MultiRouter');
if (!$context->hasService('Nette\\Application\\IPresenterFactory')) {
$context->addService('Nette\\Application\\IPresenterFactory', function() use ($context) {
return new Nette\Application\PresenterFactory(Environment::getVariable('appDir'), $context);
});
}
$class = isset($options['class']) ? $options['class'] : 'Nette\Application\Application';
$application = new $class;
$application->setContext($context);
$application->catchExceptions = Environment::isProduction();
return $application;
}
示例6: run
/**
* Dispatch a HTTP request to a front controller.
* @return void
*/
public function run()
{
$httpRequest = $this->getHttpRequest();
$httpResponse = $this->getHttpResponse();
$httpRequest->setEncoding('UTF-8');
if (Environment::getVariable('baseUri') === NULL) {
Environment::setVariable('baseUri', $httpRequest->getUri()->getBasePath());
}
// autostarts session
$session = $this->getSession();
if (!$session->isStarted() && $session->exists()) {
$session->start();
}
// enable routing debuggger
Nette\Debug::addPanel(new RoutingDebugger($this->getRouter(), $httpRequest));
// check HTTP method
if ($this->allowedMethods) {
$method = $httpRequest->getMethod();
if (!in_array($method, $this->allowedMethods, TRUE)) {
$httpResponse->setCode(Nette\Web\IHttpResponse::S501_NOT_IMPLEMENTED);
$httpResponse->setHeader('Allow', implode(',', $this->allowedMethods));
echo '<h1>Method ' . htmlSpecialChars($method) . ' is not implemented</h1>';
return;
}
}
// dispatching
$request = NULL;
$repeatedError = FALSE;
do {
try {
if (count($this->requests) > self::$maxLoop) {
throw new ApplicationException('Too many loops detected in application life cycle.');
}
if (!$request) {
$this->onStartup($this);
// default router
$router = $this->getRouter();
if ($router instanceof MultiRouter && !count($router)) {
$router[] = new SimpleRouter(array('presenter' => 'Default', 'action' => 'default'));
}
// routing
$request = $router->match($httpRequest);
if (!$request instanceof PresenterRequest) {
$request = NULL;
throw new BadRequestException('No route for HTTP request.');
}
if (strcasecmp($request->getPresenterName(), $this->errorPresenter) === 0) {
throw new BadRequestException('Invalid request.');
}
}
$this->requests[] = $request;
$this->onRequest($this, $request);
// Instantiate presenter
$presenter = $request->getPresenterName();
try {
$class = $this->getPresenterLoader()->getPresenterClass($presenter);
$request->setPresenterName($presenter);
} catch (InvalidPresenterException $e) {
throw new BadRequestException($e->getMessage(), 404, $e);
}
$request->freeze();
// Execute presenter
$this->presenter = new $class();
$response = $this->presenter->run($request);
// Send response
if ($response instanceof ForwardingResponse) {
$request = $response->getRequest();
continue;
} elseif ($response instanceof IPresenterResponse) {
$response->send();
}
break;
} catch (\Exception $e) {
// fault barrier
if ($this->catchExceptions === NULL) {
$this->catchExceptions = Environment::isProduction();
}
$this->onError($this, $e);
if (!$this->catchExceptions) {
$this->onShutdown($this, $e);
throw $e;
}
if ($repeatedError) {
$e = new ApplicationException('An error occured while executing error-presenter', 0, $e);
}
if (!$httpResponse->isSent()) {
$httpResponse->setCode($e instanceof BadRequestException ? $e->getCode() : 500);
}
if (!$repeatedError && $this->errorPresenter) {
$repeatedError = TRUE;
$request = new PresenterRequest($this->errorPresenter, PresenterRequest::FORWARD, array('exception' => $e));
// continue
} else {
// default error handler
echo "<!DOCTYPE html><meta name=robots content=noindex>\n\n";
echo "<style>body{color:black;background:white;width:500px;margin:100px auto}h1{font:bold 47px/1.5 sans-serif;margin:.6em 0}p{font:21px/1.5 Georgia,serif;margin:1.5em 0}small{font-size:70%;color:gray}</style>\n\n";
//.........这里部分代码省略.........