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

  • Compiler
  • CompilerExtension
  • Configurator
  • Helpers
  • Loader

Interfaces

  • IAdapter
  • 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\Config;
 13: 
 14: use Nette,
 15:     Nette\DI\ContainerBuilder;
 16: 
 17: 
 18: 
 19: /**
 20:  * Configurator compiling extension.
 21:  *
 22:  * @author     David Grudl
 23:  * @property-read array $config
 24:  * @property-read Nette\DI\ContainerBuilder $containerBuilder
 25:  */
 26: abstract class CompilerExtension extends Nette\Object
 27: {
 28:     /** @var Compiler */
 29:     protected $compiler;
 30: 
 31:     /** @var string */
 32:     protected $name;
 33: 
 34: 
 35: 
 36:     public function setCompiler(Compiler $compiler, $name)
 37:     {
 38:         $this->compiler = $compiler;
 39:         $this->name = $name;
 40:         return $this;
 41:     }
 42: 
 43: 
 44: 
 45:     /**
 46:      * Returns extension configuration.
 47:      * @param  array default values.
 48:      * @param  bool  perform %parameters% expansion?
 49:      * @return array
 50:      */
 51:     public function getConfig(array $defaults = NULL, $expand = TRUE)
 52:     {
 53:         $config = $this->compiler->getConfig();
 54:         $config = isset($config[$this->name]) ? $config[$this->name] : array();
 55:         unset($config['services'], $config['factories']);
 56:         $config = Helpers::merge($config, $defaults);
 57:         return $expand ? $this->compiler->getContainerBuilder()->expand($config) : $config;
 58:     }
 59: 
 60: 
 61: 
 62:     /**
 63:      * @return Nette\DI\ContainerBuilder
 64:      */
 65:     public function getContainerBuilder()
 66:     {
 67:         return $this->compiler->getContainerBuilder();
 68:     }
 69: 
 70: 
 71: 
 72:     /**
 73:      * Reads configuration from file.
 74:      * @param  string  file name
 75:      * @return array
 76:      */
 77:     public function loadFromFile($file)
 78:     {
 79:         $loader = new Loader;
 80:         $res = $loader->load($file);
 81:         $container = $this->compiler->getContainerBuilder();
 82:         foreach ($loader->getDependencies() as $file) {
 83:             $container->addDependency($file);
 84:         }
 85:         return $res;
 86:     }
 87: 
 88: 
 89: 
 90:     /**
 91:      * Prepend extension name to identifier or service name.
 92:      * @param  string
 93:      * @return string
 94:      */
 95:     public function prefix($id)
 96:     {
 97:         return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
 98:     }
 99: 
100: 
101: 
102:     /**
103:      * Processes configuration data. Intended to be overridden by descendant.
104:      * @return void
105:      */
106:     public function loadConfiguration()
107:     {
108:     }
109: 
110: 
111: 
112:     /**
113:      * Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
114:      * @return void
115:      */
116:     public function beforeCompile()
117:     {
118:     }
119: 
120: 
121: 
122:     /**
123:      * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
124:      * @return void
125:      */
126:     public function afterCompile(Nette\Utils\PhpGenerator\ClassType $class)
127:     {
128:     }
129: 
130: }
131: 
Nette Framework 2.0.4 API API documentation generated by ApiGen 2.7.0