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

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

Test if the container can provide something for the given name.
public has ( string $name ) : boolean
$name string Entry name or a class name.
Результат boolean
    public function has($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)));
        }
        if (array_key_exists($name, $this->singletonEntries)) {
            return true;
        }
        $definition = $this->definitionSource->getDefinition($name);
        if ($definition === null) {
            return false;
        }
        return $this->definitionResolver->isResolvable($definition);
    }

Usage Example

Пример #1
0
 /**
  * @param string $controller
  *
  * @return GenericController
  */
 private function getControllerInstance(string $controller)
 {
     if ($this->container && $this->container->has($controller)) {
         $obj = $this->container->get($controller);
     }
     if (!isset($obj)) {
         $obj = new $controller();
         if ($this->container) {
             $this->container->injectOn($obj);
         }
     }
     return $obj;
 }
All Usage Examples Of DI\Container::has