Populates the index by which modules may be looked up by associated class.

@return $this
347966
protected function populateAssociatedClassIndex()
    {
        $this->associatedClassIndex = [];

        foreach ($this->modules as $module) {

            if (    ! $module->getAssociatedClass()
                ||  array_key_exists('', $this->associatedClassIndex)
            ) {
                continue;
            }

            $this->associatedClassIndex[ $module->getAssociatedClass() ] = $module->getKey();
        }

        return $this;
    }
198327
public function getClassIndex(): ClassIndex
    {
        if (is_null($this->classIndex)) {
            $this->classIndex = new ClassIndex();
        }

        return $this->classIndex;
    }
398070
protected function applySort()
    {
        $sort = $this->getActualSort();

        if ( ! $sort) return $this;

        $criteria = $this->getModelSortCriteria();

        if ( ! $criteria) return $this;

        $this->getModelRepository()->pushCriteria($criteria, CriteriaKey::ORDER);

        return $this;
    }
675372
public function index()
    {
        return $this->core->api()->response(
            $this->makeContainer($this->modules->getModules())
        );
    }
168180
public function sort()
    {
        if ($this->modules) {
            $modules = [];
            $sorter = new StringSort();

            foreach ($this->modules as $slug => $module) {
                $sorter->add($slug, array_intersect(array_keys($module->getAttribute('require')), array_keys($this->modules)));
            }

            foreach ($sorter->sort() as $slug) {
                $modules[$slug] = $this->modules[$slug];
            }

            // Override modules array
            $this->modules = $modules;
        }

        return $this;
    }
49815
public function scan() : ModularCollection
    {
        if ($this->hasScanned) {
            return $this;
        }

        /**
         * @var SplFileInfo $path
         */
        foreach (new RecursiveDirectoryIterator($this->getModularDirectory()) as $path) {
            $baseName = $path->getBaseName();
            // skip dotted
            if ($baseName == '.' || $baseName == '..') {
                continue;
            }

            $directory = $this->getModularDirectory() . DIRECTORY_SEPARATOR . $baseName;
            // don't allow symlink to be execute & skip if contains file
            if ($path->isLink() || ! $path->isDir()) {
                $this->unwantedPath[$baseName] = $path->getType();
                continue;
            }

            $file = $directory . DIRECTORY_SEPARATOR . $baseName .'.php';
            if (! file_exists($file)) {
                $this->invalidModular[$baseName] = new ModularNotFoundException(
                    $file,
                    sprintf(
                        '%1$s file for %2$s has not found',
                        $this->modularParser->getName(),
                        $baseName
                    )
                );

                continue;
            }

            try {
                $modular = $this
                    ->modularParser
                    ->create($file)
                    ->process();
                if (! $modular->isValid()) {
                    throw new InvalidModularException(
                        sprintf(
                            '%1$s Is not valid.',
                            $this->modularParser->getName()
                        )
                    );
                }

                $this->validModular[$this->sanitizeModularName($baseName)] = [
                    static::CLASS_NAME_KEY => $modular->getClassName(),
                    static::FILE_PATH_KEY => $modular->getFile(),
                ];
            } catch (\Exception $e) {
                $this->invalidModular[$this->sanitizeModularName($baseName)] = $e;
            }
        }

        return $this;
    }
705371
public function registerIndexSingleton()
    {
        $this->app->singleton(Index::class, function ($app) {

            $settings = new IndexSettings(
                config('elasticsearch.index'),
                config('elasticsearch.settings'),
                config('elasticsearch.mappings')
            );

            $settings->setIndexables(config('elasticsearch.indexables'));

            return new Index($app[Client::class], $settings);
        });
    }
3053
public function set(): TaxonomyInterface
    {
        if (function_exists('current_filter') && 'init' === $hook = current_filter()) {
            $this->register();
        } else {
            $this->action->add('init', [$this, 'register']);
        }

        return $this;
    }
259220
public function init($modules = null)
    {
        if (!isset($modules)) {
            $modules = $this->module->getEnabled();
        }

        foreach ((array) $modules as $module) {

            if (empty($module['hooks'])) {
                continue;
            }

            foreach ($module['hooks'] as $method) {
                $this->register($method, $module['class']);
            }
        }

        return $this->hooks;
    }
916894
public static function init()
    {
        foreach (self::$_modulePaths as $path) {
            $folder = new Folder($path);
            $modulePaths = $folder->read(true, false, true)[0];

            foreach ($modulePaths as $modulePath) {
                self::_initializeModule($modulePath);
            }
        }

        self::$_initialized = true;
    }
239743
function initialize()
    {
        if ($this->isInitialize())
            return $this;

        // ) Load Modules ------------------------------------------------------\
        $serviceManager = $this->getServiceManager();
        /** @var ModuleManager $moduleManager */
        $moduleManager  = $serviceManager->get('ModuleManager');
        $moduleManager->loadModules();

        // ) Attach Listeners To Events ----------------------------------------\
        $events = $this->getEventManager();
        foreach ($this->listeners as $listener) {
            if (!is_object($listener)) {
                if (class_exists($listener))
                    $listener = new $listener();
                else
                    $listener = $this->getServiceManager()->get($listener);
            }

            if (!$listener instanceof ListenerAggregateInterface)
                throw new \Exception(sprintf(
                    'Listener must instance of "ListenerAggregateInterface" but "%s" given.'
                    , is_object($listener) ? get_class($listener) : gettype($listener)
                ));

            // Attach Aggregate Listener
            $events->attach($listener);
        }

        // Ci) Bootstrap Application --------------------------------------------\
        $this->bootstrap();

        $this->__isInitialize = true;

        return $this;
    }
792939
protected function initialiseModules()
    {
        $this->modules = array();
        $exceptions = array();

        foreach ($this->registerModules($this->environment) as $module) {
            if ($this->isSafeMode() && ! $module->isCoreModule()) {
                continue;
            }

            $name = $module->getName();

            if (isset($this->modules[$name])) {
                throw new \LogicException(sprintf('Trying to register two modules with the same name "%s"', $name));
            }

            $module->boot($this->getContainer());

            $this->modules[$module->getName()] = $module;
        }

        // Go through registered modules and execute post-boot actions
        foreach ($this->modules as $module) {
            $module->postBoot($this->getContainer());
        }

        return $this->modules;
    }
1008993
public function index() {
        Garp_Cli::lineOut('Building up index. Hang on to your knickers...');
        $modelSet = Garp_Spawn_Model_Set::getInstance();

        foreach ($modelSet as $model) {
            $this->_indexModel($model);
        }
        return true;
    }
733704
public function locally()
    {
        list(
            $this->item,
            $this->itemIterator,
            $this->itemIteratorTotal,
            $this->popIndex,
            $this->upIndex,
            $this->currentIndex
        ) = $this->itemStack[$this->localIndex];

        // Remember any  un-completed (resetLocalScope hasn't been called) lookup chain. Even if there isn't an
        // un-completed chain we need to store an empty item, as resetLocalScope doesn't know the difference later
        $this->localStack[] = array_splice($this->itemStack, $this->localIndex + 1);

        return $this;
    }
62810
public function setModules(array $modules)
    {
        $this->modules = array();

        foreach ($modules as $module) {
            $this->addModule($module);
        }

        return $this;
    }
729105
private function addMappings()
    {
        $indicesSettings = $this->indexSettings->getIndicesConfig();

        foreach ($this->_data as $requestName => $requestConfig) {
            $index = $requestConfig['index'];
            $this->_data[$requestName]['mapping'] = $indicesSettings[$index]['mapping'];
        }

        return $this;
    }
976089
public function getSortedModuleList() : array {
		$moduleList = $this->modules;

		foreach ($moduleList as $moduleSpec) {
			$moduleClass = $moduleSpec['class'];
			$module      = $moduleSpec['object'];

			if ($module instanceof OrderAwareModule) {
				//All modules that should be loaded after this one
				foreach ($module->getModulesAfter() as $afterModuleClass) {
					if (\array_key_exists($afterModuleClass, $moduleList)) {
						$moduleList[$moduleClass]['after'][] = $afterModuleClass;
						$moduleList[$afterModuleClass]['before'][] = $moduleClass;
					}
				}
				//All modules that should be loaded before this one
				foreach ($module->getModulesBefore() as $afterModuleClass) {
					if (\array_key_exists($afterModuleClass, $moduleList)) {
						$moduleList[$moduleClass]['before'][] = $afterModuleClass;
						$moduleList[$afterModuleClass]['after'][] = $moduleClass;
					}
				}
			}
		}

		$sortedList = [];
		$noIncomingNodes = [];
		foreach ($moduleList as $moduleSpec) {
			$moduleSpec['after']  = \array_unique($moduleSpec['after']);
			$moduleSpec['before'] = \array_unique($moduleSpec['before']);
			if (empty($moduleSpec['before'])) {
				$noIncomingNodes[$moduleSpec['class']] = $moduleSpec;
			}
		}

		//Do the topological sorting (Kahn's algorithm)
		while (!empty($noIncomingNodes)) {
			$moduleSpec = array_shift($noIncomingNodes);
			\array_push($sortedList, $moduleSpec);
			unset($moduleList[$moduleSpec['class']]);

			foreach ($moduleSpec['after'] as $nextModuleKey => $nextModuleClass) {
				unset($moduleList[$nextModuleClass]['before'][
					\array_search($moduleSpec['class'], $moduleList[$nextModuleClass]['before'])
				]);
				if (empty($moduleList[$nextModuleClass]['before'])) {
					$noIncomingNodes[] = $moduleList[$nextModuleClass];
				}
				unset($moduleSpec['after'][$nextModuleKey]);
			}
		}

		foreach ($moduleList as $key => $remainingModuleSpec) {
			if (empty($remainingModuleSpec['before'])) {
				$sortedList[] = $moduleList[$remainingModuleSpec['class']];
				unset($moduleList[$key]);
			}
		}

		if (!empty($moduleList)) {
			throw new CircularModuleLoadOrderDetectedException($this->getDotGraph());
		} else {
			$result = [];
			foreach ($sortedList as $moduleSpec) {
				$result[] = $moduleSpec['object'];
			}
			return $result;
		}
	}