Exemple #1
0
 /**
  * Returns an entry of the container by its name.
  *
  * @param string $name Entry name or a class name.
  *
  * @throws InvalidArgumentException The name parameter must be of type string.
  * @throws DependencyException Error while resolving the entry.
  * @throws NotFoundException No entry found for the given name.
  * @return mixed
  */
 public function get($name)
 {
     if (!is_string($name)) {
         throw new InvalidArgumentException(sprintf('The name parameter must be of type string, %s given', is_object($name) ? get_class($name) : gettype($name)));
     }
     // Try to find the entry in the singleton map
     if (array_key_exists($name, $this->singletonEntries)) {
         return $this->singletonEntries[$name];
     }
     $definition = $this->definitionManager->getDefinition($name);
     if (!$definition) {
         throw new NotFoundException("No entry or class found for '{$name}'");
     }
     $value = $this->resolveDefinition($definition);
     // If the entry is singleton, we store it to always return it without recomputing it
     if ($definition->getScope() == Scope::SINGLETON()) {
         $this->singletonEntries[$name] = $value;
     }
     return $value;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getScope()
 {
     return Scope::PROTOTYPE();
 }
Exemple #3
0
 /**
  * Default scope is singleton: the callable is called once and the result is shared.
  *
  * {@inheritdoc}
  */
 public function getScope()
 {
     return $this->scope ?: Scope::SINGLETON();
 }
<?php

use DI\Scope;
return ['A' => \DI\object()->scope(Scope::PROTOTYPE()), 'B' => \DI\object()->scope(Scope::PROTOTYPE()), 'C' => \DI\object()->scope(Scope::PROTOTYPE()), 'D' => \DI\object()->scope(Scope::PROTOTYPE()), 'E' => \DI\object()->scope(Scope::PROTOTYPE()), 'F' => \DI\object()->scope(Scope::PROTOTYPE()), 'G' => \DI\object()->scope(Scope::PROTOTYPE()), 'H' => \DI\object()->scope(Scope::PROTOTYPE()), 'I' => \DI\object()->scope(Scope::PROTOTYPE()), 'J' => \DI\object()->scope(Scope::PROTOTYPE())];
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function getScope()
 {
     return Scope::SINGLETON();
 }
<?php

return ['B' => \DI\object()->scope(\DI\Scope::PROTOTYPE())];