本文整理汇总了PHP中Nette\Utils\LimitedScope类的典型用法代码示例。如果您正苦于以下问题:PHP LimitedScope类的具体用法?PHP LimitedScope怎么用?PHP LimitedScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LimitedScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tryLoad
/**
* Handles autoloading of classes, interfaces or traits.
* @param string
* @return void
*/
public function tryLoad($type)
{
$type = ltrim(strtolower($type), '\\');
// PHP namespace bug #49143
$info =& $this->classes[$type];
if (isset($this->missing[$type]) || is_int($info) && $info >= self::RETRY_LIMIT) {
return;
}
if ($this->autoRebuild) {
if (!is_array($info) || !is_file($info['file'])) {
$info = is_int($info) ? $info + 1 : 0;
if ($this->rebuilt) {
$this->getCache()->save($this->getKey(), $this->classes, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
} else {
$this->rebuild();
}
} elseif (!$this->rebuilt && filemtime($info['file']) !== $info['time']) {
$this->updateFile($info['file']);
if (!isset($this->classes[$type])) {
$this->classes[$type] = 0;
}
$this->getCache()->save($this->getKey(), $this->classes, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
}
}
if (isset($this->classes[$type]['file'])) {
Nette\Utils\LimitedScope::load($this->classes[$type]['file'], TRUE);
self::$count++;
} else {
$this->missing[$type] = TRUE;
}
}
示例2: tryLoad
/**
* Handles autoloading of classes, interfaces or traits.
* @param string
* @return void
*/
public function tryLoad($type)
{
$type = ltrim(strtolower($type), '\\');
// PHP namespace bug #49143
$info =& $this->list[$type];
if ($this->autoRebuild && empty($this->checked[$type]) && (is_array($info) ? !is_file($info[0]) : $info < self::RETRY_LIMIT)) {
$info = is_int($info) ? $info + 1 : 0;
$this->checked[$type] = TRUE;
if ($this->rebuilt) {
$this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
} else {
$this->rebuild();
}
}
if (isset($info[0])) {
Nette\Utils\LimitedScope::load($info[0], TRUE);
if ($this->autoRebuild && !class_exists($type, FALSE) && !interface_exists($type, FALSE) && (PHP_VERSION_ID < 50400 || !trait_exists($type, FALSE))) {
$info = 0;
$this->checked[$type] = TRUE;
if ($this->rebuilt) {
$this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
} else {
$this->rebuild();
}
}
self::$count++;
}
}
示例3: tryLoad
/**
* Handles autoloading of classes or interfaces.
* @param string
* @return void
*/
public function tryLoad($type)
{
$type = ltrim(strtolower($type), '\\');
if (isset($this->list[$type])) {
Nette\Utils\LimitedScope::load(NETTE_DIR . $this->list[$type]);
self::$count++;
}
}
示例4: createContainer
/**
* Returns the application DIC.
*
* @return \SystemContainer
*/
public function createContainer()
{
$c = $this->buildContainer();
LimitedScope::evaluate($c);
$container = new $this->parameters['container']['class']();
$container->initialize();
return $container;
}
示例5: tryLoad
/**
* Handles autoloading of classes or interfaces.
* @param string
* @return void
*/
public function tryLoad($type)
{
$type = ltrim($type, '\\');
if (isset($this->renamed[$type])) {
class_alias($this->renamed[$type], $type);
trigger_error("Class {$type} has been renamed to {$this->renamed[$type]}.", E_USER_WARNING);
} elseif (isset($this->list[$type])) {
Nette\Utils\LimitedScope::load(NETTE_DIR . $this->list[$type] . '.php', TRUE);
self::$count++;
} elseif (substr($type, 0, 6) === 'Nette\\' && is_file($file = NETTE_DIR . strtr(substr($type, 5), '\\', '/') . '.php')) {
Nette\Utils\LimitedScope::load($file, TRUE);
self::$count++;
}
}
示例6: render
/**
* Renders template to output.
* @return void
*/
public function render()
{
$cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.Template');
$cached = $compiled = $cache->load($this->source);
if ($compiled === NULL) {
$compiled = $this->compile();
$cache->save($this->source, $compiled, array(Caching\Cache::CONSTS => 'Nette\\Framework::REVISION'));
$cached = $cache->load($this->source);
}
if ($cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage) {
Nette\Utils\LimitedScope::load($cached['file'], $this->getParameters());
} else {
Nette\Utils\LimitedScope::evaluate($compiled, $this->getParameters());
}
}
示例7: tryLoad
/**
* Handles autoloading of classes or interfaces.
* @param string
* @return void
*/
public function tryLoad($type)
{
$mapper = function ($namespace) use ($type) { // find namespace in map
return Strings::startsWith(strtolower($type), strtolower($namespace)) ? $namespace : NULL;
};
$namespace = array_filter(array_keys($this->map), $mapper);
sort($namespace);
if (count($namespace)) { // is in map?
$namespace = end($namespace);
$type = substr($type, Strings::length($namespace) + (Strings::endsWith($namespace, '\\') ? 0 : 1)); // remove namespace
$path = $this->map[$namespace] . "/"; // map dir
$path .= str_replace('\\', DIRECTORY_SEPARATOR, $type); // class to file in map
$path .= ".php";
if (file_exists($path)) {
\Nette\Utils\LimitedScope::load($path);
}
}
}
示例8: getPresenterClass
/**
* @param string presenter name
*
* @return string class name
* @throws InvalidPresenterException
*/
public function getPresenterClass(&$name)
{
if (isset($this->cache[$name])) {
list($class, $name) = $this->cache[$name];
return $class;
}
if (!is_string($name) || !Nette\Utils\Strings::match($name, "#^[a-zA-Z-ÿ][a-zA-Z0-9-ÿ:]*\$#")) {
throw new InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
}
$class = $this->formatPresenterClass($name);
if (!class_exists($class)) {
// internal autoloading
$file = $this->formatPresenterFile($name);
if (is_file($file) && is_readable($file)) {
Nette\Utils\LimitedScope::load($file, true);
}
if (!class_exists($class)) {
throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' was not found in '{$file}'.");
}
}
$reflection = new Nette\Reflection\ClassType($class);
$class = $reflection->getName();
if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
}
if ($reflection->isAbstract()) {
throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
}
// canonicalize presenter name
$realName = $this->unformatPresenterClass($class);
if ($name !== $realName) {
if ($this->caseSensitive) {
throw new InvalidPresenterException("Cannot load presenter '{$name}', case mismatch. Real name is '{$realName}'.");
} else {
$this->cache[$name] = array($class, $realName);
$name = $realName;
}
} else {
$this->cache[$name] = array($class, $realName);
}
return $class;
}
示例9: beforeCompile
public function beforeCompile()
{
$container = $this->getContainerBuilder();
$code = '';
foreach ($container->findByTag('proxy') as $factory => $meta) {
$definition = $container->getDefinition($factory);
$class = substr($definition->class, strrpos($definition->class, '\\') + 1);
$namespace = substr($definition->class, 0, strrpos($definition->class, '\\'));
$extend = ltrim($meta, '\\');
$code .= $this->generateCode($class, $extend, $namespace);
}
if ($code) {
$cache = $this->getCache();
$cache->save('file', $code);
// find the file
$cached = $cache->load('file');
$this->classesFile = $cached['file'];
\Nette\Utils\LimitedScope::evaluate($code);
}
}
示例10: createContainer
/**
* Returns system DI container.
* @return \SystemContainer
*/
public function createContainer()
{
if ($cacheDir = $this->getCacheDirectory()) {
$cache = new Cache(new Nette\Caching\Storages\PhpFileStorage($cacheDir), 'Nette.Configurator');
$cacheKey = array($this->parameters, $this->files);
$cached = $cache->load($cacheKey);
if (!$cached) {
$code = $this->buildContainer($dependencies);
$cache->save($cacheKey, $code, array(Cache::FILES => $dependencies));
$cached = $cache->load($cacheKey);
}
Nette\Utils\LimitedScope::load($cached['file'], TRUE);
} elseif ($this->files) {
throw new Nette\InvalidStateException("Set path to temporary directory using setTempDirectory().");
} else {
Nette\Utils\LimitedScope::evaluate($this->buildContainer());
// back compatibility with Environment
}
$container = new $this->parameters['container']['class']();
$container->initialize();
Nette\Environment::setContext($container);
// back compatibility
return $container;
}
示例11: render
/**
* Renders template to output.
*
* @return void
*/
public function render()
{
if ($this->file == null) {
// intentionally ==
throw new Nette\InvalidStateException("Template file name was not specified.");
}
$cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
if ($storage instanceof Caching\Storages\PhpFileStorage) {
$storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file);
}
$cached = $compiled = $cache->load($this->file);
if ($compiled === null) {
try {
$compiled = "<?php\n\n// source file: {$this->file}\n\n?>" . $this->compile();
} catch (FilterException $e) {
$e->setSourceFile($this->file);
throw $e;
}
$cache->save($this->file, $compiled, array(Caching\Cache::FILES => $this->file, Caching\Cache::CONSTS => 'Nette\\Framework::REVISION'));
$cached = $cache->load($this->file);
}
if ($cached !== null && $storage instanceof Caching\Storages\PhpFileStorage) {
Nette\Utils\LimitedScope::load($cached['file'], $this->getParameters());
} else {
Nette\Utils\LimitedScope::evaluate($compiled, $this->getParameters());
}
}
示例12: loadConfig
//.........这里部分代码省略.........
$section = Environment::CONSOLE;
} else {
$section = $container->params['productionMode'] ? Environment::PRODUCTION : Environment::DEVELOPMENT;
}
}
$cache = new Cache($container->templateCacheStorage, 'Nette.Configurator');
$cacheKey = array((array) $container->params, $file, $section);
$cached = $cache->load($cacheKey);
if ($cached) {
require $cached['file'];
fclose($cached['handle']);
return $this->container;
}
$config = Nette\Config\Config::fromFile($file, $section);
$code = "<?php\n// source file {$file}\n\n";
// back compatibility with singular names
foreach (array('service', 'variable') as $item) {
if (isset($config[$item])) {
trigger_error(basename($file) . ": Section '{$item}' is deprecated; use plural form '{$item}s' instead.", E_USER_WARNING);
$config[$item . 's'] = $config[$item];
unset($config[$item]);
}
}
// process services
if (isset($config['services'])) {
foreach ($config['services'] as $key => &$def) {
if (preg_match('#^Nette\\\\.*\\\\I?([a-zA-Z]+)$#', strtr($key, '-', '\\'), $m)) {
// back compatibility
$m[1][0] = strtolower($m[1][0]);
trigger_error(basename($file) . ": service name '{$key}' has been renamed to '{$m['1']}'", E_USER_WARNING);
$key = $m[1];
}
if (is_array($def)) {
if (method_exists(get_called_class(), "createService{$key}") && !isset($def['factory']) && !isset($def['class'])) {
$def['factory'] = array(get_called_class(), "createService{$key}");
}
if (isset($def['option'])) {
$def['arguments'][] = $def['option'];
}
if (!empty($def['run'])) {
$def['tags'] = array('run');
}
}
}
$builder = new DI\ContainerBuilder();
$code .= $builder->generateCode($config['services']);
unset($config['services']);
}
// consolidate variables
if (!isset($config['variables'])) {
$config['variables'] = array();
}
foreach ($config as $key => $value) {
if (!in_array($key, array('variables', 'services', 'php', 'const', 'mode'))) {
$config['variables'][$key] = $value;
}
}
// pre-expand variables at compile-time
$variables = $config['variables'];
array_walk_recursive($config, function (&$val) use($variables) {
$val = Configurator::preExpand($val, $variables);
});
// add variables
foreach ($config['variables'] as $key => $value) {
$code .= $this->generateCode('$container->params[?] = ?', $key, $value);
}
// PHP settings
if (isset($config['php'])) {
foreach ($config['php'] as $key => $value) {
if (is_array($value)) {
// back compatibility - flatten INI dots
foreach ($value as $k => $v) {
$code .= $this->configurePhp("{$key}.{$k}", $v);
}
} else {
$code .= $this->configurePhp($key, $value);
}
}
}
// define constants
if (isset($config['const'])) {
foreach ($config['const'] as $key => $value) {
$code .= $this->generateCode('define', $key, $value);
}
}
// set modes - back compatibility
if (isset($config['mode'])) {
foreach ($config['mode'] as $mode => $state) {
trigger_error(basename($file) . ": Section 'mode' is deprecated; use '{$mode}Mode' in section 'variables' instead.", E_USER_WARNING);
$code .= $this->generateCode('$container->params[?] = ?', $mode . 'Mode', (bool) $state);
}
}
// pre-loading
$code .= self::preloadEnvironment($container);
// auto-start services
$code .= 'foreach ($container->getServiceNamesByTag("run") as $name => $foo) { $container->getService($name); }' . "\n";
$cache->save($cacheKey, $code, array(Cache::FILES => $file));
Nette\Utils\LimitedScope::evaluate($code, array('container' => $container));
return $this->container;
}
示例13: loadConfig
//.........这里部分代码省略.........
}
// add expanded variables
while (!empty($config['variables'])) {
$old = $config['variables'];
foreach ($config['variables'] as $key => $value) {
try {
$code .= $this->generateCode('$container->params[?] = ?', $key, $container->params[$key] = $container->expand($value));
unset($config['variables'][$key]);
} catch (Nette\InvalidArgumentException $e) {}
}
if ($old === $config['variables']) {
throw new InvalidStateException("Unable to expand variables: " . implode(', ', array_keys($old)) . ".");
}
}
unset($config['variables']);
// process services
if (isset($config['services'])) {
foreach ($config['services'] as $key => & $def) {
if (preg_match('#^Nette\\\\.*\\\\I?([a-zA-Z]+)$#', strtr($key, '-', '\\'), $m)) { // back compatibility
$m[1][0] = strtolower($m[1][0]);
trigger_error(basename($file) . ": service name '$key' has been renamed to '$m[1]'", E_USER_WARNING);
$key = $m[1];
}
if (is_array($def)) {
if (method_exists(get_called_class(), "createService$key") && !isset($def['factory']) && !isset($def['class'])) {
$def['factory'] = array(get_called_class(), "createService$key");
}
if (isset($def['option'])) {
$def['arguments'][] = $def['option'];
}
if (!empty($def['run'])) {
$def['tags'] = array('run');
}
}
}
$builder = new DI\ContainerBuilder;
/**/$code .= $builder->generateCode($config['services']);/**/
/*5.2* $code .= $this->generateCode('$builder = new '.get_class($builder).'; $builder->addDefinitions($container, ?)', $config['services']);*/
unset($config['services']);
}
// expand variables
array_walk_recursive($config, function(&$val) use ($container) {
$val = $container->expand($val);
});
// PHP settings
if (isset($config['php'])) {
foreach ($config['php'] as $key => $value) {
if (is_array($value)) { // back compatibility - flatten INI dots
foreach ($value as $k => $v) {
$code .= $this->configurePhp("$key.$k", $v);
}
} else {
$code .= $this->configurePhp($key, $value);
}
}
unset($config['php']);
}
// define constants
if (isset($config['const'])) {
foreach ($config['const'] as $key => $value) {
$code .= $this->generateCode('define', $key, $value);
}
unset($config['const']);
}
// set modes - back compatibility
if (isset($config['mode'])) {
trigger_error(basename($file) . ": Section 'mode' is deprecated; use 'params' instead.", E_USER_WARNING);
foreach ($config['mode'] as $mode => $state) {
$code .= $this->generateCode('$container->params[?] = ?', $mode . 'Mode', (bool) $state);
}
unset($config['mode']);
}
// other
foreach ($config as $key => $value) {
$code .= $this->generateCode('$container->params[?] = ' . (is_array($value) ? 'Nette\ArrayHash::from(?)' : '?'), $key, $value);
}
// pre-loading
$code .= self::preloadEnvironment($container);
// auto-start services
$code .= 'foreach ($container->getServiceNamesByTag("run") as $name => $foo) { $container->getService($name); }' . "\n";
$cache->save($cacheKey, $code, array(
Cache::FILES => $file,
));
Nette\Utils\LimitedScope::evaluate($code, array('container' => $container));
return $this->container;
}
示例14: load
/**
* Reads configuration from PHP file.
* @param string file name
* @return array
*/
public function load($file)
{
return Nette\Utils\LimitedScope::load($file);
}
示例15: load
Nette\Config\IAdapter{function
load($file){return
Nette\Utils\LimitedScope::load($file);}function