ACC SHELL

Path : /srv/www/vhosts/centrumlb/3rdparty/Nette/Config/
File Upload :
Current File : /srv/www/vhosts/centrumlb/3rdparty/Nette/Config/CompilerExtension.php

<?php

/**
 * This file is part of the Nette Framework (http://nette.org)
 * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 * @package Nette\Config
 */



/**
 * Configurator compiling extension.
 *
 * @author     David Grudl
 * @property-read array $config
 * @property-read NDIContainerBuilder $containerBuilder
 * @package Nette\Config
 */
abstract class NConfigCompilerExtension extends NObject
{
	/** @var NConfigCompiler */
	protected $compiler;

	/** @var string */
	protected $name;


	public function setCompiler(NConfigCompiler $compiler, $name)
	{
		$this->compiler = $compiler;
		$this->name = $name;
		return $this;
	}


	/**
	 * Returns extension configuration.
	 * @param  array default values.
	 * @param  bool  perform %parameters% expansion?
	 * @return array
	 */
	public function getConfig(array $defaults = NULL, $expand = TRUE)
	{
		$config = $this->compiler->getConfig();
		$config = isset($config[$this->name]) ? $config[$this->name] : array();
		unset($config['services'], $config['factories']);
		$config = NConfigHelpers::merge($config, $defaults);
		return $expand ? $this->compiler->getContainerBuilder()->expand($config) : $config;
	}


	/**
	 * @return NDIContainerBuilder
	 */
	public function getContainerBuilder()
	{
		return $this->compiler->getContainerBuilder();
	}


	/**
	 * Reads configuration from file.
	 * @param  string  file name
	 * @return array
	 */
	public function loadFromFile($file)
	{
		$loader = new NConfigLoader;
		$res = $loader->load($file);
		$container = $this->compiler->getContainerBuilder();
		foreach ($loader->getDependencies() as $file) {
			$container->addDependency($file);
		}
		return $res;
	}


	/**
	 * Prepend extension name to identifier or service name.
	 * @param  string
	 * @return string
	 */
	public function prefix($id)
	{
		return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
	}


	/**
	 * Processes configuration data. Intended to be overridden by descendant.
	 * @return void
	 */
	public function loadConfiguration()
	{
	}


	/**
	 * Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
	 * @return void
	 */
	public function beforeCompile()
	{
	}


	/**
	 * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
	 * @return void
	 */
	public function afterCompile(NPhpClassType $class)
	{
	}

}

ACC SHELL 2018