Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • CacheMacro
  • CoreMacros
  • FormMacros
  • MacroSet
  • UIMacros
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Latte\Macros;
 13: 
 14: use Nette,
 15:     Nette\Latte;
 16: 
 17: 
 18: 
 19: /**
 20:  * Macro {cache} ... {/cache}
 21:  *
 22:  * @author     David Grudl
 23:  */
 24: class CacheMacro extends Nette\Object implements Latte\IMacro
 25: {
 26:     /** @var bool */
 27:     private $used;
 28: 
 29: 
 30: 
 31:     /**
 32:      * Initializes before template parsing.
 33:      * @return void
 34:      */
 35:     public function initialize()
 36:     {
 37:         $this->used = FALSE;
 38:     }
 39: 
 40: 
 41: 
 42:     /**
 43:      * Finishes template parsing.
 44:      * @return array(prolog, epilog)
 45:      */
 46:     public function finalize()
 47:     {
 48:         if ($this->used) {
 49:             return array('Nette\Latte\Macros\CacheMacro::initRuntime($template, $_g);');
 50:         }
 51:     }
 52: 
 53: 
 54: 
 55:     /**
 56:      * New node is found.
 57:      * @return bool
 58:      */
 59:     public function nodeOpened(Latte\MacroNode $node)
 60:     {
 61:         $this->used = TRUE;
 62:         $node->isEmpty = FALSE;
 63:         $node->openingCode = Latte\PhpWriter::using($node)
 64:             ->write('<?php if (Nette\Latte\Macros\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
 65:                 Nette\Utils\Strings::random()
 66:             );
 67:     }
 68: 
 69: 
 70: 
 71:     /**
 72:      * Node is closed.
 73:      * @return void
 74:      */
 75:     public function nodeClosed(Latte\MacroNode $node)
 76:     {
 77:         $node->closingCode = '<?php $_l->tmp = array_pop($_g->caches); if (!$_l->tmp instanceof stdClass) $_l->tmp->end(); } ?>';
 78:     }
 79: 
 80: 
 81: 
 82:     /********************* run-time helpers ****************d*g**/
 83: 
 84: 
 85: 
 86:     /**
 87:      * @return void
 88:      */
 89:     public static function initRuntime(Nette\Templating\FileTemplate $template, \stdClass $global)
 90:     {
 91:         if (!empty($global->caches)) {
 92:             end($global->caches)->dependencies[Nette\Caching\Cache::FILES][] = $template->getFile();
 93:         }
 94:     }
 95: 
 96: 
 97: 
 98:     /**
 99:      * Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
100:      * @param  Nette\Caching\IStorage
101:      * @param  string
102:      * @param  Nette\Caching\OutputHelper[]
103:      * @param  array
104:      * @return Nette\Caching\OutputHelper
105:      */
106:     public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, & $parents, array $args = NULL)
107:     {
108:         if ($args) {
109:             if (array_key_exists('if', $args) && !$args['if']) {
110:                 return $parents[] = (object) NULL;
111:             }
112:             $key = array_merge(array($key), array_intersect_key($args, range(0, count($args))));
113:         }
114:         if ($parents) {
115:             end($parents)->dependencies[Nette\Caching\Cache::ITEMS][] = $key;
116:         }
117: 
118:         $cache = new Nette\Caching\Cache($cacheStorage, 'Nette.Templating.Cache');
119:         if ($helper = $cache->start($key)) {
120:             if (isset($args['expire'])) {
121:                 $args['expiration'] = $args['expire']; // back compatibility
122:             }
123:             $helper->dependencies = array(
124:                 Nette\Caching\Cache::TAGS => isset($args['tags']) ? $args['tags'] : NULL,
125:                 Nette\Caching\Cache::EXPIRATION => isset($args['expiration']) ? $args['expiration'] : '+ 7 days',
126:             );
127:             $parents[] = $helper;
128:         }
129:         return $helper;
130:     }
131: 
132: }
133: 
Nette Framework 2.0.3 API API documentation generated by ApiGen 2.7.0