Factory.

@param int  $id
@param bool $usingNamespace

@return mixed
342811
public function make($id, $usingNamespace = false)
    {
        if ($usingNamespace) {
            return $this->factory->resolveAndCreate($id, $this);
        }

        return $this->factory->create($id, $this);
    }
321920
public function get($id)
    {
        if (isset($this->aliases[$id])) {
            $id = $this->aliases[$id];
        }

        if (!isset($this->keys[$id])) {
            throw new NotFoundException(sprintf(
                'The service "%s" is not found',
                $id
            ));
        }

        if (isset($this->values[$id])) {
            return $this->values[$id];
        }

        if (! $this->keys[$id]) {
            if (isset($this->factories[$id])) {
                return $this->createFromFactory($this->factories[$id]);
            } else {
                return $this->createFromDefinition($this->definition[$id]);
            }
        }

        if (isset($this->factories[$id])) {
            $service = $this->createFromFactory($this->factories[$id]);
            unset($this->factories[$id]);
        } else {
            $service = $this->createFromDefinition($this->definition[$id]);
            unset($this->definition[$id]);
        }

        $this->values[$id] = $service;
        $this->immutable[$id] = true;
        return $service;
    }
44963
public function lookup($id, $required = true) {
		if ($id instanceof \ReflectionClass) {
			$id = $id->getName();
		}
		
		// @todo check $required
		switch ($id) {
			case Request::class:
				try {
					return $this->getHttpContext()->getRequest();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Request not available.', 0, $e); 
				}
				return $this->request;
			case Response::class:
				try {
					return $this->getHttpContext()->getResponse();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Response not available.', 0, $e); 
				}
			case Session::class:
				try {
					return $this->getHttpContext()->getSession();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('Session not available.', 0, $e);
				}
			case HttpContext::class:
				try {
					return $this->getHttpContext();
				} catch (HttpContextNotAvailableException $e) {
					if (!$required) return null;
					throw new MagicObjectUnavailableException('HttpContext not available.', 0, $e);
				}
			case N2nContext::class:
				return $this;
			case LookupManager::class:
				return $this->getLookupManager();
			case N2nLocale::class:
				return $this->getN2nLocale();
			case EntityManager::class:
				return $this->lookup(PdoPool::class)->getEntityManagerFactory()->getExtended();
			case EntityManagerFactory::class:
				return $this->lookup(PdoPool::class)->getEntityManagerFactory();
			case TransactionManager::class:
				return $this->transactionManager;
			case VarStore::class:
				return $this->varStore;
			case AppCache::class:
				return $this->appCache;
			case AppConfig::class:
				return $this->appConfig;
			case GeneralConfig::class:
				return $this->appConfig->general();
			case WebConfig::class:
				return $this->appConfig->web();
			case MailConfig::class:
				return $this->appConfig->mail();
			case IoConfig::class:
				return $this->appConfig->io();
			case FilesConfig::class:
				return $this->appConfig->files();
			case ErrorConfig::class:
				return $this->appConfig->error();
			case DbConfig::class:
				return $this->appConfig->db();
			case OrmConfig::class:
				return $this->appConfig->orm();
			case N2nLocaleConfig::class:
				return $this->appConfig->locale();
			default:
				try {
					return $this->getLookupManager()->lookup($id);
				} catch (LookupFailedException $e) {
					throw new MagicObjectUnavailableException('Could not lookup object with name: ' . $id, 0, $e);
				}
		}
	}
845036
private function getNamespacedId(string $id) : string
    {
        $namespaceVersion = $this->getNamespaceVersion();

        return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
    }
420867
public function invalidate($namespaceId)
    {
        $namespace = $this->fetch($namespaceId);

        if (false === $namespace) {
            return false;
        }

        $newNamespace = rand(0, 10000);
        // @codeCoverageIgnoreStart
        while ($namespace === $newNamespace) {
            $newNamespace = rand(0, 10000);
        }

        // @codeCoverageIgnoreEnd
        return $this->save($namespaceId, $namespaceId . '_' . $newNamespace .'_', 0);
    }
926451
static function factory($model, $id = null) {
        if (is_string($model)) {
            $model_class = $model;
            if($model_class::isSoftDelete()){
                $model       = $model_class::withTrashed()->find($id);
            } else {
                $model       = $model_class::find($id);
            }
        }
        else {
            $model_class = get_class($model);
        }
        $acl_class = str_replace('\Model\\', '\Acl\Acl', \Str::studly($model_class));
        if (!class_exists($acl_class)) {
            $acl_class = __CLASS__;
        }
        return new $acl_class($model);
    }
329879
static function getInstance($id = null)
    {
        $key = empty($id) ? 'default' : $id;
        if (Core::$enableCoroutine)
        {
            return new static($id);
        }
        if (empty(self::$_instances[$key]))
        {
            $object = new static($id);
        }
        else
        {
            $object = self::$_instances[$key];
        }
        return $object;
    }
318400
public static function build($containerClass = Container::class, $config = [], $useAnnotations = true)
    {
        $builder = new \DI\ContainerBuilder($containerClass);

        $builder->useAnnotations($useAnnotations);

        $builder->addDefinitions(static::getDefaultConfig());
        $builder->addDefinitions($config);

        $container = $builder->build();

        $container->set(Request::class, get('request'));
        $container->set(Response::class, get('response'));
        $container->set($containerClass, get(\DI\Container::class));

        return $container;
    }
554206
public function get($id)
  {
    if (isset($this->instances[$id])) return $this->instances[$id];
    if (isset($this->callables[$id]))
    {
      $item = call_user_func($this->callables[$id],$this);
      return $this->instances[$id] = $item;
    }
    throw new \InvalidArgumentException(sprintf('Identifier "%s" is not defined for get.', $id));
  }
925952
private function getEnumById($id)
    {
        if (!$enum = SchemaStore::getEnumById($id, true)) {
            throw new \InvalidArgumentException(sprintf(
                'Cannot find an enum with id "%s"',
                $id
            ));
        }

        return $enum;
    }
1174393
public function make( $id, array $parameters = [] ) {
		if ( ! $this->bound( $id ) ) {
			throw new InvalidArgumentException( sprintf( 'Identifier `%s` is not defined', $id ) );
		}

		$id      = $this->get_class_prefix( $id );
		$value   = $this->bindings[$id];
		$closure = $value['closure'];

		return $this->call_closure( $closure, $parameters );
	}
612874
static function instance( $id, $load = false ) {
            if ( ! isset( self::$_instances[ $id ] ) ) {
                self::$_instances[ $id ] = new FS_Options( $id, $load );
            }

            return self::$_instances[ $id ];
        }
646809
public function load($id, array $parameters = [], array $headers = [])
    {
        return $this->getFactory()->create(
            $this->getApi()->getList($id, $parameters, $headers)
        );
    }
747721
protected function loadHelper($id, $onlyCheck = false) {
		$namespaces = $this->getNamespaces();
		
		if (empty($namespaces)) {
			throw new NoNamespaces('Wasn\'t a namespaces registered');
		}
		
		$misses = &$this->_loadMisses;
		set_error_handler(function() use(&$misses) {
			++ $misses;
		});
		
		foreach ($this->_namespaces as $namespace) {
			$class = $namespace . '\\' . ucfirst($id);
			
			if (class_exists($class)) {
				restore_error_handler();
				unset($misses);
				
				if ($onlyCheck) {
					return true;
				} else {
					$helper = new $class();
					
					if (! $helper instanceof HelperInterface) {
						throw new WrongHelper('Helper must implement the "HelperInterface"');
					}
					
					return $helper;
				}
			}
		}
		
		restore_error_handler();
		unset($misses);
	}
241532
public function get($id) {
		$source = $id;
		while (is_string($source) && isset($this->getter[$source])) {
			$source = $this->getter[$source];
		}
		if (!is_string($source)) {
			if ($source instanceof \Closure) {
				$source->bindTo($this);
				return $source();
			} elseif (is_object($source)) {
				return $source;
			} else {
				throw new NotFoundException("Class $id not found");
			}
		}
		if (isset($this->instance[$source])) {
			if (!isset($this->multi[$source])) {
				return $this->instance[$source];
			} elseif ($this->multi[$source] === self::MULTI_CLONE) {
				return clone $this->instance[$source];
			}
		}
		if (!class_exists($source)) {
			throw new NotFoundException("Class $id not found");
		}
		// Check cyclic dependency
		if (isset($this->creating[$source])) {
			throw new CyclicDependencyException("Found cyclic dependency of $id");
		}
		$this->creating[$source] = true;
		$ref = new ReflectionClass($source);
		if (!$ref->isInstantiable()) {
			throw new InvalidClassException("Can not create instance of $id");
		}
		// constructor
		$constructor = $ref->getConstructor();
		if ($constructor !== null) {
			// Read comment for getter
			$comment = $constructor->getDocComment();
			$is_autowire = preg_match_all('/@Autowired\s+([\w\\\\]+)\s+([\w\\\\]+)\s+/', $comment, $autowire_matches);
			$getter = [];
			if ($is_autowire && count($autowire_matches[1]) > 0) {
				foreach ($autowire_matches[1] as $k => $v) {
					$getter[$v] = $autowire_matches[2][$k];
				}
			}
			$params = $constructor->getParameters();
			$init_params = [];
			foreach ($params as $param) {
				if ($param->isOptional()) {
					$init_params[] = $param->getDefaultValue();
				} elseif (isset($getter[$param->getName()])) {
					$typeName = $getter[$param->getName()];
					$init_params[] = $this->get($typeName);
				} elseif ($param->hasType()) {
					$type = $param->getType();
					if (class_exists('ReflectionNamedType') && $type instanceof \ReflectionNamedType) {
						$typeName = $type->getName();
					} else {
						$typeName = $type->__toString();
					}
					if ($type->isBuiltin()) {
						$value = null;
						settype($value, $typeName);
						$init_params[] = $value;
					} else {
						$init_params[] = $this->get($typeName);
					}
				} else {
					$init_params[] = null;
				}
			}
			$instance = $ref->newInstance(...$init_params);
		} else {
			$instance = $ref->newInstance();
		}
		// properties
		$properties = $ref->getProperties();
		foreach ($properties as $property) {
			if ($property->isStatic()) {
				continue;
			}
			// Using getter and setter
			$propertyName = $property->getName();
			$setter = 'set' . ucfirst($propertyName);
			$getter = 'get' . ucfirst($propertyName);
			if (method_exists($instance, $setter) && method_exists($instance, $getter)) {
				if ($instance->$getter() === null) {
					$setter_ref = $ref->getMethod($setter);
					$is_autowire = preg_match('/@Autowired\s+([\w\\\\]+)\s+/', $setter_ref->getDocComment(), $autowire);
					if ($is_autowire) {
						$instance->$setter($this->get($autowire[1]));
					} else {
						$params = $setter_ref->getParameters();
						$param = $params[0];
						if ($param->hasType()) {
							$type = $param->getType();
							if (class_exists('ReflectionNamedType') && $type instanceof \ReflectionNamedType) {
								$typeName = $type->getName();
							} else {
								$typeName = $type->__toString();
							}
							$instance->$setter($this->get($typeName));
						}
					}
				}
			} else {
				$comment = $property->getDocComment();
				$is_autowire = preg_match('/@Autowired\s+([\w\\\\]+)\s+/', $comment, $autowire);
				if ($is_autowire) {
					$is_public = $property->isPublic();
					if (!$is_public) {
						$property->setAccessible(true);
					}
					if ($property->getValue($instance) === null) {
						$property->setValue($instance, $this->get($autowire[1]));
					}
					if (!$is_public) {
						$property->setAccessible(false);
					}
				}
			}
		}
		// put into instance
		if (!isset($this->multi[$source]) || $this->multi[$source] === self::MULTI_CLONE) {
			$this->instance[$source] = $instance;
		}
		unset($this->creating[$source]);
		return $instance;
	}
1117978
public function getParentModel($withNamespace = false)
    {
        /** @var BaseModel $path */
        $config = $this->getDI()->get('config');
        $modelNameSpace = $config['namespaces']['models'];
        $path = $modelNameSpace . $this->getModelName();
        $parentModelName = $path::$parentModel;

        if (!$parentModelName) {
            return false;
        }

        return $withNamespace ? $modelNameSpace . $parentModelName : $parentModelName;
    }
210870
public static function create($id = null)
    {
        if ( empty($id) )
        {
            $id = md5(__METHOD__) . count(self::$instances); 
        }
        if ( empty(self::$instances[$id]) )
        {
            self::$instances[$id] = new self();  
        }
        return self::$instances[$id];
    }