Parses Log File.
@access		protected
@return		array
772289
protected function parseLine( $line )
	{
		$data	= preg_replace_callback( $this->patterns, array( $this, 'callback' ), $line );
		return unserialize( $data );
	}
951146
private function logAfterParsingAllFiles()
    {
        if (!$this->stopwatch) {
            return;
        }

        $event = $this->stopwatch->stop('parser.parse');

        $this->log('Elapsed time to parse all files: ' . round($event->getDuration() / 1000, 2) . 's');
        $this->log('Peak memory usage: ' . round($event->getMemory() / 1024 / 1024, 2) . 'M');
    }
1280329
public function parse()
    {
        $nextCursor = (int) $this->body[0];
        return array_merge([
            'finished' => (0 === $nextCursor),
            'nextCursor' => $nextCursor,
        ], $this->parseBody((array) $this->body[1]));
    }
382725
private function parseTextFile()
    {
        $data = file($this->inputTextFile);

        $timeZoneMap = array();

        foreach ($data as $line) {
            // Remove \n
            $line = str_replace(array("\n", "\r"), '', $line);
            $line = trim($line);

            if (strlen($line) == 0 || substr($line, 0, 1) == '#') {
                continue;
            }
            if (strpos($line, '|')) {
                // Valid line
                $parts = explode('|', $line);


                $prefix = $parts[0];
                $timezone = $parts[1];

                $timeZoneMap[$prefix] = $timezone;
            }
        }

        return $timeZoneMap;
    }
799019
public function getLogFiles()
    {
        $files = new Finder();
        $files->files()->in(LOG_DIR)->name('*.log')->sortByModifiedTime();
        $logs = array();
        /** @var \SplFileInfo $file */
        foreach ($files as $file) {
            $size = $file->getSize() / 8 / 1024;
            $time = date('c', $file->getMTime());
            $dateTime = new \DateTime($time);
            if (!isset($logs[$dateTime->format('Y')])) {
                $logs[$dateTime->format('Y')] = [];
            }
            $logs[$dateTime->format('Y')][$dateTime->format('m')][$time] = [
                'filename' => $file->getFilename(),
                'size' => round($size, 3),
            ];
            krsort($logs[$dateTime->format('Y')][$dateTime->format('m')]);
            krsort($logs[$dateTime->format('Y')]);
        }
        return $logs;
    }
655417
private function getLogFileName() : string
    {
        $file_name = $this->file_name;
        if ($this->filename_processor){
            $file_name = $this->filename_processor->process($file_name);
        }
        $file_name = self::escapeFileName($file_name);
        return $file_name;
    }
902972
public function parse(array &$file2): array
    {
        $i = 0;
        foreach ($file2 as &$line) {
            ++$i;

            // Null byte and carriage return removal. (CR+LF)
            $line = str_replace(["\x00", "\r", "\n"], '', $line);

            // Basic sanitization, remove non printable chars.
            $lineTrim = \trim($line);
            $line = \preg_replace($this->stripChars, '', $lineTrim);
            $line_bytes = \strlen($line);

            if ($line_bytes !== \strlen($lineTrim)) {
                $this->errors[] = "There's a not printable character on line " . $i . ": " . $lineTrim;
            }

            if ($line_bytes < 2) {
                continue;
            }

            switch (\substr($line, 0, 3)) {
                case "UNA":
                    if (!$this->unaChecked) {
                        $this->analyseUNA(\substr($line, 4, 6));
                    }
                    break;
                case "UNB":
                    $line = $this->splitSegment($line);
                    if (!$this->unbChecked) {
                        $this->analyseUNB($line[1]);
                    }
                    $this->parsedfile[] = $line;
                    break;
                case "UNH":
                    $line = $this->splitSegment($line);
                    $this->analyseUNH($line);
                    $this->parsedfile[] = $line;
                    break;
                default:
                    $line = $this->splitSegment($line);
                    $this->parsedfile[] = $line;
                    break;
            }
        }

        return $this->parsedfile;
    }
88916
private function parseFile()
    {
        $contents = file_get_contents($this->getPath());
        $lines = new Collection(explode("\n", $contents));
        $result = new Collection();

        $lines->filter(function ($value) {
            return $value;
        })->each(function ($value) use ($result) {
            preg_match('/([a-zA-Z_-]+)\=(.+)/', $value, $regexResult);

            array_shift($regexResult);
            $result->push(new Collection($regexResult));
        });

        return $result;
    }
671747
public function getConfig(): array
    {
        if (empty($this->config)) {
            $yamlParser = new Parser();
            $files = $this->getFileNames();
            $config = [];
            foreach ($files as $file) {
                $fileConfig = $yamlParser->parseFile($file);
                $config = \array_merge($config, $fileConfig);
            }
            $this->config = $config;
        }
        return $this->config;
    }
152716
public function log() {
		$this->empty = true;
		$log = array ();
		
		$pattern = "/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/";
		
		$log_levels = $this->getLevels ();
		
		//$log_file = glob ( $this->path . '/log-' . $this->sapi . '*-' . $this->fileName . '.txt' );
		$log_file = $this->path.'/'.$this->fileName;
		
		if (! empty ( $log_file ) && File::exists ( $log_file ) ) {
			$this->empty = false;
			$file = File::get ( $log_file );

			// There has GOT to be a better way of doing this...
			preg_match_all ( $pattern, $file, $headings );
			$log_data = preg_split ( $pattern, $file );

			if ($log_data [0] < 1) {
				$trash = array_shift ( $log_data );
				unset ( $trash );
			}
			
			
			foreach ( $headings as $h ) {
				for($i = 0, $j = count ( $h ); $i < $j; $i ++) {
					foreach ( $log_levels as $ll ) {
						if ($this->level == $ll or $this->level == 'all') {
							if (strpos ( strtolower ( $h [$i] ), strtolower ( 'production.' . $ll ) )) {
								$log [] = array (
										'level' => $ll,
										'header' => $h [$i],
										'stack' => $log_data [$i] 
								);
							}
						}
					}
				}
			}
		}
		
		unset ( $headings );
		unset ( $log_data );
		
		if (strtolower ( Config::get ( 'logviewer::log_order' ) ) == "desc") {
			$log = array_reverse ( $log );
		}
		
		return $log;
	}
1008679
protected static function _parse($file) {
		$header = '';
		$content = '';

		if (!$stream = fopen($file, 'r')) {
			throw new Exception('Failed to open file.');
		}

		$isHeader = false;

		while (!feof($stream)) {
			$line = rtrim(fgets($stream));

			if ($line === '---') {
				$isHeader = !$isHeader;
				continue;
			}
			if ($isHeader) {
				$header .= $line . "\n";
			} else {
				$content .= $line . "\n";
			}
		}
		if ($header) {
			$info = Yaml::parse($header);
		} else {
			$info = [];
		}

		fclose($stream);
		return [$info, $content];
	}
796664
protected function getFileHandler()
    {
        if ($this->fileHandler === null) {
            $fileHandler = @fopen($this->logFile, 'r');

            if ($fileHandler === false) {
                throw new ParserException('Can not open log file.');
            }

            $this->fileHandler = $fileHandler;
        }

        return $this->fileHandler;
    }
123427
public function getLogPath(): string
    {
        $path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'logs';
        FileHelper::createDirectory($path);
        return $path;
    }
376883
public function parse()
    {
        $path = $this->_contents;

        if (!isset($this->_parsed_data[$path])) {
            $context = $this->getCommandContext();
            $context->data = $path;
            $this->getCommandChain()->run(LibBaseTemplateFilter::MODE_READ, $context);
            $this->_parsed_data[$path] = $context->data;
        }

        return $this->_parsed_data[$path];
    }
109372
protected function read()
    {
        $filename = $this->filename;
        if (!$this->isFileWritable() && file_exists($this->getCacheFilename())) {
            $filename = $this->getCacheFilename();
        }

        if (!file_exists($filename)) {
            return array();
        }

        $ret = Yaml::parse(file_get_contents($filename));
        if (false === $ret || array() === $ret) {
            throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $filename));
        }

        if (isset($ret['parameters']) && is_array($ret['parameters'])) {
            return $ret['parameters'];
        } else {
            return array();
        }
    }
340643
public function parse()
    {
        $templates = array();
        $finder = new Finder(); 
        
        $directories = array(
            $this->templatesDir, 
        );
        
        $globalResourcesFolder = $this->kernelDir . '/Resources/views/' . $this->themeName;
        if (is_dir($globalResourcesFolder)) {
            $directories[] = $globalResourcesFolder;
        }
        
        $templateFiles = $finder->files('*.twig')->in($directories);
        foreach ($templateFiles as $template) {
            $template = (string)$template;
            $templateName = basename($template);
            $templateContents = file_get_contents($template);
            
            $slots = $this->fetchSlots($templateContents);
            if (empty($slots)) {
                continue;
            }
            
            $templates[$templateName]['assets']['external_stylesheets'] = $this->fetchExternalStylesheets($templateContents);
            $templates[$templateName]['assets']['external_javascripts'] = $this->fetchExternalJavascripts($templateContents);
            $templates[$templateName]['assets']['external_stylesheets_cms'] = $this->fetchExternalStylesheetsCms($templateContents);
            $templates[$templateName]['assets']['external_javascripts_cms'] = $this->fetchExternalJavascriptsCms($templateContents);
            $templates[$templateName]['slots'] = $slots;
            if (strpos($template, $this->kernelDir) === false) {
                $templates[$templateName]['generate_template'] = dirname($template) == $this->templatesDir;
            }
        }
        
        return $templates;
    }
1035361
public function parse()
    {
        $matched = [];
        foreach ($this->_routers as $router) {
            if ($router->isMatched($this->getPathInfo(), count($matched))) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug(sprintf('router %s is matched', get_class($router)));
                }

                $matched[] = $router;
                if ($router->isContinue() === false) {
                    break;
                }
            }
        }

        return $matched;
    }