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

Classes

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

Exceptions

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