Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • FileTemplate
  • Helpers
  • Template

Interfaces

  • IFileTemplate
  • ITemplate
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Templating;
  9: 
 10: use Latte\CompileException;
 11: use Nette;
 12: use Nette\Caching;
 13: use Latte;
 14: 
 15: 
 16: /**
 17:  * @deprecated
 18:  */
 19: class FileTemplate extends Template implements IFileTemplate
 20: {
 21:     /** @var string */
 22:     private $file;
 23: 
 24: 
 25:     /**
 26:      * Constructor.
 27:      * @param  string  template file path
 28:      */
 29:     public function __construct($file = NULL)
 30:     {
 31:         //trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
 32:         if ($file !== NULL) {
 33:             $this->setFile($file);
 34:         }
 35:     }
 36: 
 37: 
 38:     /**
 39:      * Sets the path to the template file.
 40:      * @param  string  template file path
 41:      * @return self
 42:      */
 43:     public function setFile($file)
 44:     {
 45:         $this->file = realpath($file);
 46:         if (!$this->file) {
 47:             throw new Nette\FileNotFoundException("Missing template file '$file'.");
 48:         }
 49:         return $this;
 50:     }
 51: 
 52: 
 53:     /**
 54:      * Returns the path to the template file.
 55:      * @return string  template file path
 56:      */
 57:     public function getFile()
 58:     {
 59:         return $this->file;
 60:     }
 61: 
 62: 
 63:     /**
 64:      * Returns template source code.
 65:      * @return string
 66:      */
 67:     public function getSource()
 68:     {
 69:         return file_get_contents($this->file);
 70:     }
 71: 
 72: 
 73:     /********************* rendering ****************d*g**/
 74: 
 75: 
 76:     /**
 77:      * Renders template to output.
 78:      * @return void
 79:      */
 80:     public function render()
 81:     {
 82:         if ($this->file == NULL) { // intentionally ==
 83:             throw new Nette\InvalidStateException('Template file name was not specified.');
 84:         }
 85: 
 86:         if (!$this->getFilters()) {
 87:             $this->onPrepareFilters($this);
 88:         }
 89: 
 90:         if ($latte = $this->getLatte()) {
 91:             return $latte->setLoader(new Latte\Loaders\FileLoader)->render($this->file, $this->getParameters());
 92:         }
 93: 
 94:         $cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
 95:         if ($storage instanceof Caching\Storages\PhpFileStorage) {
 96:             $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file);
 97:         }
 98:         $cached = $compiled = $cache->load($this->file);
 99: 
100:         if ($compiled === NULL) {
101:             try {
102:                 $compiled = "<?php\n\n// source file: $this->file\n\n?>" . $this->compile();
103: 
104:             } catch (CompileException $e) {
105:                 throw $e->setSource(file_get_contents($this->file), $e->sourceLine, $this->file);
106:             }
107: 
108:             $cache->save($this->file, $compiled, array(
109:                 Caching\Cache::FILES => $this->file,
110:                 Caching\Cache::CONSTS => 'Nette\Framework::REVISION',
111:             ));
112:             $cached = $cache->load($this->file);
113:         }
114: 
115:         $isFile = $cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage;
116:         self::load($isFile ? $cached['file'] : $compiled, $this->getParameters(), $isFile);
117:     }
118: 
119: }
120: 
Nette 2.3.8 API API documentation generated by ApiGen 2.8.0