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
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

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

Exceptions

  • MissingServiceException
  • ServiceCreationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  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:     /**
 31:      * @return static
 32:      */
 33:     public function setCompiler(Compiler $compiler, $name)
 34:     {
 35:         $this->compiler = $compiler;
 36:         $this->name = $name;
 37:         return $this;
 38:     }
 39: 
 40: 
 41:     /**
 42:      * @return static
 43:      */
 44:     public function setConfig(array $config)
 45:     {
 46:         $this->config = $config;
 47:         return $this;
 48:     }
 49: 
 50: 
 51:     /**
 52:      * Returns extension configuration.
 53:      * @return array
 54:      */
 55:     public function getConfig()
 56:     {
 57:         if (func_num_args()) { // deprecated
 58:             return Config\Helpers::merge($this->config, $this->getContainerBuilder()->expand(func_get_arg(0)));
 59:         }
 60:         return $this->config;
 61:     }
 62: 
 63: 
 64:     /**
 65:      * Checks whether $config contains only $expected items and returns combined array.
 66:      * @return array
 67:      * @throws Nette\InvalidStateException
 68:      */
 69:     public function validateConfig(array $expected, array $config = null, $name = null)
 70:     {
 71:         if (func_num_args() === 1) {
 72:             return $this->config = $this->validateConfig($expected, $this->config);
 73:         }
 74:         if ($extra = array_diff_key((array) $config, $expected)) {
 75:             $name = $name ?: $this->name;
 76:             $hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($expected), key($extra));
 77:             $extra = $hint ? key($extra) : implode(", $name.", array_keys($extra));
 78:             throw new Nette\InvalidStateException("Unknown configuration option $name.$extra" . ($hint ? ", did you mean $name.$hint?" : '.'));
 79:         }
 80:         return Config\Helpers::merge($config, $expected);
 81:     }
 82: 
 83: 
 84:     /**
 85:      * @return ContainerBuilder
 86:      */
 87:     public function getContainerBuilder()
 88:     {
 89:         return $this->compiler->getContainerBuilder();
 90:     }
 91: 
 92: 
 93:     /**
 94:      * Reads configuration from file.
 95:      * @param  string  file name
 96:      * @return array
 97:      */
 98:     public function loadFromFile($file)
 99:     {
100:         $loader = new Config\Loader;
101:         $res = $loader->load($file);
102:         $this->compiler->addDependencies($loader->getDependencies());
103:         return $res;
104:     }
105: 
106: 
107:     /**
108:      * Prepend extension name to identifier or service name.
109:      * @param  string
110:      * @return string
111:      */
112:     public function prefix($id)
113:     {
114:         return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
115:     }
116: 
117: 
118:     /**
119:      * Processes configuration data. Intended to be overridden by descendant.
120:      * @return void
121:      */
122:     public function loadConfiguration()
123:     {
124:     }
125: 
126: 
127:     /**
128:      * Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
129:      * @return void
130:      */
131:     public function beforeCompile()
132:     {
133:     }
134: 
135: 
136:     /**
137:      * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
138:      * @return void
139:      */
140:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
141:     {
142:     }
143: }
144: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0