/** * 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])) { LimitedScope::load($this->list[$type][0]); self::$count++; } }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new \InvalidStateException("Template file name was not specified."); } $this->__set('template', $this); $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof TemplateCacheStorage) { $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file); } $cached = $content = $cache[$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 (TemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $content, array(Cache::FILES => $this->file, Cache::CONSTS => 'Nette\\Framework::REVISION')); $cache->release(); $cached = $cache[$this->file]; } if ($cached !== NULL && $storage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->getParams()); flock($cached['handle'], LOCK_UN); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->getParams()); } }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { $type = ltrim(strtolower($type), '\\'); if (isset($this->list[$type])) { LimitedScope::load(NETTE_DIR . $this->list[$type]); self::$count++; } }
/** * @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\String::match($name, "#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*$#")) { 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\Loaders\LimitedScope::load($file); } if (!class_exists($class)) { throw new InvalidPresenterException("Cannot load presenter '$name', class '$class' was not found in '$file'."); } } $reflection = new Nette\Reflection\ClassReflection($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; }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { $type = ltrim(strtolower($type), '\\'); if (isset($this->aliases[$type])) { $type = $this->aliases[$type]; } if (isset($this->list[$type])) { LimitedScope::load(NETTE_DIR . $this->list[$type]); if ($a = strrpos($type, '\\')) { class_alias($type, 'n' . substr($type, $a + 1)); } self::$count++; } }
/** * 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]) || $this->list[$type] !== FALSE && !is_file($this->list[$type][0])) { $this->list[$type] = FALSE; if ($this->autoRebuild) { if ($this->rebuilt) { $this->getCache()->save($this->getKey(), $this->list); } else { $this->rebuild(); } } } if (!empty($this->list[$type])) { LimitedScope::load($this->list[$type][0]); self::$count++; } }
/** * 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])) { if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type][0]); self::$count++; } } else { $this->list[$type] = FALSE; if ($this->autoRebuild === NULL) { $this->autoRebuild = !$this->isProduction(); } if ($this->autoRebuild) { if ($this->rebuilded) { $this->getCache()->save($this->getKey(), $this->list); } else { $this->rebuild(); } } if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type][0]); self::$count++; } } }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new \InvalidStateException("Template file name was not specified."); } $this->__set('template', $this); $shortName = str_replace(dirname(dirname($this->file)), '', $this->file); $cache = new Cache($this->getCacheStorage(), 'Nette.FileTemplate'); $key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { if (!$this->getFilters()) { $this->onPrepareFilters($this); } if (!$this->getFilters()) { LimitedScope::load($this->file, $this->getParams()); return; } $content = $this->compile(file_get_contents($this->file), "file …{$shortName}"); $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire, Cache::CONSTS => 'Nette\\Framework::REVISION')); $cache->release(); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->getParams()); } }