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

  • Compiler
  • CompilerExtension
  • Container
  • ContainerBuilder
  • ContainerFactory
  • ContainerLoader
  • ServiceDefinition
  • Statement

Exceptions

  • MissingServiceException
  • ServiceCreationException
  • 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\DI;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Configurator compiling extension.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: abstract class CompilerExtension extends Nette\Object
 19: {
 20:     /** @var Compiler */
 21:     protected $compiler;
 22: 
 23:     /** @var string */
 24:     protected $name;
 25: 
 26:     /** @var array */
 27:     protected $config = array();
 28: 
 29: 
 30:     public function setCompiler(Compiler $compiler, $name)
 31:     {
 32:         $this->compiler = $compiler;
 33:         $this->name = $name;
 34:         return $this;
 35:     }
 36: 
 37: 
 38:     public function setConfig(array $config)
 39:     {
 40:         $this->config = $config;
 41:         return $this;
 42:     }
 43: 
 44: 
 45:     /**
 46:      * Returns extension configuration.
 47:      * @return array
 48:      */
 49:     public function getConfig()
 50:     {
 51:         if (func_num_args()) { // deprecated
 52:             return Config\Helpers::merge($this->config, $this->getContainerBuilder()->expand(func_get_arg(0)));
 53:         }
 54:         return $this->config;
 55:     }
 56: 
 57: 
 58:     /**
 59:      * Checks whether $config contains only $expected items and returns combined array.
 60:      * @return array
 61:      * @throws Nette\InvalidStateException
 62:      */
 63:     public function validateConfig(array $expected, array $config = NULL, $name = NULL)
 64:     {
 65:         if (func_num_args() === 1) {
 66:             return $this->config = $this->validateConfig($expected, $this->config);
 67:         }
 68:         if ($extra = array_diff_key((array) $config, $expected)) {
 69:             $name = $name ?: $this->name;
 70:             $extra = implode(", $name.", array_keys($extra));
 71:             throw new Nette\InvalidStateException("Unknown configuration option $name.$extra.");
 72:         }
 73:         return Config\Helpers::merge($config, $expected);
 74:     }
 75: 
 76: 
 77:     /**
 78:      * @return ContainerBuilder
 79:      */
 80:     public function getContainerBuilder()
 81:     {
 82:         return $this->compiler->getContainerBuilder();
 83:     }
 84: 
 85: 
 86:     /**
 87:      * Reads configuration from file.
 88:      * @param  string  file name
 89:      * @return array
 90:      */
 91:     public function loadFromFile($file)
 92:     {
 93:         $loader = new Config\Loader;
 94:         $res = $loader->load($file);
 95:         $this->compiler->addDependencies($loader->getDependencies());
 96:         return $res;
 97:     }
 98: 
 99: 
100:     /**
101:      * Prepend extension name to identifier or service name.
102:      * @param  string
103:      * @return string
104:      */
105:     public function prefix($id)
106:     {
107:         return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
108:     }
109: 
110: 
111:     /**
112:      * Processes configuration data. Intended to be overridden by descendant.
113:      * @return void
114:      */
115:     public function loadConfiguration()
116:     {
117:     }
118: 
119: 
120:     /**
121:      * Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
122:      * @return void
123:      */
124:     public function beforeCompile()
125:     {
126:     }
127: 
128: 
129:     /**
130:      * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
131:      * @return void
132:      */
133:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
134:     {
135:     }
136: 
137: }
138: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0