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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Compiler
  • CompilerExtension
  • Container
  • ContainerBuilder
  • ContainerLoader
  • DependencyChecker
  • PhpGenerator
  • ServiceDefinition
  • Statement

Exceptions

  • MissingServiceException
  • ServiceCreationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\DI;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Configurator compiling extension.
 15:  */
 16: abstract class CompilerExtension
 17: {
 18:     use Nette\SmartObject;
 19: 
 20:     /** @var Compiler */
 21:     protected $compiler;
 22: 
 23:     /** @var string */
 24:     protected $name;
 25: 
 26:     /** @var array */
 27:     protected $config = [];
 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:             $hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($expected), key($extra));
 71:             $extra = $hint ? key($extra) : implode(", $name.", array_keys($extra));
 72:             throw new Nette\InvalidStateException("Unknown configuration option $name.$extra" . ($hint ? ", did you mean $name.$hint?" : '.'));
 73:         }
 74:         return Config\Helpers::merge($config, $expected);
 75:     }
 76: 
 77: 
 78:     /**
 79:      * @return ContainerBuilder
 80:      */
 81:     public function getContainerBuilder()
 82:     {
 83:         return $this->compiler->getContainerBuilder();
 84:     }
 85: 
 86: 
 87:     /**
 88:      * Reads configuration from file.
 89:      * @param  string  file name
 90:      * @return array
 91:      */
 92:     public function loadFromFile($file)
 93:     {
 94:         $loader = new Config\Loader;
 95:         $res = $loader->load($file);
 96:         $this->compiler->addDependencies($loader->getDependencies());
 97:         return $res;
 98:     }
 99: 
100: 
101:     /**
102:      * Prepend extension name to identifier or service name.
103:      * @param  string
104:      * @return string
105:      */
106:     public function prefix($id)
107:     {
108:         return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
109:     }
110: 
111: 
112:     /**
113:      * Processes configuration data. Intended to be overridden by descendant.
114:      * @return void
115:      */
116:     public function loadConfiguration()
117:     {
118:     }
119: 
120: 
121:     /**
122:      * Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
123:      * @return void
124:      */
125:     public function beforeCompile()
126:     {
127:     }
128: 
129: 
130:     /**
131:      * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
132:      * @return void
133:      */
134:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
135:     {
136:     }
137: 
138: }
139: 
Nette 2.4-20161109 API API documentation generated by ApiGen 2.8.0