/** * Define an object or a value in the container * * @param string $name Entry name * @param mixed|DefinitionHelper $value Value, use definition helpers to define objects */ public function set($name, $value) { // Clear existing entry if it exists if (array_key_exists($name, $this->singletonEntries)) { unset($this->singletonEntries[$name]); } if ($value instanceof DefinitionHelper) { $definition = $value->getDefinition($name); } else { $definition = new ValueDefinition($name, $value); } $this->definitionManager->addDefinition($definition); }
/** * Build and return a container. * * @return Container */ public function build() { // Definition sources $firstSource = null; $lastSource = null; foreach (array_reverse($this->files) as $file) { $source = new PHPFileDefinitionSource($file); // Chain file sources if ($lastSource instanceof PHPFileDefinitionSource) { $lastSource->chain($source); } else { $firstSource = $source; } $lastSource = $source; } if ($this->useAnnotations) { if ($lastSource) { $lastSource->chain(new AnnotationDefinitionSource()); } else { $firstSource = new AnnotationDefinitionSource(); } } elseif ($this->useAutowiring) { if ($lastSource) { $lastSource->chain(new ReflectionDefinitionSource()); } else { $firstSource = new ReflectionDefinitionSource(); } } // Definition manager $definitionManager = new DefinitionManager($firstSource); if ($this->cache) { $definitionManager->setCache($this->cache); } // Proxy factory $proxyFactory = $this->buildProxyFactory(); $containerClass = $this->containerClass; return new $containerClass($definitionManager, $proxyFactory, $this->wrapperContainer); }