/** * 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(Environment::getVariable('appDir'), '', $this->file); $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $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)); $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()); } }
/** * 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++; } }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { $type = strtolower($type); if (isset($this->list[$type])) { LimitedScope::load($this->base . $this->list[$type]); self::$count++; } }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { $type = ltrim($type, '\\'); if (isset($this->list[$type])) { LimitedScope::load(NETTE_DIR . $this->list[$type] . '.php', TRUE); self::$count++; } }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { if (strpbrk($type, './;|') !== FALSE) { throw new InvalidArgumentException("Invalid class/interface name '{$type}'."); } $file = strtr($type, '\\', '/') . '.php'; /* if (strncmp($type, 'Nette\\', 6) === 0) { $file = dirname(dirname(dirname(__FILE__))) . '/' . $file; } */ @LimitedScope::load($file); self::$count++; }
/** * Renders template to output. * @return void */ public function render() { $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.Template'); $cached = $compiled = $cache->load($this->source); if ($compiled === NULL) { $compiled = $this->compile(); $cache->save($this->source, $compiled, array(Cache::CONSTS => 'Framework::REVISION')); $cached = $cache->load($this->source); } if ($cached !== NULL && $storage instanceof PhpFileStorage) { LimitedScope::load($cached['file'], $this->getParameters()); } else { LimitedScope::evaluate($compiled, $this->getParameters()); } }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { if ($this->list === NULL) { $this->list = array(); // prevents cycling $cache = $this->getCache(); $data = $cache['data']; $opt = array($this->scanDirs, $this->ignoreDirs, $this->acceptFiles); if ($data['opt'] === $opt) { $this->list = $data['list']; } else { $this->rebuild(); $cache['data'] = array('list' => $this->list, 'opt' => $opt); } if (isset($this->list[strtolower(__CLASS__)]) && class_exists('NetteLoader', FALSE)) { NetteLoader::getInstance()->unregister(); } } $type = strtolower($type); if (isset($this->list[$type])) { if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type]); self::$count++; } } else { if ($this->autoRebuild === NULL) { $this->autoRebuild = !$this->isProduction(); } if ($this->autoRebuild) { if (!$this->rebuilded) { $this->rebuild(); } if (isset($this->list[$type])) { LimitedScope::load($this->list[$type]); self::$count++; } else { $this->list[$type] = FALSE; } $cache = $this->getCache(); $cache['data'] = array('list' => $this->list, 'opt' => array($this->scanDirs, $this->ignoreDirs, $this->acceptFiles)); } } }
/** * @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) || !preg_match("#^[a-zA-Z-ÿ][a-zA-Z0-9-ÿ:]*\$#", $name)) { 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 ReflectionClass($class); $class = $reflection->getName(); if (!$reflection->implementsInterface('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 = strtolower($type); if (isset($this->list[$type])) { if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type]); self::$count++; } } else { $this->list[$type] = FALSE; if ($this->autoRebuild === NULL) { $this->autoRebuild = !$this->isProduction(); } if ($this->autoRebuild) { $this->rebuild(FALSE); } if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type]); 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."); } elseif (!is_file($this->file) || !is_readable($this->file)) { throw new FileNotFoundException("Missing template file '{$this->file}'."); } $this->__set('template', $this); $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $key = md5($this->file) . '.' . basename($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { if (!$this->getFilters()) { $this->onPrepareFilters($this); } if (!$this->getFilters()) { /*Nette\Loaders\*/ LimitedScope::load($this->file, $this->getParams()); return; } try { $shortName = $this->file; $shortName = str_replace(Environment::getVariable('templatesDir'), "…", $shortName); } catch (Exception $foo) { } $content = $this->compile(file_get_contents($this->file), "file {$shortName}"); $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire)); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { /*Nette\Loaders\*/ LimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { /*Nette\Loaders\*/ LimitedScope::evaluate($content, $this->getParams()); } }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof 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 (TemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $compiled, array(Cache::FILES => $this->file, Cache::CONSTS => 'Framework::REVISION')); $cached = $cache->load($this->file); } if ($cached !== NULL && $storage instanceof PhpFileStorage) { LimitedScope::load($cached['file'], $this->getParameters()); } else { LimitedScope::evaluate($compiled, $this->getParameters()); } }
/** * 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++; } } }
/** * Reads configuration from PHP file. * @param string file name * @return array */ public function load($file) { return LimitedScope::load($file); }
/** * Returns system DI container. * @return SystemContainer */ public function createContainer() { if ($cacheDir = $this->getCacheDirectory()) { $cache = new Cache(new 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); } LimitedScope::load($cached['file'], TRUE); } elseif ($this->files) { throw new InvalidStateException("Set path to temporary directory using setTempDirectory()."); } else { LimitedScope::evaluate($this->buildContainer()); // back compatibility with Environment } $container = new $this->parameters['container']['class'](); $container->initialize(); Environment::setContext($container); // back compatibility return $container; }
/** * Handles autoloading of classes or interfaces. * @param string * @return void */ public function tryLoad($type) { $type = strtolower($type); /*$type = ltrim($type, '\\'); // PHP namespace bug #49143 */ if (isset($this->list[$type])) { if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type]); self::$count++; } } else { $this->list[$type] = FALSE; if ($this->autoRebuild === NULL) { $this->autoRebuild = !$this->isProduction(); } if ($this->autoRebuild) { $this->rebuild(FALSE); } if ($this->list[$type] !== FALSE) { LimitedScope::load($this->list[$type]); 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."); } elseif (!is_file($this->file) || !is_readable($this->file)) { throw new FileNotFoundException("Missing template file '{$this->file}'."); } $this->params['template'] = $this; if (!count($this->filters)) { LimitedScope::load($this->file, $this->params); return; } $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $key = md5($this->file) . count($this->filters) . '.' . basename($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { $content = file_get_contents($this->file); foreach ($this->filters as $filter) { if (!is_callable($filter)) { $able = is_callable($filter, TRUE, $textual); throw new InvalidStateException("Filter '{$textual}' is not " . ($able ? 'callable.' : 'valid PHP callback.')); } // remove PHP code $res = ''; $blocks = array(); unset($php); foreach (token_get_all($content) as $token) { if (is_array($token)) { if ($token[0] === T_INLINE_HTML) { $res .= $token[1]; unset($php); } else { if (!isset($php)) { $res .= $php = "@php:p" . count($blocks) . "@"; $php =& $blocks[$php]; } $php .= $token[1]; } } else { $php .= $token; } } try { $content = call_user_func($filter, $res); } catch (Exception $e) { is_callable($filter, TRUE, $textual); throw new InvalidStateException("Filter {$textual}: " . $e->getMessage() . " (in file {$this->file})", 0, $e); } $content = strtr($content, $blocks); // put PHP code back } $content = "<?php\n// template {$this->file}\n?>{$content}"; $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire)); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->params); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->params); } }
/** * 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 => '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 => 'Framework::REVISION')); } } if (isset($this->classes[$type]['file'])) { LimitedScope::load($this->classes[$type]['file'], TRUE); self::$count++; } else { $this->missing[$type] = TRUE; } }