Parses the $rawFiles and does sanity checks

@throws ErrorException
@throws Asset\NotFoundException
330197
public function init()
    {
        if (empty($this->rawFiles)) {
            throw new ErrorException('No file specified; make sure you are using the correct .htaccess rules.');
        }

        // Handle legacy code for minifying
        if (preg_match('%^/minify/%', $this->rawFiles)) {
            $this->rawFiles = substr($this->rawFiles, 7);
            $this->setRawParam('minify', 'true');
        }

        $this->ext = strtolower(pathinfo($this->rawFiles, PATHINFO_EXTENSION));
        $supportedExtensions = Registry::getSupportedExtensions($this->ext);
        // Suppressing errors because Exceptions thrown in the callback cause Warnings.
        $webroot = $this->webroot;
        $this->files = @array_map(function($v) use ($supportedExtensions, $webroot) {
            // Make sure all the file extensions are supported
            if (! in_array(strtolower(pathinfo($v, PATHINFO_EXTENSION)), $supportedExtensions)) {
                throw new ErrorException('All requested files need to be: ' . implode(', ', $supportedExtensions));
            }
            // Strip any parent directory slugs (../) - loop through until they are all gone
            $count = 1;
            while ($count > 0) {
                $v = preg_replace('%(/\\.\\.?|\\.\\.?/)%', '', $v, -1, $count);
                // If there is no slash prefix, add it back in
                if (substr($v, 0, 1) != '/') {
                    $v = '/' . $v;
                }
            }

            // Remove sub-folder if in the path, it shouldn't be there.
            $v = str_replace(SUB_FOLDER, '', $v);

            return $webroot . $v;
        }, explode(',', $this->rawFiles));
    }
694192
private function parseRoutes()
	{
		$this->bad_routes = array();
		
		foreach($this->routes as $r => $route)
		{
			if (strpos($route, 'not:') !== false)
			{
				$bad_route =  substr($route, strpos($route, "not:")+4);

				$this->bad_routes[] = $bad_route;

				unset($this->routes[$r]);
			}
		}
	}
335653
protected function doParse()
    {
        // just make it work modified base class
        $this->document = $this->data;
        $object = $this->objectName;

        if (!$this->document instanceof SimpleXmlElement) {
            throw new RuntimeException('document is not instance of SimpleXmlElement');
        }

        if ('ok' !== (string) $this->document->attributes()->stat) {
            $errorCode = (integer) $this->document->err->attributes()->code;
            $errorMessage = (string) $this->document->err;

            if (in_array($errorCode, array(1, 15))) {
                throw new AuthenticationErrorException($errorMessage, $errorCode);
            } else {
                throw new RuntimeException($errorMessage, $errorCode);
            }
        }

        if ('login' == $object) {
            $this->result = (string) $this->document->api_key;
        } else {
            if (!empty($this->document->result)) {
                $this->resultCount = (integer) $this->document->result->total_results;
                $this->result = $this->document->xpath('/rsp/result/'.$object);
            } elseif (!empty($this->document->$object)) {
                $this->resultCount = 1;
                $this->result = array($this->document->$object);
            } else {
                throw new RuntimeException('Unknown response format');
            }
        }
    }
1134374
protected function _load()
    {
        $file = new File($this->_file, "r");

        $data = @parse_ini_string($file->read(), true);
        if ($data === false) {
            throw new Exception\ParserErrorException(
                "Error parsing configuration file {$this->_file}"
            );
        }
        $this->_data = $data;
    }
852325
private function parse()
    {
        $handle = fopen($this->filepath, 'r');
        if(! $handle) throw new \Exception("Can't read file $this->filepath");

        $plugin = null;

        while(($line = fgets($handle)) !== false) {

            /* Skip comments and empty lines */
            if(starts_with($line, '#') || trim($line) === '') continue;

            /* Find description setting */
            else if(starts_with($line, 'description')) $this->parseDescription($line);

            /* Find help setting */
            else if(starts_with($line, 'help')) $this->parseHelp($line);

            /* Capture commands */
            else if(starts_with_whitespace($line)) $plugin->parseCommand($line);

            /* Start plugin capture */
            else {
                $plugin = $this->parseCurrentPlugin($line);
            }
        }

        fclose($handle);

        /* Set state as parsed */
        $this->isParsed = true;
    }
299512
public function parse($rawOutput)
    {
        if (!is_string($rawOutput)) {
            return false;
        }

        $rawOutput = trim($rawOutput);

        $this->rawOutput = $rawOutput;
        $this->decodedRawOutput = new DecodedRawOutput(trim($rawOutput));

        $exceptionFactory = new ExceptionFactory($rawOutput);

        if ($exceptionFactory->isInputFileNotFoundException()) {
            throw $exceptionFactory->createInputFileNotFoundException();
        }

        if ($exceptionFactory->isIncorrectNodeJsPathException()) {
            throw $exceptionFactory->createIncorrectNodeJsPathException();
        }

        if (!$this->decodedRawOutput->isWellFormed()) {
            throw new NodeJsLintOutputException(
                'Unexpected output; is not a lint result set',
                NodeJsLintOutputException::CODE_UNEXPECTED_OUTPUT
            );
        }

        $statusLine = $this->decodedRawOutput->getStatusLine();
        $entries = $this->decodedRawOutput->getLintResult();

        $this->nodeJsLintOutput = new NodeJslintOutput();
        $this->nodeJsLintOutput->setStatusLine($statusLine);

        if (empty($entries)) {
            return $this->nodeJsLintOutput;
        }

        $entryParser = new EntryFactory();

        foreach ($entries as $entryData) {
            if (!is_null($entryData)) {
                $this->nodeJsLintOutput->addEntry($entryParser->create($entryData));
            }
        }

        return $this->nodeJsLintOutput;
    }
186002
public function parse()
    {
        if (!is_file($this->file)) {
            throw new \Exception(sprintf(
                'Template "%s" file doesn\'t exist!', $this->file
            ));
        }

        $fp = fopen($this->file, 'r');

        $lineCount       = 0;
        $nextToken       = '';
        $block           = '';
        $currentValue    = '';
        $stringComposing = false;
        $skipMultilineComment = false;

        while (($line = fgets($fp)) !== false) {
            $lineCount++;

            if ($stringComposing) {
                if (substr(ltrim($line), 0, 3) === '>>>') {
                    $this->blocks[$block][$name] = trim($value);
                    //$block = '';
                    $value = '';
                    $stringComposing = false;
                } else {
                    // $line = trim($line);
//                     if (substr($value, -1) != '>' && ! empty($line)) {
//                         $line = " " . $line;
//                     }

                    //$value .= substr($value, -1) == '>' ? trim($line) : " " . trim($line);
                    $value .= $line;
                }

                continue;
            }

            $line = trim($line);

            if (substr($line, 0, 1) === '#' || $line === '' || substr($line, 0, 2) === '//') {
                continue; // skip single comments or empty lines
            } elseif (substr($line, 0, 2) === '/*') { // start multiline comment
                if (strpos($line, '*/') === false) {
                    $skipMultilineComment = true; // activate multiline comments skipping
                } else {
                    continue; // just skip this line, it has the form: /* ... */
                }
            } elseif (strpos($line, '*/') !== false) { // end multiline comment
                $skipMultilineComment = false;
                continue; // just skip the end multiline comment
            }

            if ($skipMultilineComment) {
                continue; //skip multiline comments segment
            }

            $kwPattern = '^@(?<keyword>\w+)';

            if (! preg_match('/'.$kwPattern.'.*/', $line, $matches)) {
                throw new \Exception(sprintf(
                    'Parse Error: Unknow keyword, lines must starts with a valid keyword, near: %s, on line %s',
                    $line, $lineCount
                ));
            }
            //var_dump($matches);
            $keyword = $matches['keyword'];

            switch ($keyword) {
                case Parser::T_DEF:
                    $pattern = '/'.$kwPattern.'\s+(?<type>[\w]+)\s+(?<name>[\w.]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new \Exception(sprintf(
                            "Syntax Error: near: '%s', on line %s.\n" .
                            "Syntax should be: @def <type> <name> <value>",
                            $line, $lineCount
                        ));
                    }

                    $keyword = $matches['keyword'];
                    $type    = $matches['type'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    $tmp     = explode('.', $name);
                    $defName = $tmp[0];
                    $defProp = isset($tmp[1]) ? $tmp[1] : '';

                    switch ($type) {
                        case Parser::T_GLOBAL:
                        case Parser::T_ITERATOR:
                        case Parser::T_SETCONF:
                            if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                                $value = trim($value, '"');
                            } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                                $value = trim($value, "'");
                            }

                            if ($value === '\n' || $value === '\r\n') {
                                $value = "\n";
                            }

                            $value = self::castValue($value);

                            if (empty($defProp)) {
                                $this->defs[$type][$defName] = $value;
                            } else {
                                $this->defs[$type][$defName][$defProp] = $value;
                            }
                            break;
                        default:
                            throw new \Exception(sprintf(
                                'Parse Error: unknow definition type: "%s" on line %s.', $type, $lineCount
                            ));
                    }
                    break;
                case Parser::T_BLOCK:
                    $pattern = '/'.$kwPattern.'\s+(?<block>[\w]+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @def <type> <name> <value>",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //var_dump($matches);

                    $block = $matches['block'];

                    if (!empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_BLOCK
                        ));
                    }

                    $nextToken = Parser::T_END;
                    break;
                case Parser::T_END:
                    if (empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: close keyword: @"%s" given, but any block was started.', Parser::T_BLOCK
                        ));
                    }

                    if ($nextToken !== Parser::T_END) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_END
                        ));
                    }

                    $nextToken = '';
                    break;
                case Parser::T_VAR:
                    $pattern = '/'.$kwPattern.'\s+(?<name>[\w]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @var <name> <value>\n or \n" .
                            "@var <name> <<<\nsome large string\nmultiline...\n>>>\n\n",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //print_r($matches);
                    $keyword = $matches['keyword'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    if (substr($value, 0, 3) === '<<<' && $value !== '<<<') {
                        throw new \Exception(sprintf(
                            "Syntax Error: multiline string must starts on new line after open braces <<<\n" .
                            "near: '%s', on line %s", $line, $lineCount
                        ));
                    }

                    if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                        $value = trim($value, '"');
                    } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                        $value = trim($value, "'");
                    }

                    if ($value !== '<<<') {
                        $this->blocks[$block][$name] = self::castValue($value);
                    } else {
                        $value = '';
                        $stringComposing = true;
                    }
                    break;
                default:
                    throw new \Exception(sprintf(
                        'Parse Error: Unknown definition type: %s, on line %s', $type, $lineCount
                    ));
            }

        }

        if ($stringComposing) {
            throw new \Exception(sprintf(
                "Parse Error: Multiline string closing braces are missing '>>>',\nfor @block: '%s', @var: '%s' " .
                "until end of file.", $block, $name
            ));
        }
    }
985616
private static function parseUploadedFiles(array $uploadedFiles) {
        $parsed = array();

        foreach ($uploadedFiles as $field => $uploadedFile) {
            if (!isset($uploadedFile['error'])) {
                if (is_array($uploadedFile)) {
                    $parsed[$field] = static::parseUploadedFiles($uploadedFile);
                }
                continue;
            }
            $parsed[$field] = array();

            if (!is_array($uploadedFile['error'])) {
                $parsed[$field] = new static(
                        $uploadedFile['tmp_name'], isset($uploadedFile['name']) ? $uploadedFile['name'] : null, isset($uploadedFile['type']) ? $uploadedFile['type'] : null, isset($uploadedFile['size']) ? $uploadedFile['size'] : null, $uploadedFile['error'], true
                );
            } else {
                foreach ($uploadedFile['error'] as $fileIdx => $error) {
                    $parsed[$field][] = new static(
                            $uploadedFile['tmp_name'][$fileIdx], isset($uploadedFile['name']) ? $uploadedFile['name'][$fileIdx] : null, isset($uploadedFile['type']) ? $uploadedFile['type'][$fileIdx] : null, isset($uploadedFile['size']) ? $uploadedFile['size'][$fileIdx] : null, $uploadedFile['error'][$fileIdx], true
                    );
                }
            }
        }

        return $parsed;
    }
298369
public function parse() {
        /* @var $scope_resource AbstractResourceFile */
        $scope_resource = $this->getScope();
        if (!$scope_resource instanceof AbstractResourceFile) {
            throw new InvalidConfigException("INVALID scope resource file to parse.");
        }
        $contents = str_replace("\r", "\n", $this->contents);
        $annotation_lines = explode("\n", $contents);
        foreach ($annotation_lines as $annotation_line) {
            $annotation_line = trim($annotation_line);
            $matches = array();
            if ('@' !== substr($annotation_line, 0, 1)) {
                continue;
            }
            $this->say($annotation_line . '[' . $this->scope->getRealPath() . ']');
            if (preg_match('#^@([a-zA-Z]+)\s(.+)$#', $annotation_line, $matches)) {
                $command_name = $matches[1];
                $params = $matches[2];
            } elseif (preg_match('#^@([0-9a-zA-Z\/\\\]+)\((.*)\)$#', $annotation_line, $matches)) {
                $command_name = $matches[1];
                $params = $matches[2];
            } else {
                continue;
            }
            // Get the instance
            if ('require' === strtolower($command_name)) {
                $command_annotation = new RequireAnnotation($this);
            } elseif ('use' === strtolower($command_name)) {
                $command_annotation = new UseAnnotation($this);
            } elseif (class_exists($command_name)) {
                $command_annotation = new $command_name($this);
            } else {
                continue;
            }
            if ($command_annotation instanceof AbstractAnnotation) {
                $command_annotation->parse($params);
                StaticsManager::registAnnotation($command_annotation);
            }
        }
    }
115525
private function parsing() : void
    {
        $lines = explode("\n", $this->raw);

        foreach ($lines as $line) {
            // check "at" mark
            if (false === strpos($line, '@')) {
                continue;
            }

            // check inline annotation
            if ($anp = strpos($line, '//')) {
                $line = substr($line, 0, $anp);
            }

            // trim blanks
            $line = trim(ltrim($line, ' *'));

            // analyze expr
            if (false === $fws = strpos($line, ' ')) {
                // @some-key
                $key = substr($line, 1);
                $val = true;
            } else {
                // @some-key some-val
                $key = substr($line, 1, $fws - 1);
                $val = trim(substr($line, $fws));
            }

            $this->lines[] = [$key, $val];

            $this->declares[$key][] = $val;
        }
    }
550103
protected static function parseFiles(array $files)
    {
        $normalizedFiles = array();

        foreach($files as $name => $file)
        {
            if(is_array($file) && !isset($file['tmp_name']))
                $normalizedFiles[$name] = static::parseFiles($file);
            else if(isset($file['tmp_name']) && is_array($file['tmp_name']))
                $normalizedFiles[$name] = static::normalizeFilesTree($file);
            else if(isset($file['tmp_name']))
                $normalizedFiles[$name] = new static(
                    $file['name'], $file['type'], $file['tmp_name'], $file['error'], $file['size']
                    );
        }

        return $normalizedFiles;
    }
705632
public function parse($arrAttributes=null)
    {
        if (!$this->blnValuesPrepared) {
            $arrSet = array();
            $arrValues = array();
            $arrUuids = array();
            $arrTemp = array();

            if (!empty($this->varValue)) { // Can be an array

                $this->varValue = (array) $this->varValue;

                foreach ($this->varValue as $varFile) {
                    if (\Validator::isUuid($varFile)) {
                        $arrUuids[] = $varFile;
                    } else {
                        $arrTemp[] = $varFile;
                    }
                }

                $objFiles = \FilesModel::findMultipleByUuids($arrUuids);

                // Get the database files
                if ($objFiles !== null) {
                    while ($objFiles->next()) {
                        $chunk = $this->generateFileItem($objFiles->path);

                        if (strlen($chunk)) {
                            $arrValues[$objFiles->uuid] = array
                            (
                                'id' => (in_array($objFiles->uuid, $arrTemp) ? $objFiles->uuid : \StringUtil::binToUuid($objFiles->uuid)),
                                'value' => $chunk
                            );

                            $arrSet[] = $objFiles->uuid;
                        }
                    }
                }

                // Get the temporary files
                foreach ($arrTemp as $varFile) {
                    $chunk = $this->generateFileItem($varFile);

                    if (strlen($chunk)) {
                        $arrValues[$varFile] = array
                        (
                            'id' => (in_array($varFile, $arrTemp) ? $varFile : \StringUtil::binToUuid($varFile)),
                            'value' => $chunk
                        );

                        $arrSet[] = $varFile;
                    }
                }
            }

            // Parse the set array
            foreach ($arrSet as $k=>$v) {
                if (in_array($v, $arrTemp)) {
                    $strSet[$k] = $v;
                } else {
                    $arrSet[$k] = \StringUtil::binToUuid($v);
                }
            }

            $this->set = implode(',', $arrSet);
            $this->values = $arrValues;
            $this->deleteTitle = specialchars($GLOBALS['TL_LANG']['MSC']['delete']);
            $this->extensions = json_encode(trimsplit(',', $this->arrConfiguration['extensions']));
            $this->limit = $this->arrConfiguration['uploaderLimit'] ? $this->arrConfiguration['uploaderLimit'] : 0;
            $this->minSizeLimit = $this->arrConfiguration['minlength'] ? $this->arrConfiguration['minlength'] : 0;
            $this->sizeLimit = $this->arrConfiguration['maxlength'] ? $this->arrConfiguration['maxlength'] : 0;
            $this->chunkSize = $this->arrConfiguration['chunkSize'] ? $this->arrConfiguration['chunkSize'] : 0;
            $this->concurrent = $this->arrConfiguration['concurrent'] ? true : false;
            $this->maxConnections = $this->arrConfiguration['maxConnections'] ? $this->arrConfiguration['maxConnections'] : 3;

            $this->blnValuesPrepared = true;
        }

        return parent::parse($arrAttributes);
    }
1104894
public function load()
	{
		$filename = $this->getFile();
		if (!file_exists($filename))
			return;

		$json = file_get_contents($filename);
		if (strlen($json) == 0)
			return;

		$data = $this->decode($json);
		if ($data === null)
			throw new Exception('Error while trying to decode ' . $filename . '.');

		$this->data = $data;

		if (!$this->verify())
			throw new Exception($filename . ' failed checksum validation.');
	}
1251750
function parseRequestData($rawInput = NULL)
    {
        try {

            if ($rawInput == NULL)
                throw new Exception ("Input must be defined", 503);

            $result = array();

            if (is_string($rawInput))
                $result = json_decode($rawInput, TRUE);

            if (is_array($rawInput))
                $result = $rawInput;

            if (is_object($rawInput))
                $result = json_decode(json_encode($rawInput), TRUE);

            return $result;

        } catch (Exception $e) {
            die("Exception raised: " . $e->getMessage() . "\nFile: " . $e->getFile() . "\nLine: " . $e->getLine());
        }
    }
909237
private function parseOriginalContent()
    {
        $content = $this->exists() ? file_get_contents($this->getPath()) : '';
        $this->arrayKeys = JsonFormatter::getArrayKeys($content);
        $this->indent = JsonFormatter::getIndent($content);
    }
1306001
public function readPoFile(string $file, ?resource $context = null): void
    {
        $oldEr = error_reporting(E_ALL ^ E_WARNING);
        $source = file_get_contents($file, false, $context);
        error_reporting($oldEr);
        if (false===$source) {
            throw new FileNotReadableException($file);
        }
        $this->parsePoSource($source);
    }
325919
protected function parsePost()
    {
        $ret = $_POST ?: [];
        if (isset($_FILES)) {
            foreach ($_FILES as $name => $info) {
                if (is_array($info["name"])) {
                    $len = count($info["name"]);
                    for ($i = 0; $i < $len; $i++) {
                        $file = $this->createUploadedFile([
                            "name" => $info["name"][$i] ?? "",
                            "type" => $info["type"][$i] ?? "",
                            "tmp_name" => $info["tmp_name"][$i] ?? "",
                            "error" => $info["error"][$i] ?? 0,
                            "size" => $info["size"][$i] ?? 0,
                        ]);
                        \sndsgd\Arr::addValue($ret, $name, $file);
                    }
                } else {
                    $file = $this->createUploadedFile($info);
                    \sndsgd\Arr::addValue($ret, $name, $file);
                }
            }
        }
        return $ret;
    }