Пример #1
0
 /**
  * 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++;
     }
 }
Пример #2
0
 /**
  * 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;
     }
 }
Пример #3
0
 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new Nette\InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $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 = $content = $cache->load($this->file);
     if ($content === NULL) {
         try {
             $content = $this->compile(file_get_contents($this->file));
             $content = "<?php\n\n// source file: {$this->file}\n\n?>{$content}";
         } catch (FilterException $e) {
             $e->setSourceFile($this->file);
             throw $e;
         }
         $cache->save($this->file, $content, array(Caching\Cache::FILES => $this->file, Caching\Cache::CONSTS => 'Nette\\Framework::REVISION'));
         $cache->release();
         $cached = $cache->load($this->file);
     }
     if ($cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage) {
         Nette\Utils\LimitedScope::load($cached['file'], $this->getParams());
         flock($cached['handle'], LOCK_UN);
         fclose($cached['handle']);
     } else {
         Nette\Utils\LimitedScope::evaluate($content, $this->getParams());
     }
 }
Пример #4
0
 /**
  * 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++;
     }
 }
Пример #5
0
 /**
  * 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
0
 /**
  * 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
0
	/**
	 * 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);
			}
		}
	}
 /**
  * @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
0
 /**
  * Handles autoloading of classes or interfaces.
  * @param  string
  * @return void
  */
 public function tryLoad($type)
 {
     $type = ltrim(strtolower($type), '\\');
     // PHP namespace bug #49143
     if (isset($this->list[$type][0]) && !is_file($this->list[$type][0])) {
         unset($this->list[$type]);
     }
     if (!isset($this->list[$type])) {
         $trace = debug_backtrace();
         $initiator =& $trace[2]['function'];
         if ($initiator === 'class_exists' || $initiator === 'interface_exists') {
             $this->list[$type] = FALSE;
             if ($this->autoRebuild && $this->rebuilt) {
                 $this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
             }
         }
         if ($this->autoRebuild && !$this->rebuilt) {
             $this->rebuild();
         }
     }
     if (isset($this->list[$type][0])) {
         Nette\Utils\LimitedScope::load($this->list[$type][0]);
         self::$count++;
     }
 }
Пример #10
0
 /**
  * Reads configuration from PHP file.
  * @param  string  file name
  * @return array
  */
 public function load($file)
 {
     return Nette\Utils\LimitedScope::load($file);
 }
 /**
  * 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;
 }
Пример #12
0
Nette\Config\IAdapter{function
load($file){return
Nette\Utils\LimitedScope::load($file);}function
Пример #13
0
 /**
  * @param $class
  * @param array $types
  * @return string
  * @throws \Nette\InvalidArgumentException
  */
 public function prepareType($class, array $types = array())
 {
     $class = trim($class, '\\');
     $key = serialize(array('class' => $class, 'types' => $types));
     if (!isset($this->loaded[$key])) {
         $newClass = $this->prepareClassName($class, $types);
         if ($this->storage) {
             $cache = new Cache($this->storage, 'Venne.Generics');
             $data = $cache->load($key);
             if (!$data) {
                 $data = $this->prepareClassTemplate($class, $newClass, $types);
                 $cache->save($key, $data);
                 $data = $cache->load($key);
             }
             if ($this->storage instanceof PhpFileStorage) {
                 \Nette\Utils\LimitedScope::load($data['file']);
             } else {
                 \Nette\Utils\LimitedScope::evaluate($data);
             }
         } else {
             $data = $this->prepareClassTemplate($class, $newClass, $types);
             \Nette\Utils\LimitedScope::evaluate($data);
         }
         $this->loaded[$key] = $newClass;
     }
     return $this->loaded[$key];
 }
Пример #14
0
 public function testLoad()
 {
     $metadata = $this->object->load('AnnotationLoaderTest_TestEntity');
     $expected = \Nette\Utils\LimitedScope::load(self::getFixtuteDir() . '/TestEntityMetadata.php');
     $this->assertEquals($expected, $metadata);
 }