Packages

  • 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
  • Package
  • Class
  • Tree
  • Deprecated
  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:  * @package Nette\Latte\Macros
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Macro {cache} ... {/cache}
 17:  *
 18:  * @author     David Grudl
 19:  * @package Nette\Latte\Macros
 20:  */
 21: class CacheMacro extends Object implements IMacro
 22: {
 23:     /** @var bool */
 24:     private $used;
 25: 
 26: 
 27:     /**
 28:      * Initializes before template parsing.
 29:      * @return void
 30:      */
 31:     public function initialize()
 32:     {
 33:         $this->used = FALSE;
 34:     }
 35: 
 36: 
 37:     /**
 38:      * Finishes template parsing.
 39:      * @return array(prolog, epilog)
 40:      */
 41:     public function finalize()
 42:     {
 43:         if ($this->used) {
 44:             return array('CacheMacro::initRuntime($template, $_g);');
 45:         }
 46:     }
 47: 
 48: 
 49:     /**
 50:      * New node is found.
 51:      * @return bool
 52:      */
 53:     public function nodeOpened(MacroNode $node)
 54:     {
 55:         $this->used = TRUE;
 56:         $node->isEmpty = FALSE;
 57:         $node->openingCode = PhpWriter::using($node)
 58:             ->write('<?php if (CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
 59:                 Strings::random()
 60:             );
 61:     }
 62: 
 63: 
 64:     /**
 65:      * Node is closed.
 66:      * @return void
 67:      */
 68:     public function nodeClosed(MacroNode $node)
 69:     {
 70:         $node->closingCode = '<?php $_l->tmp = array_pop($_g->caches); if (!$_l->tmp instanceof stdClass) $_l->tmp->end(); } ?>';
 71:     }
 72: 
 73: 
 74:     /********************* run-time helpers ****************d*g**/
 75: 
 76: 
 77:     /**
 78:      * @return void
 79:      */
 80:     public static function initRuntime(FileTemplate $template, stdClass $global)
 81:     {
 82:         if (!empty($global->caches)) {
 83:             end($global->caches)->dependencies[Cache::FILES][] = $template->getFile();
 84:         }
 85:     }
 86: 
 87: 
 88:     /**
 89:      * Starts the output cache. Returns CachingHelper object if buffering was started.
 90:      * @param  ICacheStorage
 91:      * @param  string
 92:      * @param  CachingHelper[]
 93:      * @param  array
 94:      * @return CachingHelper
 95:      */
 96:     public static function createCache(ICacheStorage $cacheStorage, $key, & $parents, array $args = NULL)
 97:     {
 98:         if ($args) {
 99:             if (array_key_exists('if', $args) && !$args['if']) {
100:                 return $parents[] = new stdClass;
101:             }
102:             $key = array_merge(array($key), array_intersect_key($args, range(0, count($args))));
103:         }
104:         if ($parents) {
105:             end($parents)->dependencies[Cache::ITEMS][] = $key;
106:         }
107: 
108:         $cache = new Cache($cacheStorage, 'Nette.Templating.Cache');
109:         if ($helper = $cache->start($key)) {
110:             if (isset($args['expire'])) {
111:                 $args['expiration'] = $args['expire']; // back compatibility
112:             }
113:             $helper->dependencies = array(
114:                 Cache::TAGS => isset($args['tags']) ? $args['tags'] : NULL,
115:                 Cache::EXPIRATION => isset($args['expiration']) ? $args['expiration'] : '+ 7 days',
116:             );
117:             $parents[] = $helper;
118:         }
119:         return $helper;
120:     }
121: 
122: }
123: 
Nette Framework 2.0.13 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0