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

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