DI\Container::get PHP Метод

get() публичный Метод

Returns an entry of the container by its name.
public get ( string $name ) : mixed
$name string Entry name or a class name.
Результат 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->definitionSource->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;
    }

Usage Example

Пример #1
0
 public function createFeatureFromClassName(string $featureClassName) : Feature
 {
     if (!in_array($featureClassName, $this->listFeatures())) {
         throw new UnknownFeatureException(sprintf('Unknown feature class `%s`', $featureClassName));
     }
     return $this->container->get($featureClassName);
 }
All Usage Examples Of DI\Container::get