Loads a module and returns the associated class or returns if already loaded

@param String $packageName
@throws ModuleException
@return AbstractModule
975227
public function load($packageName) {
		if ($this->loadedModules->has($packageName)) {
			return $this->loadedModules->get($packageName);
		}

		// check existence
		if (!$this->installedModules->has($packageName)) {
			throw new ModuleException(sprintf('Module (%s) does not exist.', $packageName), 500);
		}

		// check activation
		if (!$this->activatedModules->has($packageName)) {
			throw new ModuleException(sprintf('Module (%s) not activated', $packageName), 501);
		}

		$model = $this->activatedModules->get($packageName);

		if ($model->getInstalledVersion() > $model->getActivatedVersion()) {
			throw new ModuleException(sprintf('Module Version Mismatch (%s). Module needs to be updated by the Administrator', $packageName), 500);
		}

		// load
		$className = $model->getClassName();

		/* @var $module AbstractModule */
		$module = new $className($model, $this->service);
		$this->loadedModules->set($packageName, $module);

		// load locale
		$localeService = $this->getServiceContainer()->getLocaleService();
		$file = sprintf('/%s/locales/{locale}/translations.json', $packageName);
		$localeService->loadLocaleFile($file, $module->getCanonicalName());

		return $module;
	}
246692
public function loadPackage($names)
    {
        $names = is_array($names) ? $names : func_get_args();

        foreach ($names as $name) {
            if (!array_key_exists($name, $this->packages)) {

                /** @var PackageInterface $package */
                if (!is_null($package = $this->manager->load($name))) {
                    $this->packages[$name] = $package;

                    if ($package->hasDependencies()) {
                        foreach ($package->getDependencies() as $dependency) {
                            $this->loadPackage($dependency);
                        }
                    }
                }
            }
        }

        return $this;
    }
1156550
public static function getSubpackageName($classname)
    {
        $reflect = new ReflectionClass($classname);

        if (preg_match('/@subpackage[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches)) {
            return $matches[1];
        } else {
            return null;
        }
    }
929606
public function getSubModule ($moduleKey)
		{
			if (isset($this->subModules[$moduleKey])) {
				return $this->subModules[$moduleKey];
			} else {
				throw new NonexistentSubModuleException('No submodule ' . $moduleKey);
			}
		}
1253573
public function getModulePath($moduleName, $returnFullPath = true)
    {
        $path = $this->getUserModulePath($moduleName, $returnFullPath);
        if ($path == '') {
            $path = $this->getComposerModulePath($moduleName, $returnFullPath);
        }

        return $path;
    }
1195952
public function &load(string $name) : ModularAbstract
    {
        $modular =& $this->internalGetModular($name);
        if (!$this->hasLoaded($name)) {
            $modular->init();
            $this->loadedModular[$this->sanitizeModularName($name)] = true;
        }

        return $modular;
    }
415633
private function getModule($name)
    {
        if (!$this->moduleContainer->hasModule($name)) {
            throw new Exception(sprintf('«%s» module is not available.', $name));
        }

        $module = $this->moduleContainer->getModule($name);

        return $module;
    }
1300453
protected function findPackageGlobal($packageName)
    {
        $packagePair = new PackageNameVersion($packageName);

        if (isset($this->packageCache[$packagePair->getNormalizedNameVersion()])) {
            return $this->packageCache[$packagePair->getNormalizedNameVersion()];
        }

        $composer = $this->embeddedComposer->createComposer($this->io);
        $repoManager = $composer->getRepositoryManager();

        $name = $packagePair->getName();
        $version = $packagePair->getVersion();
        $composerPackage = $this->packageCache[$packageName] = $repoManager->findPackage($name, $version);

        return $composerPackage;
    }
1247224
public function getModule ($module)
	{
		
		// Load modules
		
		$this->getModules ();
		
		// Loop through the modules
		
		foreach ($this->modules as $obj)
		{
			
			// If the module names match and the class exists
			
			if (strtolower ($obj->get ('name')) == $module && class_exists ($obj->getModuleClass ()))
			{
				
				// Return the module
				
				return $obj;
				
			}
			
		}
		
		// Return FALSE
		
		return FALSE;
		
	}
761055
private function loadPackageFromClass(string $name, $packageClass) : Package\IPackage
    {
        if (is_callable($packageClass)) {
            $package      = $packageClass($this, $name);
            $packageClass = is_scalar($package) ? gettype($package) : get_class($package);
        } else {
            $package = null;
        }

        if (!is_subclass_of($packageClass, IPackage::class, true)) {
            throw InvalidArgumentException::format(
                'Invalid package class defined within cms: expecting subclass of %s, %s given',
                IPackage::class, $packageClass
            );
        }

        /** @var IPackage $package */
        if (!$package) {
            $package = $this->container->get($packageClass);
        }

        if ($package->getName() !== $name) {
            throw InvalidArgumentException::format(
                'Invalid package class defined within package: defined package name \'%s\' does not match package name \'%s\' from instance of %s',
                $name, $package->getName(), get_class($package)
            );
        }

        return $package;
    }
550752
public function getRequiredModules($moduleName) {
        $moduleName = strtolower($moduleName);
        if (isset($this->_requiredModules[$moduleName])) {
            return $this->_requiredModules[$moduleName];
        }
        else {
            return null;
        }
    }
1113469
public function getAggregatePackageContaining($packageName)
    {
        foreach ($this->packages as $packageNode) {
            if ($packageNode->replaces($packageName)) {
                return $packageNode;
            }
        }

        return null;
    }
999496
public function load(string $moduleAndGroupName) : LoadedContentGroup
    {
        $loadedContentGroup = $this->actualContentLoaderService->load($moduleAndGroupName);

        return new LoadedContentGroup(
            $loadedContentGroup->getConfig(),
            $this->createPreviewContentGroup($loadedContentGroup->getContentGroup())
        );
    }
1221327
private function loadModuleByName($name)
    {
        // First of all, make sure a valid module name is being processed
        if (!$this->nameValid($name)) {
            throw new LogicException(sprintf(
                'Invalid module name "%s" is being processed. Module name must start from a capital letter and contain only alphabetic characters', $name
            ));
        }

        // Prepare PSR-0 compliant name
        $moduleNamespace = sprintf('%s\%s', $name, self::MODULE_CONFIG_FILE);

        // Ensure a module exists
        if (!class_exists($moduleNamespace)) {
            return false;
        }

        $pathProvider = new PathProvider($this->appConfig->getModulesDir(), $name);

        $sl = new ServiceLocator();
        $sl->registerArray($this->services);

        // Build module instance
        $module = new $moduleNamespace($this, $sl, $this->appConfig, $pathProvider, $name);

        // Routes must be global, so we'd extract them
        if (method_exists($module, 'getRoutes')) {
            $this->appendRoutes($this->prepareRoutes($moduleNamespace, $module->getRoutes()));
        }

        $this->loaded[$name] = $module;
        return $module;
    }
1137654
public function load(string $moduleAndGroupName) : LoadedContentGroup
    {
        if (substr_count($moduleAndGroupName, '.') !== 1) {
            throw InvalidArgumentException::format(
                'Invalid content group name supplied to %s: expecting format \'module-name.group-name\', \'%s\' given',
                __METHOD__, $moduleAndGroupName
            );
        }

        list($moduleName, $groupName) = explode('.', $moduleAndGroupName);

        if (!isset($this->cache[$moduleAndGroupName])) {
            $groups = $this->contentGroupRepo->matching(
                $this->contentGroupRepo->criteria()
                    ->where(ContentGroup::NAMESPACE, '=', $moduleName)
                    ->where(ContentGroup::NAME, '=', $groupName)
            );

            $this->cache[$moduleAndGroupName] = new LoadedContentGroup($this->config, $groups[0] ?? new ContentGroup($moduleName, $groupName, $this->clock));
        }

        return $this->cache[$moduleAndGroupName];
    }
477673
public function load()
    {
        if (!$this->isRegistered()) {
            if (!$this->exist()) {
                require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php');

                if (!\CUpdateClientPartner::LoadModuleNoDemand(
                    $this->getName(),
                    $strError,
                    $this->isBeta() ? 'N' : 'Y',
                    LANGUAGE_ID)
                ) {
                    throw new Exception\ModuleLoadException($strError, $this->getName());
                }
            }
        }

        return $this;
    }
673247
protected function getRequiredModule(string $className) {
		if (\array_key_exists($className, $this->modules)) {
			return $this->modules[$className];
		} else {
			throw new ConfigurationException(__CLASS__ . ' tried to request module ' . $className .
				', but it was not listed as a dependency or has not yet added.');
		}
	}