parse metadata from given template content.

@param string $templateFileContent

@return array<alias, array>
555414
protected function getMetadata($templateFileContent)
    {
        $regex                = '/\@MajoraGenerator\((.+)\)/';
        $templateFileMetadata = array('force_generation' => false);
        if (!preg_match_all($regex, $templateFileContent, $matches, PREG_SET_ORDER)) {
            return $templateFileMetadata;
        }
        foreach ($matches as $match) {
            if (null === $metadata = json_decode($match[1], true)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid annotation json data, error %s : %s',
                    json_last_error(),
                    json_last_error_msg()
                ));
            }

            $templateFileMetadata =  array_replace_recursive(
                $templateFileMetadata,
                $metadata
            );
        }

        return $templateFileMetadata;
    }
777080
public function extractMigrationInfoFromSource($fileContents)
    {
        $stream = new PhpSourceStream($fileContents);

        $result = [];

        while ($stream->forward()) {
            $tokenCode = $stream->getCurrentCode();

            if ($tokenCode == T_NAMESPACE) {
                $namespace = $this->extractNamespace($stream);
                if ($namespace === null) {
                    return null;
                }

                $result['namespace'] = $namespace;
            }

            if ($tokenCode == T_CLASS) {
                $className = $this->extractClassName($stream);
                if ($className === null) {
                    return null;
                }

                $result['class'] = $className;
            }
        }

        if (!$result) {
            return null;
        }

        return $result;
    }
589832
protected static String getSubstitutedTemplateContent(String templateContent, NamesValuesList<String, String> namesValues) {
        String templateContentSubst = templateContent;
        // substitute the name/values

        for (NameValue<String, String> nameValue : namesValues) {
            templateContentSubst = templateContentSubst.replace(nameValue.name, nameValue.value);
        }
        return templateContentSubst;
    }
1105483
protected function extractTemplate($fileContent, MessageCatalogue $catalogue)
    {
        $translateParameters = [];

        $translateFound = preg_match_all(
            '/\\{\\{\\s*translate\\s(.*)\\s*\\}\\}/',
            $fileContent,
            $translateParameters,
            PREG_SET_ORDER
        );

        $messages = [];
        if ($translateFound) {
            foreach ($translateParameters as $translateParameter) {
                $message = $this->extractParameters($translateParameter[1], $catalogue);
                if ($message !== null) {
                    $messages[] = $message;
                }
            }
        }

        return $messages;
    }
68592
public function parse($template)
	{
		$dom = TemplateLoader::load($template);

		$ir = new DOMDocument;
		$ir->loadXML('<template/>');

		$this->createXPath($dom);
		$this->parseChildren($ir->documentElement, $dom->documentElement);
		$this->normalizer->normalize($ir);

		return $ir;
	}
280532
public function getTemplate($templatePath)
    {
        $absoluteTemplateFilePath = $this->getTemplateFilePath($templatePath);
        if (!$absoluteTemplateFilePath) {
            return;
        }
        extract($this->getArrayCopy());
        ob_start();
        include $absoluteTemplateFilePath;
        $content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
452848
protected function extractTemplateConfiguration(DOMElement $template, DOMXPath $xpath)
    {
        $configElements = $xpath->query('./docbook:ezconfig', $template);
        if (0 === $configElements->length) {
            return [];
        }

        return $this->extractHash($configElements->item(0));
    }
495544
public function parseTemplateContent($content, $template = "")
    {
        return $this->getParser()->compileString(
            $content,
            $template,
            Director::isDev() && SSViewer::config()->uninherited('source_file_comments')
        );
    }
610603
private function _readTemplate($templateFile) {
		$filename = PHPCHECKSTYLE_HOME_DIR . "/html/template/" . $templateFile . ".tmpl";
		$handle = fopen($filename, "r");
		$contents = fread($handle, filesize($filename));
		fclose($handle);

		return $contents;
	}
1280336
protected function fetch($templateFile='',$content='',$prefix='') {
        return $this->view->fetch($templateFile,$content,$prefix);
    }
1034576
public static function parseFile($fileName, $fileContent = null)
    {
        $fileName = PathResolver::realpath($fileName);
        if (isset(self::$parsedFiles[$fileName]) && !isset($fileContent)) {
            return self::$parsedFiles[$fileName];
        }

        if (isset(self::$maximumCachedFiles) && (count(self::$parsedFiles) === self::$maximumCachedFiles)) {
            array_shift(self::$parsedFiles);
        }

        if (!isset($fileContent)) {
            $fileContent = file_get_contents($fileName);
        }
        $treeNode = self::$parser->parse($fileContent);
        $treeNode = self::$traverser->traverse($treeNode);

        self::$parsedFiles[$fileName] = $treeNode;

        return $treeNode;
    }
199536
protected function parseTemplate($template)
	{
		$this->references = [
			'anywhere' => [],
			'asUrl'    => [],
			'inText'   => []
		];

		preg_match_all($this->referencesRegexp, $template, $matches);
		foreach ($matches[0] as $match)
		{
			$key = trim($match, '\\${}');
			$this->references['anywhere'][$key] = $key;
		}

		$dom   = TemplateLoader::load($template);
		$xpath = new DOMXPath($dom);
		foreach ($xpath->query('//text()') as $node)
		{
			preg_match_all($this->referencesRegexp, $node->textContent, $matches);
			foreach ($matches[0] as $match)
			{
				$key = trim($match, '\\${}');
				$this->references['inText'][$key] = $key;
			}
		}

		foreach (NodeLocator::getURLNodes($dom) as $node)
		{
			// We only bother with literal attributes that start with a capture
			if ($node instanceof DOMAttr
			 && preg_match('(^(?:[$\\\\]\\d+|\\$\\{\\d+\\}))', trim($node->value), $m))
			{
				$key = trim($m[0], '\\${}');
				$this->references['asUrl'][$key] = $key;
			}
		}

		$this->removeUnknownReferences();
	}
804179
private function prepareFileContent($fileContent)
    {
        // Remove 1 line comments
        $fileContent = preg_replace("#(.*)//(.*)#", " ", $fileContent);

        // Remove multi-line comments
        $fileContent = preg_replace("#/\*(.*)\*?/#", "", $fileContent);

        // Remove all new line characters
        $fileContent = preg_replace("/\n*/", "", $fileContent);

        // Add 2 new line characters after <?php
        $fileContent = str_replace("<?php", "<?php\n\n", $fileContent);

        // Add 1 new line characters after ;
        $fileContent = str_replace(";", ";\n", $fileContent);

        // Add 1 new line characters after {
        $fileContent = str_replace("{ ", "{\n", $fileContent);

        // Add 1 new line character after });
        $fileContent = str_replace("});", "});\n", $fileContent);

        return $fileContent;
    }
1085740
private function getResourceFilesInSource(string $sourceFileContent): array
  {
    $resource_files = [];
    foreach ($this->getResourcesInfo() as $file_info)
    {
      if (strpos($sourceFileContent, $file_info['path_name_in_sources_with_hash'])!==false)
      {
        $resource_files[] = $file_info;
      }
    }

    return $resource_files;
  }
804155
protected function _parseTags(&$text, TemplateInterface $template)
    {
        $tags = '';

        $matches = array();
        if(preg_match_all('#<meta\ content="([^"]+)"(.*)\/>#siU', $text, $matches))
        {
            foreach($matches[1] as $key => $match)
            {
                //Set required attributes
                $attribs = array(
                    'content' => $match
                );

                $attribs = array_merge($this->parseAttributes( $matches[2][$key]), $attribs);
                $tags .= $this->_renderTag($attribs, null, $template);
            }

            $text = str_replace($matches[0], '', $text);
        }

        return $tags;
    }
1274175
public function getTemplateBlocks($templateFileName)
    {
        $templateBlocksWithContent = [];

        $config = \OxidEsales\Eshop\Core\Registry::getConfig();

        $tplDir = trim($config->getConfigParam('_sTemplateDir'), '/\\');
        $templateFileName = str_replace(['\\', '//'], '/', $templateFileName);
        if (preg_match('@/' . preg_quote($tplDir, '@') . '/(.*)$@', $templateFileName, $m)) {
            $templateFileName = $m[1];
        }

        if ($this->isShopTemplateBlockOverriddenByActiveModule()) {
            $shopId = $config->getShopId();

            $ids = $this->_getActiveModuleInfo();

            $activeModulesId = array_keys($ids);
            $activeThemeIds = oxNew(\OxidEsales\Eshop\Core\Theme::class)->getActiveThemesList();

            $templateBlockRepository = oxNew(ModuleTemplateBlockRepository::class);
            $activeBlockTemplates = $templateBlockRepository->getBlocks($templateFileName, $activeModulesId, $shopId, $activeThemeIds);

            if ($activeBlockTemplates) {
                $activeBlockTemplatesByTheme = $this->filterTemplateBlocks($activeBlockTemplates);

                $templateBlocksWithContent = $this->fillTemplateBlockWithContent($activeBlockTemplatesByTheme);
            }
        }

        return $templateBlocksWithContent;
    }
704705
public function listPaths(array $composerContent)
    {
        $paths = [];

        if (isset($composerContent['autoload']['psr-0'])) {
            $paths = array_merge($paths, $this->getPsrPaths($composerContent['autoload']['psr-0']));
        }

        if (isset($composerContent['autoload']['classmap'])) {
            $paths = array_merge($paths, array_values($composerContent['autoload']['classmap']));
        }

        if (isset($composerContent['autoload']['files'])) {
            $paths = array_merge($paths, array_values($composerContent['autoload']['files']));
        }

        if (isset($composerContent['autoload']['psr-4'])) {
            $paths = array_merge($paths, $this->getPsrPaths($composerContent['autoload']['psr-4']));
        }

        return array_values(array_unique($paths));
    }