Find all declared fusion namespaces for the currently migrated package

@return array an array with namespace alias as key and packageKey as value
@throws FilesException
18673
protected function findDeclaredFusionNamespaces()
    {
        $namespaces = [];

        $targetDirectory = $this->targetPackageData['path'] . '/Resources/Private';
        if(!is_dir($targetDirectory)) {
            return $namespaces;
        }

        foreach (Files::getRecursiveDirectoryGenerator($targetDirectory, null, true) as $pathAndFilename) {
            $pathInfo = pathinfo($pathAndFilename);
            if (!isset($pathInfo['filename'])) {
                continue;
            }
            if (strpos($pathAndFilename, 'Migrations/Code') !== false) {
                continue;
            }

            if (array_key_exists('extension', $pathInfo) && ($pathInfo['extension'] == 'ts2' || $pathInfo['extension'] == 'fusion')) {
                $namespaceDeclarationMatches = [];
                $count = preg_match_all(
                    '/^namespace:[\\s]*(?P<alias>[\\w\\.]+)[\\s]*\\=[\\s]*(?P<packageKey>[\\w\\.]+)[\\s]*$/um',
                    file_get_contents($pathAndFilename),
                    $namespaceDeclarationMatches,
                    PREG_SET_ORDER
                );
                if ($count > 0) {
                    foreach ($namespaceDeclarationMatches as $match) {
                        if (!array_key_exists($match['alias'], $namespaces)) {
                            $namespaces[$match['alias']] = $match['packageKey'];
                        } else {
                            if ($namespaces[$match['alias']] !== $match['packageKey']) {
                                $this->showWarning(
                                    sprintf(
                                        'Namespace-alias "%s" was declared multiple times for different aliases %s is used',
                                        $match['alias'],
                                        $namespaces[$match['alias']]
                                    )
                                );
                            }
                        }
                    }
                }
            }
        }
        return $namespaces;
    }
63377
public function getNamespaceList()
    {
        if (!isset($this->_namespaceList)) $this->getBasePathList();
        static::$_modulesNs[$this::className()] = $this->_namespaceList;
        return $this->_namespaceList;
    }
823163
public function getAllNamespaces()
    {
        $returnValue = array();

        
        
        if(count($this->namespaces) == 0){
        	$db = core_kernel_classes_DbWrapper::singleton();
        	$query = 'SELECT modelid, modeluri FROM models';
			$result = $db->query($query);
			
			while ($row = $result->fetch()){	
				$id 	= $row['modelid'];
				$uri 	= $row['modeluri'];
				$this->namespaces[$id] = $uri;
			}
        }
        
        foreach($this->namespaces as $id => $uri){
        	$returnValue[$uri] = new common_ext_Namespace($id, $uri);
        }

        

        return (array) $returnValue;
    }
1019933
public function getRootNamespace ()
	{
		
		$arr		= explode ('\\', $this->get ('namespace'));
		$table		= explode ('_', $this->get ('table'));
		$ns			= [];
		
		foreach ($arr as $nsSegment)
		{
			$tableSegment	= array_shift ($table);
			if (strtolower ($nsSegment) != strtolower ($tableSegment))
			{
				$ns[]	= $nsSegment;
				array_unshift ($table, $tableSegment);
			}
		}
		
		$namespace	= join ('\\', $ns) . '\\';
		
		return $namespace;
	}
400145
protected function getAllMigrations()
	{
		$migrations = array();
		$file_extensions = $this->getMigrationFileExtensions();

		// Use "DirectoryIterator" instead of "glob", because it works within PHAR files as well.
		$directory_iterator = new \DirectoryIterator($this->_migrationsDirectory);

		foreach ( $directory_iterator as $file ) {
			if ( $file->isFile() && in_array($file->getExtension(), $file_extensions) ) {
				$migrations[] = $file->getBasename();
			}
		}

		sort($migrations);

		return $migrations;
	}
638225
protected function findAllAssetPackages()
    {
        $packages = array();

        //
        $namespaces = $this->dispatcher->getHints();

        foreach ($namespaces as $name => $hint) {
            $packages[] = $name;
        }

        return $packages;
    }
533515
public function findGeneralConfiguration(): array
    {
        /** @var array[] $configurationSets */
        $configurationSets = [[]];

        $modules = $this->packageRepository->findModules();
        foreach ($modules as $module) {
            $extra = $module->getExtra();
            $this->validateGeneralConfigurationSectionInExtra($extra);
            if (!isset($extra['phplist/core']['configuration'])) {
                continue;
            }

            $configurationSets[] = $extra['phplist/core']['configuration'];
        }

        return /** @scrutinizer ignore-call */ array_replace_recursive(...$configurationSets);
    }
361729
public function getExtensions()
  {
    $ext = array();

    foreach ($this->Config->get('file-extensions') as $key => $value)
    {
      $ext = array_merge($ext, $value['extensions']);
    }

    return $ext;
  }
680068
private function getBundleFixtureDirectories()
    {
        return array_filter(
            array_map(
                function ($bundle) {
                    $path = $bundle->getPath() . '/DataFixtures/ORM';

                    return is_dir($path) ? $path : null;
                },
                $this->kernel->getBundles()
            )
        );
    }
974111
public function getFlatListOfExtensions()
	{
		if (!isset($this->flatExtentions))
		{
			$this->flatExtentions = [];

			foreach ($this->getFlatListOfFiles() as $file)
			{
				$this->flatExtentions[] = $file->getExtension();
			}

			$this->flatExtentions = array_count_values($this->flatExtentions);
		}

		return $this->flatExtentions;
	}
595961
private function namespaceDefinitions(array $definitions, Endpoint $endpoint): array
    {
        $namespacedDefinitions = [];
        /** @var DefinitionInterface $definition */
        foreach ($definitions as $definition) {
            if (!$definition->hasMeta('namespace') || !$definition->getMeta('namespace')) {
                $namespacedDefinitions[$definition->getName()] = $definition;
                continue;
            }

            $root = null;
            $parent = null;
            $namespaceConfig = $definition->getMeta('namespace');
            $namespacePath = $namespaceConfig['namespace'] ?? null;
            if ($namespacePath) {
                $querySuffix = $this->globalConfig['nodes']['query_suffix'] ?? 'Query';
                $mutationSuffix = $this->globalConfig['nodes']['mutation_suffix'] ?? 'Mutation';
                $subscriptionSuffix = $this->globalConfig['nodes']['subscription_suffix'] ?? 'Subscription';
                $namespaces = explode('/', $namespacePath);
                foreach ($namespaces as $namespace) {
                    $name = lcfirst($namespace);
                    $suffix = $querySuffix;
                    if ($definition instanceof MutationDefinition) {
                        $suffix = $mutationSuffix;
                    }
                    if ($definition instanceof SubscriptionDefinition) {
                        $suffix = $subscriptionSuffix;
                    }
                    $typeName = ucfirst($name).$suffix;
                    if (!$root) {
                        if (isset($namespacedDefinitions[$name])) {
                            $root = $namespacedDefinitions[$name];
                        } else {
                            $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                        }
                        $parent = $endpoint->getType($root->getType());
                        $namespacedDefinitions[$root->getName()] = $root;
                    } else {
                        $parent = $this->createChildNamespace($parent, $name, $typeName, $endpoint);
                    }
                }
                if ($alias = $namespaceConfig['alias'] ?? null) {
                    $definition->setName($alias);
                }
                $this->addDefinitionToNamespace($parent, $definition, $definition->getName());
                continue;
            }

            if ($bundle = $namespaceConfig['bundle'] ?? null) {
                $bundleQuerySuffix = $this->globalConfig['bundle']['query_suffix'] ?? 'BundleQuery';
                $bundleMutationSuffix = $this->globalConfig['bundle']['mutation_suffix'] ?? 'BundleMutation';
                $bundleSubscriptionSuffix = $this->globalConfig['bundle']['subscription_suffix'] ?? 'BundleSubscription';
                $name = lcfirst($bundle);
                $suffix = $bundleQuerySuffix;
                if ($definition instanceof MutationDefinition) {
                    $suffix = $bundleMutationSuffix;
                }
                if ($definition instanceof SubscriptionDefinition) {
                    $suffix = $bundleSubscriptionSuffix;
                }
                $typeName = ucfirst($name).$suffix;
                $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                $parent = $endpoint->getType($root->getType());
            }

            if ($nodeName = $namespaceConfig['node'] ?? null) {
                if ($endpoint->hasTypeForClass($nodeName)) {
                    $nodeName = $endpoint->getTypeForClass($nodeName);
                }

                $name = Inflector::pluralize(lcfirst($nodeName));

                $querySuffix = $this->globalConfig['nodes']['query_suffix'] ?? 'Query';
                $mutationSuffix = $this->globalConfig['nodes']['mutation_suffix'] ?? 'Mutation';
                $subscriptionSuffix = $this->globalConfig['nodes']['subscription_suffix'] ?? 'Subscription';

                $suffix = $querySuffix;
                if ($definition instanceof MutationDefinition) {
                    $suffix = $mutationSuffix;
                }
                if ($definition instanceof SubscriptionDefinition) {
                    $suffix = $subscriptionSuffix;
                }

                $typeName = ucfirst($nodeName).$suffix;
                if (!$root) {
                    $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                    $parent = $endpoint->getType($root->getType());
                } elseif ($parent) {
                    $parent = $this->createChildNamespace($parent, $name, $typeName, $endpoint);
                }

                if ($alias = $namespaceConfig['alias'] ?? null) {
                    $originName = $definition->getName();
                    $definition->setName($alias);
                } else {
                    //remove node suffix on namespaced definitions
                    $originName = $definition->getName();
                    $definition->setName(preg_replace(sprintf("/(\w+)%s$/", $nodeName), '$1', $definition->getName()));
                    $definition->setName(preg_replace(sprintf("/(\w+)%s$/", Inflector::pluralize($nodeName)), '$1', $definition->getName()));
                }
            }

            if ($root && $parent) {
                $this->addDefinitionToNamespace($parent, $definition, $originName);
                $namespacedDefinitions[$root->getName()] = $root;
            } else {
                $namespacedDefinitions[$definition->getName()] = $definition;
            }
        }

        return $namespacedDefinitions;
    }
685289
protected function getMigrationFiles()
    {
        $directoryIterator = new \DirectoryIterator($this->directory);
        $migrationFiles = [];
        foreach ($directoryIterator as $fileInfo) {
            /** @var \SplFileInfo $fileInfo */
            if ($fileInfo->isFile()) {
                if (preg_match($this->filePattern, $fileInfo->getRealPath())) {
                    $migrationFiles[] = $fileInfo->getRealPath();
                } else {
                    $context = [
                        'path' => $fileInfo->getRealPath(),
                    ];

                    $this->getLogger()->notice(
                        self::MESSAGE__FOUND_UNSUPPORTED_FILE__PATH,
                        $context
                    );
                }
            }
        }
        sort($migrationFiles);

        if (empty($migrationFiles)) {
            $context = [
                'path' => $this->directory,
                'pattern' => $this->filePattern,
            ];

            $this->getLogger()->warning(
                self::MESSAGE__THERE_IS_NOTHING_MATCHING_PATTERN__PATH_PATTERN,
                $context
            );
        }

        $this->getLogger()->info(
            self::MESSAGE__FOUND_MIGRATION_FILES__COUNT_PATH_PATTERN,
            [
                'count' => count($migrationFiles),
                'path' => $this->directory,
                'pattern' => $this->filePattern,
            ]
        );

        return $migrationFiles;
    }
1169217
public function getPaths(): array
    {
        $paths = [];
        foreach ($this->finder->getNamespaces() as $namespace) {
            $name = ($namespace !== FileViewFinder::DEFAULT_NAMESPACE) ? $namespace : null;
            foreach ($this->finder->getPaths($namespace) as $path) {
                $paths[] = new TemplatePath($path, $name);
            }
        }

        return $paths;
    }
954982
public function getMigrationsClasses()
    {
        $appFiles = $this->getMigrationsFiles();
        $classes = [];

        /* @var $component AppInterface */
        foreach ($appFiles as $appName => $migrationFiles) {
            $component = $this->orm->getComponent($appName);
            foreach ($migrationFiles as $migrationFile) {
                $className = ClassHelper::getClassFromFile($migrationFile);
                $foundClass = ClassHelper::classExists(
                    $className,
                    $component->getNamespace()
                );
                if (!$foundClass) {
                    throw new ClassNotFoundException(
                        sprintf(
                            'The class [ %2$s\\%1$s or \\%1$s ] '.
                            'could not be located',
                            $className,
                            $component->getNamespace()
                        )
                    );
                }
                $classes[$appName][] = $foundClass;
            }
        }

        return $classes;
    }
1265588
public function findAll()
    {
        $repos = array();
        foreach ($this->repository->findAll() as $repo) {
            $this->loadPackagistInfos($repo);
            $repos[] = $repo;
        }

        return $repos;
    }
884387
private function fetchNamespaces (NamespaceRegistry $entryNamespaces) : array
    {
        $namespaces = [];

        foreach ($entryNamespaces as $namespace => $path)
        {
            $namespaces[$namespace] = $this->makePathRelative($path);
        }

        return $namespaces;
    }
1027910
public function getBundeled() : array
    {
        $directory = MODULARITY_PATH . 'source/php/Module/';
        $bundeled = array();

        foreach (@glob($directory . "*", GLOB_ONLYDIR) as $folder) {
            $bundeled[$folder] = basename($folder);
        }

        return $bundeled;
    }