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