Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • 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

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