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

Classes

  • Compiler
  • CompilerExtension
  • Configurator
  • Helpers
  • Loader

Interfaces

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