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

  • ApplicationExtension
  • LatteExtension
  • RoutingExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Bridges\ApplicationDI;
  9: 
 10: use Nette,
 11:     Latte;
 12: 
 13: 
 14: /**
 15:  * Latte extension for Nette DI.
 16:  *
 17:  * @author     David Grudl
 18:  * @author     Petr Morávek
 19:  */
 20: class LatteExtension extends Nette\DI\CompilerExtension
 21: {
 22:     public $defaults = array(
 23:         'xhtml' => FALSE,
 24:         'macros' => array(),
 25:     );
 26: 
 27:     /** @var bool */
 28:     private $debugMode;
 29: 
 30:     /** @var string */
 31:     private $tempDir;
 32: 
 33: 
 34:     public function __construct($tempDir, $debugMode = FALSE)
 35:     {
 36:         $this->tempDir = $tempDir;
 37:         $this->debugMode = $debugMode;
 38:     }
 39: 
 40: 
 41:     public function loadConfiguration()
 42:     {
 43:         if (!class_exists('Latte\Engine')) {
 44:             return;
 45:         }
 46: 
 47:         $config = $this->validateConfig($this->defaults);
 48:         $container = $this->getContainerBuilder();
 49: 
 50:         $latteFactory = $container->addDefinition($this->prefix('latteFactory'))
 51:             ->setClass('Latte\Engine')
 52:             ->addSetup('setTempDirectory', array($this->tempDir))
 53:             ->addSetup('setAutoRefresh', array($this->debugMode))
 54:             ->addSetup('setContentType', array($config['xhtml'] ? Latte\Compiler::CONTENT_XHTML : Latte\Compiler::CONTENT_HTML))
 55:             ->addSetup('Nette\Utils\Html::$xhtml = ?', array((bool) $config['xhtml']))
 56:             ->setImplement('Nette\Bridges\ApplicationLatte\ILatteFactory');
 57: 
 58:         $container->addDefinition($this->prefix('templateFactory'))
 59:             ->setClass('Nette\Application\UI\ITemplateFactory')
 60:             ->setFactory('Nette\Bridges\ApplicationLatte\TemplateFactory');
 61: 
 62:         $container->addDefinition('nette.latte')
 63:             ->setClass('Latte\Engine')
 64:             ->addSetup('::trigger_error', array('Service nette.latte is deprecated, implement Nette\Bridges\ApplicationLatte\ILatteFactory.', E_USER_DEPRECATED))
 65:             ->addSetup('setTempDirectory', array($this->tempDir))
 66:             ->addSetup('setAutoRefresh', array($this->debugMode))
 67:             ->addSetup('setContentType', array($config['xhtml'] ? Latte\Compiler::CONTENT_XHTML : Latte\Compiler::CONTENT_HTML))
 68:             ->addSetup('Nette\Utils\Html::$xhtml = ?', array((bool) $config['xhtml']))
 69:             ->setAutowired(FALSE);
 70: 
 71:         foreach ($config['macros'] as $macro) {
 72:             if (strpos($macro, '::') === FALSE && class_exists($macro)) {
 73:                 $macro .= '::install';
 74:             }
 75:             $this->addMacro($macro);
 76:         }
 77: 
 78:         if (class_exists('Nette\Templating\FileTemplate')) {
 79:             $container->addDefinition('nette.template')
 80:                 ->setFactory('Nette\Templating\FileTemplate')
 81:                 ->addSetup('::trigger_error', array('Service nette.template is deprecated.', E_USER_DEPRECATED))
 82:                 ->addSetup('registerFilter', array(new Nette\DI\Statement(array($latteFactory, 'create'))))
 83:                 ->addSetup('registerHelperLoader', array('Nette\Templating\Helpers::loader'))
 84:                 ->setAutowired(FALSE);
 85:         }
 86: 
 87:         if ($this->name === 'latte') {
 88:             $container->addAlias('nette.latteFactory', $this->prefix('latteFactory'));
 89:             $container->addAlias('nette.templateFactory', $this->prefix('templateFactory'));
 90:         }
 91:     }
 92: 
 93: 
 94:     /**
 95:      * @param  callable
 96:      * @return void
 97:      */
 98:     public function addMacro($macro)
 99:     {
100:         Nette\Utils\Validators::assert($macro, 'callable');
101: 
102:         $container = $this->getContainerBuilder();
103:         $container->getDefinition('nette.latte')
104:             ->addSetup('?->onCompile[] = function($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
105: 
106:         $container->getDefinition($this->prefix('latteFactory'))
107:             ->addSetup('?->onCompile[] = function($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
108:     }
109: 
110: }
111: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0