Special function for data processing

@param array $data
@param array $composer_data
@param array $composer_dirs
324304
public static function processDepsArray($data, & $composer_data, & $composer_dirs, $origin_submodule, & $origin_dependencies, $type = 'vendor') {
		if (empty($data)) return;
		foreach ($data as $k => $v) {
			foreach ($v as $k2 => $v2) {
				if (!is_array($v2) && !empty($v2)) {
					$name = $k . '/' . $k2;
					$composer_data[$name] = $v2;
					$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/';
					if (!file_exists($dir)) continue;
					$composer_dirs[$name] = $dir;
					if ($k2 != '__any') {
						$origin_dependencies[$origin_submodule][$name] = $name;
					}
				} else {
					foreach ($v2 as $k3 => $v3) {
						if (!is_array($v3) && !empty($v3)) {
							$name = $k . '/' . $k2 . '/' . $k3;
							$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/' . $k3 . '/';
							if (!file_exists($dir)) continue;
							$composer_dirs[$name] = $dir;
							if ($k3 != '__any') {
								$origin_dependencies[$origin_submodule][$name] = $name;
							}
						} else {
							foreach ($v3 as $k4 => $v4) {
								if (!is_array($v4) && !empty($v4)) {
									$name = $k . '/' . $k2 . '/' . $k3 . '/' . $k4;
									$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/';
									if (!file_exists($dir)) continue;
									$composer_dirs[$name] = $dir;
									if ($k4 != '__any') {
										$origin_dependencies[$origin_submodule][$name] = $name;
									}
								} else {
									foreach ($v4 as $k5 => $v5) {
										if (!is_array($v5) && !empty($v5)) {
											$name = $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5;
											$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5 . '/';
											if (!file_exists($dir)) continue;
											$composer_dirs[$name] = $dir;
											if ($k5 != '__any') {
												$origin_dependencies[$origin_submodule][$name] = $name;
											}
										} else {
											foreach ($v5 as $k6 => $v6) {
												if (!is_array($v6) && !empty($v6)) {
													$name = $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5 . '/' . $k6;
													$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5 . '/' . $k6 . '/';
													if (!file_exists($dir)) continue;
													$composer_dirs[$name] = $dir;
													if ($k6 != '__any') {
														$origin_dependencies[$origin_submodule][$name] = $name;
													}
												} else {
													foreach ($v6 as $k7 => $v7) {
														if (!is_array($v7) && !empty($v7)) {
															$name = $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5 . '/' . $k6 . '/' . $k7;
															$dir = '../libraries/' . $type . '/' . $k . '/' . $k2 . '/' . $k3 . '/' . $k4 . '/' . $k5 . '/' . $k6 . '/' . $k7 . '/';
															if (!file_exists($dir)) continue;
															$composer_dirs[$name] = $dir;
															if ($k7 != '__any') {
																$origin_dependencies[$origin_submodule][$name] = $name;
															}
														} else {
															// we skip more than 7 part keys for now
															Throw new \Exception('we skip more than 7 part keys for now');
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
1015661
public function render($templates, array $data = array())
    {
        $__templates = (array) $templates;

        extract($data);
        ob_start();

        foreach ($__templates as $__template) {
            $__template = $this->templatesPath.$__template;

            if (is_readable($__template) && is_file($__template)) {
                include $__template;
            } else {
                ob_end_clean();
                throw new \Shade\Exception('Template file "'.$__template.'" does not exists');
            }
            $content = ob_get_clean();
        }

        return $content;
    }
572009
public function deferredRevenue(array $data = [], array $headers = [])
    {
        $url = $this->url('exports/deferred_revenue');

        return $this->post($url, $data, $headers);
    }
362324
public function visitComposerAutoloadFiles(ProjectAnalyzer $project_analyzer, $debug = false)
    {
        $this->collectPredefinedConstants();
        $this->collectPredefinedFunctions();

        $composer_json_path = $this->base_dir . 'composer.json'; // this should ideally not be hardcoded

        $autoload_files_files = [];

        if ($this->autoloader) {
            $autoload_files_files[] = $this->autoloader;
        }

        if (file_exists($composer_json_path)) {
            /** @psalm-suppress PossiblyFalseArgument */
            if (!$composer_json = json_decode(file_get_contents($composer_json_path), true)) {
                throw new \UnexpectedValueException('Invalid composer.json at ' . $composer_json_path);
            }

            if (isset($composer_json['autoload']['files'])) {
                /** @var string[] */
                $composer_autoload_files = $composer_json['autoload']['files'];

                foreach ($composer_autoload_files as $file) {
                    $file_path = realpath($this->base_dir . $file);

                    if ($file_path && file_exists($file_path)) {
                        $autoload_files_files[] = $file_path;
                    }
                }
            }

            $vendor_autoload_files_path
                = $this->base_dir . DIRECTORY_SEPARATOR . 'vendor'
                    . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'autoload_files.php';

            if (file_exists($vendor_autoload_files_path)) {
                /**
                 * @var string[]
                 * @psalm-suppress UnresolvableInclude
                 */
                $vendor_autoload_files = require $vendor_autoload_files_path;

                $autoload_files_files = array_merge($autoload_files_files, $vendor_autoload_files);
            }
        }

        $autoload_files_files = array_unique($autoload_files_files);

        if ($autoload_files_files) {
            $codebase = $project_analyzer->getCodebase();
            $codebase->register_autoload_files = true;

            foreach ($autoload_files_files as $file_path) {
                $codebase->scanner->addFileToDeepScan($file_path);
            }

            if ($debug) {
                echo 'Registering autoloaded files' . "\n";
            }

            $codebase->scanner->scanFiles($codebase->classlikes);

            if ($debug) {
                echo 'Finished registering autoloaded files' . "\n";
            }

            $codebase->register_autoload_files = false;
        }

        if ($this->autoloader) {
            // do this in a separate method so scope does not leak
            $this->requireAutoloader($this->autoloader);

            $this->collectPredefinedConstants();
            $this->collectPredefinedFunctions();
        }
    }
165819
protected function parseComposerJsonFiles ()
    {
        // First find all composer.json files that match pattern vendor-dev/*/*/composer.json
        $composerJsonFiles = array();

        $DirRoot = new \DirectoryIterator($this->rootPath);
        foreach ($DirRoot as $FileInRoot) {
            // Ignore non-directories
            if (!$FileInRoot->isDir()) {
                continue;
            }
            if ($FileInRoot->isDot()) {
                continue;
            }

            // Check if composer.json is present here - if so, do not recurse deeper
            $composerFile = $FileInRoot->getPathname() .'/composer.json';
            if (file_exists($composerFile)) {
                $composerJsonFiles[$composerFile] = $composerFile;
                continue;
            }

            $DirVendor = new \DirectoryIterator($FileInRoot->getPathname());
            foreach ($DirVendor as $FileInVendor) {
                // Ignore non-directories
                if (!$FileInVendor->isDir()) {
                    continue;
                }
                if ($FileInVendor->isDot()) {
                    continue;
                }

                $composerFile = $FileInVendor->getPathname() .'/composer.json';
                if (file_exists($composerFile)) {
                    $composerJsonFiles[$composerFile] = $composerFile;
                }
            }
        }

        // Sort by path to get predictable results
        ksort($composerJsonFiles);

        // Now parse all composer.jsons and extract namespace information
        foreach ($composerJsonFiles as $cjfPath) {
            $cjf = json_decode(file_get_contents($cjfPath), true);

            // Signal invalid json
            if (NULL === $cjf) {
                throw new \Exception("Unparseable composer.json file: '$cjfPath'");
            }

            // Skip if no autoload or no psr-4 section is present
            if (!isset($cjf['autoload'])) {
                continue;
            }
            if (!isset($cjf['autoload']['psr-4'])) {
                continue;
            }

            foreach ($cjf['autoload']['psr-4'] as $namespace => $relPath) {
                $absPath = dirname($cjfPath) .'/'. $relPath;

                // Do not allow overlapping namespaces for now
                if (isset($this->nsData[$namespace])) {
                    throw new \Exception("VendorDevLoader error: duplicate namespace definition. First instance defined in '". $this->namespace2path[$namespace]["composerJsonPath"] ."', second instance found in '$cjfPath'");
                }

                $this->nsData[$namespace] = array(
                    'namespace'        => $namespace,
                    'relPath'          => $relPath,
                    'absPath'          => $absPath,
                    'composerJsonPath' => $cjfPath,
                );
            }
        }

        // Now reverse sort it, so that the most specific namespace definition gets evaluated first
        krsort($this->nsData);
    }
266075
protected function process_ltisubmission($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;

        $data->ltiid = $this->get_new_parentid('lti');

        $data->datesubmitted = $this->apply_date_offset($data->datesubmitted);
        $data->dateupdated = $this->apply_date_offset($data->dateupdated);
        if ($data->userid > 0) {
            $data->userid = $this->get_mappingid('user', $data->userid);
        }

        $newitemid = $DB->insert_record('lti_submission', $data);

        $this->set_mapping('ltisubmission', $oldid, $newitemid);
    }
465045
public function data_postprocessing($data) {
        parent::data_postprocessing($data);
        if (!empty($data->completionunlocked)) {
            $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
            if (empty($data->completionentriesenabled) || !$autocompletion) {
                $data->completionentries = 0;
            }
        }
    }
841373
private function combineSheetDataWithHeadings(array $data, GSuiteHandlingSpecificationsInterface $gSuiteHandlingSpecifications): array
    {
        $headings = null;
        $outputData = [];

        foreach ($data as $row) {
            if (true === $this->isEmptyRow($row)) {
                continue;
            }

            // Skip non-headings rows until we find headings
            if (true === empty($headings) && false === $gSuiteHandlingSpecifications->isHeadingsRow($row)) {
                continue;
            }

            if (true === empty($headings) && true === $gSuiteHandlingSpecifications->isHeadingsRow($row)) {
                $headings = $row;
                continue;
            }

            // Slice first N elements from headings if row doesn't have values for ending columns
            $outputData[] = array_combine(
                array_slice($headings, 0, count($row)),
                $row
            );
        }

        return $outputData;
    }
322229
private function addDocumentsFromArray(array $data)
    {
        $_documentClass = $this->_documentClass;

        $this->_result[] = $_documentClass::createFromArray($data, $this->_options);
    }
705245
protected function findFiles()
    {
        $ds = new DirectoryScanner();
        $ds->setBasedir($this->dir);
        $ds->setIncludes(array('**/composer.json'));
        $ds->scan();
        return $ds->getIncludedFiles();
    }
986843
public function data_postprocessing($data) {
        parent::data_postprocessing($data);
        // Turn off completion setting if the checkbox is not ticked.
        if (!empty($data->completionunlocked)) {
            $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
            if (empty($data->completiontimespentenabled) || !$autocompletion) {
                $data->completiontimespent = 0;
            }
            if (empty($data->completionendreached) || !$autocompletion) {
                $data->completionendreached = 0;
            }
        }
    }
996644
public function data_postprocessing($data) {
        parent::data_postprocessing($data);

        foreach (['text', 'file'] as $type) {
            $field = 'submissiontype' . $type;
            $available = $field . 'available';
            $required = $field . 'required';
            if ($data->$required) {
                $data->$field = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
            } else if ($data->$available) {
                $data->$field = WORKSHOP_SUBMISSION_TYPE_AVAILABLE;
            } else {
                $data->$field = WORKSHOP_SUBMISSION_TYPE_DISABLED;
            }
            unset($data->$available);
            unset($data->$required);
        }
    }
866338
protected function loadComposerData($composerFile)
    {
        if (!is_readable($composerFile))
        {
            throw new ExceptionPackageInfo('Could not read composer data.');
        }

        $this->composerJson = json_decode(file_get_contents($composerFile), true);
    }
1117755
protected static function buildComposerJson(array $vars) {

    $document_root_path = $vars['document_root_path'];

    $composer_json = [];

    $composer_json['name'] = $vars['name'];
    $composer_json['description'] = $vars['description'];
    $composer_json['type'] = 'project';
    $composer_json['license'] = $vars['license'];

    $composer_json['repositories'][] = [
      'type' => 'composer',
      'url' => 'https://packages.drupal.org/8',
    ];
    if ($vars['asset_packagist']) {
      $composer_json['repositories'][] = [
        'type' => 'composer',
        'url' => 'https://asset-packagist.org',
      ];
    }

    $require = [];
    $require_dev = [];

    self::addPackage($require, 'drupal/core');
    $require['drupal/core'] = $vars['drupal'];
    self::addPackage($require, 'composer/installers');
    self::addPackage($require, 'drupal-composer/drupal-scaffold');
    self::addPackage($require, 'zaporylie/composer-drupal-optimizations');
    $require_dev['webflo/drupal-core-require-dev'] = $vars['drupal'];

    if ($vars['asset_packagist']) {
      self::addPackage($require, 'oomphinc/composer-installers-extender');
    }

    if ($vars['drupal_core_strict']) {
      $require['webflo/drupal-core-strict'] = $vars['drupal'];
    }

    if ($vars['drush']) {
      $vars['drush_installation'] == 'require'
        ? self::addPackage($require, 'drush/drush')
        : self::addPackage($require_dev, 'drush/drush');
    }

    if ($vars['drupal_console']) {
      $vars['drupal_console_installation'] == 'require'
        ? self::addPackage($require, 'drupal/console')
        : self::addPackage($require_dev, 'drupal/console');
    }

    if ($vars['composer_patches']) {
      self::addPackage($require, 'cweagans/composer-patches');
    }

    if ($vars['composer_merge']) {
      self::addPackage($require, 'wikimedia/composer-merge-plugin');
    }

    if ($vars['behat']) {
      // Behat and Mink drivers are Drupal core dev dependencies.
      self::addPackage($require_dev, 'drupal/drupal-extension');
    }

    if ($vars['env']) {
      self::addPackage($require, 'symfony/dotenv');
    }

    $composer_json['require'] = [
      'php' => $vars['php'],
      'ext-curl' => '*',
      'ext-gd' => '*',
      'ext-json' => '*',
    ];
    ksort($require);
    $composer_json['require'] += $require;

    ksort($require_dev);
    $composer_json['require-dev'] = $require_dev;

    // PHPUnit is core dev dependency.
    $composer_json['scripts']['phpunit'] = 'phpunit --colors=always --configuration ' . $document_root_path . 'core ' . $document_root_path . 'modules/custom';
    if ($vars['behat']) {
      $composer_json['scripts']['behat'] = 'behat --colors --config=tests/behat/local.behat.yml';
    }
    $composer_json['scripts']['phpcs'] = 'phpcs --standard=phpcs.xml';
    $composer_json['scripts']['post-install-cmd'][] = '@php ./scripts/composer/create_required_files.php';
    $composer_json['scripts']['post-update-cmd'][] = '@php ./scripts/composer/create_required_files.php';

    $composer_json['minimum-stability'] = 'dev';
    $composer_json['prefer-stable'] = TRUE;

    $composer_json['config'] = [
      'sort-packages' => TRUE,
      'bin-dir' => 'bin',
    ];

    if ($vars['env']) {
      $composer_json['autoload']['files'][] = 'load.environment.php';
    }

    if ($vars['composer_patches']) {
      $composer_json['extra']['composer-exit-on-patch-failure'] = TRUE;
    }

    if ($vars['asset_packagist']) {
      $composer_json['extra']['installer-types'] = [
        'bower-asset',
        'npm-asset',
      ];
    }
    $composer_json['extra']['installer-paths'] = [
      $document_root_path . 'core' => ['type:drupal-core'],
      $document_root_path . 'libraries/{$name}' => ['type:drupal-library'],
      $document_root_path . 'modules/contrib/{$name}' => ['type:drupal-module'],
      $document_root_path . 'themes/{$name}' => ['type:drupal-theme'],
      'drush/{$name}' => ['type:drupal-drush'],
    ];
    if ($vars['asset_packagist']) {
      $composer_json['extra']['installer-paths'][$document_root_path . 'libraries/{$name}'][] = 'type:bower-asset';
      $composer_json['extra']['installer-paths'][$document_root_path . 'libraries/{$name}'][] = 'type:npm-asset';
    }

    $composer_json['extra']['drupal-scaffold']['excludes'] = [
      '.csslintrc',
      '.editorconfig',
      '.eslintignore',
      '.eslintrc.json',
      '.gitattributes',
      '.ht.router.php',
      '.htaccess',
      'robots.txt',
      'update.php',
      'web.config',
    ];
    // Initial files are created but never updated.
    $composer_json['extra']['drupal-scaffold']['initial'] = [
      '.htaccess' => '.htaccess',
      'robots.txt' => 'robots.txt',
    ];

    // Move these files to Composer root.
    if ($vars['document_root']) {
      $composer_json['extra']['drupal-scaffold']['initial']['.editorconfig'] = '../.editorconfig';
      $composer_json['extra']['drupal-scaffold']['initial']['.gitattributes'] = '../.gitattributes';
    }
    ksort($composer_json['extra']['drupal-scaffold']['initial']);

    if ($vars['composer_merge']) {
      $composer_json['extra']['merge-plugin'] = [
        'include' => [
          $document_root_path . 'modules/custom/*/composer.json',
        ],
        'recurse' => TRUE,
      ];
    }

    return json_encode($composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
  }
951711
public function data_postprocessing($data) {
        parent::data_postprocessing($data);
        // Turn off completion settings if the checkboxes aren't ticked
        if (!empty($data->completionunlocked)) {
            $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
            if (empty($data->completiondiscussionsenabled) || !$autocompletion) {
                $data->completiondiscussions = 0;
            }
            if (empty($data->completionrepliesenabled) || !$autocompletion) {
                $data->completionreplies = 0;
            }
            if (empty($data->completionpostsenabled) || !$autocompletion) {
                $data->completionposts = 0;
            }
        }
    }
1347908
public function runCommandFromData(array $data, $from_working_directory = '')
    {
        return $this->runCommand($this->prepareCommandFromData($data), $from_working_directory, $data['log_to_file'], $data['in_background']);
    }
608463
protected function process(array $data)
        {
            $config = array();

            foreach ($data as $section => $value) {
                if (Arrays::isArray($value)) {
                    if (strpos($section, $this->nestSeparator) !== false) {
                        $sections = explode($this->nestSeparator, $section);
                        $config = array_merge_recursive($config, $this->buildNestedSection($sections, $value));
                    } else {
                        $config[$section] = $this->processSection($value);
                    }
                } else {
                    $this->processKey($section, $value, $config);
                }
            }

            return $config;
        }