Parses TypoScript configuration string.

@param array $entries User-defined translation entries via TypoScript
@return array Associative list of translation domain and original string / list of tranlations
174924
protected static function parseTranslations( array $entries )
	{
		$translations = array();

		foreach( $entries as $entry )
		{
			if( isset( $entry['domain'] ) && isset( $entry['string'] ) && isset( $entry['trans'] ) )
			{
				$string = str_replace( ['\\n', '\\'], ["\n", ''], $entry['string'] );
				$trans = array();

				foreach( (array) $entry['trans'] as $str ) {
					$trans[] = str_replace( ['\\n', '\\'], ["\n", ''], $str );
				}

				$translations[$entry['domain']][$string] = $trans;
			}
		}

		return $translations;
	}
53668
public function add_entry_or_merge($entry)
    {
        if (is_array($entry)) {
            $entry = new EntryTranslations($entry);
        }
        $key = $entry->key();
        if (false === $key) {
            return false;
        }
        if (isset($this->entries[$key])) {
            $this->entries[$key]->merge_with($entry);
        } else {
            $this->entries[$key] = &$entry;
        }

        return true;
    }
245463
private function parseHeaders(array $headers)
    {

        // Set the raw headers as we got from the constructor.
        $this->raw_headers = $headers;

        // flatten the headers array so that values are not arrays themselves
        // but rather simple key value pairs.
        $headers = array_map(function ($value) {

            if (! is_array($value))
                return $value;

            return implode(';', $value);
        }, $headers);

        // Set the parsed headers.
        $this->headers = $headers;

        // Check for some header values that might be interesting
        // such as the current error limit and number of pages
        // available.
        $this->hasHeader('X-Esi-Error-Limit-Remain') ?
            $this->error_limit = (int) $this->getHeader('X-Esi-Error-Limit-Remain') : null;

        $this->hasHeader('X-Pages') ? $this->pages = (int) $this->getHeader('X-Pages') : null;
    }
885069
public static function parseTS( $tsString )
	{
		$parser = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser' );
		$parser->parse( $tsString );

		if( !empty( $parser->errors ) ) {
			throw new \InvalidArgumentException( 'Invalid TypoScript: \"' . $tsString . "\"\n" . print_r( $parser->errors, true ) );
		}

		$service = GeneralUtility::makeInstance( 'TYPO3\CMS\Extbase\Service\TypoScriptService' );
		$tsConfig = $service->convertTypoScriptArrayToPlainArray( $parser->setup );

		// Allows "plugin.tx_aimeos.settings." prefix everywhere
		if( isset( $tsConfig['plugin']['tx_aimeos']['settings'] )
			&& is_array( $tsConfig['plugin']['tx_aimeos']['settings'] )
		) {
			$tsConfig = array_replace_recursive( $tsConfig['plugin']['tx_aimeos']['settings'], $tsConfig );
			unset( $tsConfig['plugin']['tx_aimeos'] );
		}

		return $tsConfig;
	}
1141423
private function formatRecords(array $entry)
    {
        $entries = str_split($entry['formatted'], self::EVENT_SIZE_LIMIT);
        $timestamp = $entry['datetime']->format('U.u') * 1000;
        $records = [];

        foreach ($entries as $entry) {
            $records[] = [
                'message' => $entry,
                'timestamp' => $timestamp
            ];
        }

        return $records;
    }
1050652
public function renderSitemap(array $entries)
    {
        $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
        $data .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
        foreach ($entries as $entry) {
            $data .= '    <url>' . PHP_EOL;
            $data .= '        <loc>' . $entry->getLoc() . '</loc>' . PHP_EOL;
            if (null !== $entry->getLastMod()) {
                $data .= '        <lastmod>' . $entry->getLastMod() . '</lastmod>' . PHP_EOL;
            }
            if (null !== $entry->getChangeFreq()) {
                $data .= '        <changefreq>' . $entry->getChangeFreq() . '</changefreq>' . PHP_EOL;
            }
            if (null !== $entry->getPriority()) {
                $data .= '        <priority>' . $entry->getPriority() . '</priority>' . PHP_EOL;
            }
            $data .= '    </url>' . PHP_EOL;
        }

        $data .= '</urlset>' . PHP_EOL;

        return $data;
    }
514361
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            $translations = (array)$row['_i18n'];
            if (count($translations) === 0 && $row->get('_translations')) {
                return $row;
            }

            $result = [];
            foreach ($translations as $translation) {
                unset($translation['id']);
                $result[$translation['locale']] = $translation;
            }

            $row['_translations'] = $result;
            unset($row['_i18n']);
            if ($row instanceof EntityInterface) {
                $row->clean();
            }

            return $row;
        });
    }
252703
public function export_translations(EntryTranslations $entry)
    {
        //TODO: warnings for control characters
        return $entry->is_plural ? implode(chr(0), $entry->translations) : $entry->translations[0];
    }
880002
protected function parseFields($fields)
    {
        $fieldsArray = explode(',', $fields);
        $text = '$this'."\n";

        foreach ($fieldsArray as $field) {
            $text .= $this->prepareAdd($field, end($fieldsArray) == $field);
        }

        return $text.';';
    }
854214
protected function writeComments(array $entry)
    {
        $result = '';

        if ($entry['tcomment'] !== '') {
            $result .= "# " . $entry['tcomment'] . "\n";
        }

        if ($entry['ccomment'] !== '') {
            $result .= '#. ' . $entry['ccomment'] . "\n";
        }

        return $result;
    }
953869
protected function formatEntries($entries)
    {
        $entries = Arr::flatten($entries);
        $entries = implode(PHP_EOL, $entries);
        $entries = trim($entries);

        return $entries;
    }
487473
public static function ParseHttpAcceptLang ($languagesList) {
		$languages = [];
		$languageRanges = explode(',', trim($languagesList));
		foreach ($languageRanges as $languageRange) {
			$regExpResult = preg_match(
				"/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/",
				trim($languageRange),
				$match
			);
			if ($regExpResult) {
				$priority = isset($match[2])
					? (string) floatval($match[2])
					: '1.0';
				if (!isset($languages[$priority])) $languages[$priority] = [];
				$langOrLangWithLocale = str_replace('-', '_', $match[1]);
				$delimiterPos = strpos($langOrLangWithLocale, '_');
				if ($delimiterPos !== FALSE) {
					$languages[$priority][] = [
						strtolower(substr($langOrLangWithLocale, 0, $delimiterPos)),
						strtoupper(substr($langOrLangWithLocale, $delimiterPos + 1))
					];
				} else {
					$languages[$priority][] = [
						strtolower($langOrLangWithLocale),
						NULL
					];
				}
			}
		}
		krsort($languages);
		reset($languages);
		return $languages;
	}
1270259
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            if (!$row instanceof EntityInterface) {
                return $row;
            }
            $translations = (array)$row->get('_i18n');
            if (empty($translations) && $row->get('_translations')) {
                return $row;
            }
            $grouped = new Collection($translations);

            $result = [];
            foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
                $entityClass = $this->_table->getEntityClass();
                $translation = new $entityClass($keys + ['locale' => $locale], [
                    'markNew' => false,
                    'useSetters' => false,
                    'markClean' => true
                ]);
                $result[$locale] = $translation;
            }

            $options = ['setter' => false, 'guard' => false];
            $row->set('_translations', $result, $options);
            unset($row['_i18n']);
            $row->clean();

            return $row;
        });
    }
451356
public function parseHeaders(array $headers)
    {
        $parsed = [];

        foreach ($headers as $key => $val)
        {
            $parsed[] = $key . ': ' . $val;
        }

        return $parsed;
    }
415072
private function parseIniString($data)
    {
        $config = $this->arr();
        $data = parse_ini_string($data, true);
        foreach ($data as $section => $value) {
            $config = $config->mergeRecursive($this->processValue($section, $value));
        }

        return $config;
    }
501030
protected function createData(array $entries): array
    {
        $rows = [];

        foreach ($entries as $entry) {
            $rows[] = $this->createEntryData($entry);
        }

        return [
            'version' => self::VERSION,
            'columns' => [self::COLUMN_LOG, self::COLUMN_TYPE, self::COLUMN_BACKTRACE],
            'rows' => $rows,
        ];
    }
60609
protected function writeMsgStr(array $entry)
    {
        $result = '';

        if (!isset($entry['msgstr'])) {
            return $result;
        }

        $isPlural = isset($entry['msgid_plural']);

        foreach ($entry['msgstr'] as $i => $value) {
            if ($entry['obsolete']) {
                $result .= "#~ ";
            }

            if ($isPlural) {
                $result .= "msgstr[$i] ";
            } else {
                if ($i == 0) {
                    $result .= 'msgstr ';
                }
            }

            $result .= $this->cleanExport($value) . "\n";
        }

        return $result;
    }