Scans the current installation and picks up all the SilverStripe modules
that contain a `docs` folder.

@return void
1607
public function populateEntitiesFromInstall()
    {
        if ($this->automaticallyPopulated) {
            // already run
            return;
        }

        foreach (scandir(BASE_PATH) as $key => $entity) {
            if ($key == "themes") {
                continue;
            }

            $dir = DocumentationHelper::normalizePath(Controller::join_links(BASE_PATH, $entity));

            if (is_dir($dir)) {
                // check to see if it has docs
                $docs = Controller::join_links($dir, 'docs');

                if (is_dir($docs)) {
                    $entities[] = array(
                        'Path' => $docs,
                        'Title' => DocumentationHelper::clean_page_name($entity),
                        'Version' => 'master',
                        'Branch' => 'master',
                        'Stable' => true
                    );
                }
            }
        }

        Config::inst()->update(
            'DocumentationManifest',
            'register_entities',
            $entities
        );

        $this->automaticallyPopulated = true;
    }
898628
public function searchAndReplaceInFiles()
    {
        $directory = base_path('Modules/'.$this->module);

        $manager = new MountManager([
            'directory' => new Flysystem(new LocalAdapter($directory)),
        ]);

        $search = [
            'objects',
            'object',
            'Objects',
            'Object',
        ];
        $replace = [
            strtolower($this->module),
            strtolower(Str::singular($this->module)),
            $this->module,
            Str::singular($this->module),
        ];

        foreach ($manager->listContents('directory://', true) as $file) {
            if ($file['type'] === 'file') {
                $content = str_replace($search, $replace, $manager->read('directory://'.$file['path']));
                $manager->put('directory://'.$file['path'], $content);
            }
        }
    }
262737
public function getInstalled()
    {
        if (!$this->db->isInitialized()) {
            return array();
        }

        $modules = &gplcart_static('module.installed.list');

        if (isset($modules)) {
            return $modules;
        }

        $options = array(
            'index' => 'module_id',
            'unserialize' => 'settings'
        );

        return $modules = $this->db->fetchAll('SELECT * FROM module', array(), $options);
    }
948382
protected function getMyModules()
    {
        $all = array_keys( app()->getLoadedProviders() );
        $modules = [];
        foreach($all as $provider) {
            $parts = explode('\\', $provider);
            if ($parts[0] === 'ErenMustafaOzdal' && array_search($parts[1],$modules) === false) {
                array_push($modules, snake_case($parts[1], '-'));
            }
        }
        return $modules;
    }
122356
public function onGetNewsModules()
    {
        $modules = [];
        $records = $this->db->fetchAll("SELECT m.id, m.name, t.name AS theme FROM tl_module m LEFT JOIN tl_theme t ON m.pid=t.id WHERE m.type IN ('newslist', 'newsarchive') ORDER BY t.name, m.name");

        foreach ($records as $record) {
            $modules[$record['theme']][$record['id']] = \sprintf('%s (ID %s)', $record['name'], $record['id']);
        }

        return $modules;
    }
1030128
protected function install()
    {
        $installScripts = array();
        foreach ($this->autoloaderCollection as $dir => $jsonAutoloader) {
            $bundleName = $jsonAutoloader->getBundleName();
            $this->installPackage($dir, $jsonAutoloader);

            // Check if the bundle under exam has attached an ActionManager file
            $actionsManager = $jsonAutoloader->getActionManager();
            if ((!array_key_exists($bundleName, $this->installedBundles) && null !== $actionsManager)) {
                if (null !== $jsonAutoloader->getActionManagerClass()) {
                    $installScripts[$bundleName] = $actionsManager;

                    // Copies the current ActionManager class to app/config/bundles/cache folder
                    // because it must be preserved when a bundle is uninstalled
                    $reflection = new \ReflectionClass($actionsManager);
                    $fileName = $reflection->getFileName();
                    $className = $this->cachePath . '/' . $bundleName . '/' . basename($fileName);
                    $this->filesystem->copy($fileName, $className, true);
                }
            }

            unset($this->installedBundles[$bundleName]);
        }

        $installerScript = $this->scriptFactory->createScript('PreBootInstaller');
        $installerScript->executeActions($installScripts);
    }
5475
protected function loadAllModules()
    {
        $listModules = array_diff(scandir(MODULES_DIR), ['.', '..']);

        foreach ($listModules as $moduleName) {
            $modulePath = realpath(MODULES_DIR.$moduleName); //Symlink

            if (!is_dir($modulePath)) {
                continue;
            }

            $this->moduleList->addModule($moduleName);
        }

        $this->moduleList->readNeedMeDependencies();
        $this->moduleList->generateTree();
    }
163021
private function scanRolesAndPermissions(): void
    {
        $files = $this->helper->getConfigFilesSorted();

        if (!empty($files)) {
            foreach ($files as $filePath) {
                $config = json_decode(file_get_contents($filePath), true);

                if (is_null($config)) {
                    $this->info('Invalid json file: ' . $filePath);
                } else {
                    $packageName = Arr::get($config, 'general.packageName');

                    if (is_null($packageName)) {
                        $this->error('SKIPPING! Package must have a name! file: ' . $filePath);
                        continue;
                    }

                    if (array_key_exists('acl', $config)) {
                        $this->aclData[] = [
                            'packageName' => $packageName,
                            'acl' => Arr::get($config, 'acl'),
                        ];
                    }
                }
            }
        }
    }
1229716
public function includeModules()
    {
        if (!is_array($this->needModules) || empty($this->needModules))
        {
            return false;
        }

        foreach ($this->needModules as $module)
        {
            if (!Main\Loader::includeModule($module))
            {
                throw new Main\LoaderException('Failed include module "'.$module.'"');
            }
        }
    }
231764
protected function getAllModules()
    {
        return $this->extensionManager->discoverModules()
                    ->showInstalled()
                    ->showUninstalled()
                    ->showNoCore()
                    ->showCore()
                    ->getList(true);
    }
1044073
public function loadInfos()
    {
        $this->findModuleName();
        
        $infos = $this->obtainInfosFromModule();
        $this->checkPropertySrcPath($infos);
        
        //Defines default paths
        $this->sourceSrcPath    = $infos->srcPath;
        $this->sourceConfigPath = $infos->srcPath;

        //Defines properties
        
        if (property_exists($infos, 'configFiles')) {
            $this->configFilesList = (array) $infos->configFiles;
        }

        if (property_exists($infos, 'configPath')) {
            $this->sourceConfigPath = $infos->configPath;
        }

        if (property_exists($infos, 'installScript')) {
            $this->sourceInstallScript = $infos->installScript;
        }

        $this->sourceSrcPath = realpath(
            $this->sourcePath.'/'.$this->sourceSrcPath
        );
        
        $this->sourceConfigPath = realpath(
            $this->sourcePath.'/'.$this->sourceConfigPath
        );
        
        if (is_bool($this->sourceSrcPath) || is_bool($this->sourceConfigPath)) {
            throw new Exception(
                'The srcPath or the configPath (if define) properties not exist'
                .' for the module '.$this->name,
                $this::ERR_LOAD_PATH_NOT_EXIST
            );
        }
    }
849180
public function load() {
        global $_wula_namespace_classpath;
        $_wula_namespace_classpath['tmpmodules'] = MODULES_PATH;
        $modules                                 = $this->scanModules();
        foreach ($modules as $file) {
            try {
                include $file;
            } catch (\Exception $e) {
                log_warn($e->getMessage(), 'loader');
            }
        }
        unset($_wula_namespace_classpath['tmpmodules']);
    }
731777
private function scanTwigFiles()
    {
        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.twig')
            ->notName('*~')
            ->exclude(['cache', 'config', 'database', 'resources', 'tests', 'bower_components', 'node_modules'])
            ->in($this->app['path_resolver']->resolve('themes'))
            ->in($this->app['path_resolver']->resolve('app')); // yes, app = bad. Will be refactored in 3.4

        // Regex from: stackoverflow.com/questions/5695240/php-regex-to-ignore-escaped-quotes-within-quotes
        $twigRegex = [
            "/\b__\(\s*'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)'(?U).*\)/s" => ['\\\'' => '\''], // __('single_quoted_string'…
            '/\b__\(\s*"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"(?U).*\)/s' => ['\"'   => '"'], // __("double_quoted_string"…
        ];

        foreach ($finder as $file) {
            /** @var \Symfony\Component\Finder\SplFileInfo $file */
            foreach ($twigRegex as $regex => $stripslashes) {
                if (preg_match_all($regex, $file->getContents(), $matches)) {
                    foreach ($matches[1] as $foundString) {
                        $this->addTranslatable(strtr($foundString, $stripslashes));
                    }
                }
            }
        }
    }
1369030
static function LoadInstalledToBackend()
    {
        $bundles = InstalledBundle::Schema()->Fetch();
        foreach ($bundles as $bundle)
        {
            $manifest = ClassFinder::Manifest($bundle->GetBundle());
            $manifest->LoadToBackend();
        }
    }
1327900
function scan (moduleName, first)
  {
    var module = context.modules[moduleName];
    if (!module)
      throw new Error (sprintf ("Module '%' was not found.", moduleName));
    // Ignore the module if it's external.
    if (module.external)
      return false;
    if (!module.optimize) {
      if (first)
        module.nonOptimizedContainer = true;
      disableOptimizationsForChildrenOf (module);
      return true;
    }
    for (var i = 0, m = module.requires.length, any = false; i < m; ++i)
      if (scan (module.requires[i])) //Note: scan() still must be called for ALL submodules!
        any = true;
    if (any)
      module.nonOptimizedContainer = true;
    return false;
  }
1349501
protected function findAndLoadClasses()
    {
        ob_start();

        $this->findFilesInProjectPath()
            ->each(function ($file) {
                try {
                    require_once $file->getRealPath();
                } catch (Exception $e) {
                }
            });

        ob_end_clean();

        return collect(get_declared_classes());
    }
574176
protected function checkDirectoryRights()
    {
        $translator = $this->getServiceLocator()->get('translator');
        $installHelper = $this->getServiceLocator()->get('InstallerHelper');

        $configDir = $installHelper->getDir('config');
        $module = $this->getModuleSvc()->getAllModules();

        $success = 0;
        $errors = [];
        $data = [];

        for ($x = 0; $x < count($configDir); $x++) {
            $configDir[$x] = 'config/' . $configDir[$x];
        }
        array_push($configDir, 'config');

        /**
         * Add config platform, MelisSites and public dir to check permission
         */
        array_push($configDir, 'config/autoload/platforms/');
        array_push($configDir, 'module/MelisModuleConfig/');
        array_push($configDir, 'module/MelisModuleConfig/languages');
        array_push($configDir, 'module/MelisModuleConfig/config');
        array_push($configDir, 'module/MelisSites/');
        array_push($configDir, 'dbdeploy/');
        array_push($configDir, 'dbdeploy/data');
        array_push($configDir, 'public/');
        array_push($configDir, 'cache/');
        array_push($configDir, 'test/');

        for ($x = 0; $x < count($module); $x++) {
            $module[$x] = $this->getModuleSvc()->getModulePath($module[$x], false) . '/config';
        }

        $dirs = array_merge($configDir, $module);

        $results = [];
        foreach ($dirs as $dir) {
            if (file_exists($dir)) {
                if ($installHelper->isDirWritable($dir)) {
                    $results[$dir] = 1;
                } else {
                    $results[$dir] = sprintf($translator->translate('tr_melis_installer_step_1_2_dir_not_writable'), $dir);
                    array_push($errors, sprintf($translator->translate('tr_melis_installer_step_1_2_dir_not_writable'), $dir));
                }
            }
        }

        if (empty($errors)) {
            $success = 1;
        }

        $response = [
            'success' => $success,
            'errors' => $errors,
            'data' => $results,
        ];


        return $response;
    }