Extract a site's config from its XML file

@param  string $filepath Path to the XML file
@return mixed
189893
protected function getConfigFromXmlFile($filepath)
	{
		$dom = new DOMDocument;
		$dom->loadXML(file_get_contents($filepath), LIBXML_NOCDATA);

		return $this->getElementConfig($dom->documentElement);
	}
812561
private function getDefaultConfiguration(\DOMXPath $xpath)
    {
        $charFilters = $this->parseFilters($xpath, self::CHAR_FILTER_TYPE_ROOT_NODE, self::CHAR_FILTER_TYPE_NODE);
        $filters     = $this->parseFilters($xpath, self::FILTER_TYPE_ROOT_NODE, self::FILTER_TYPE_NODE);
        $analyzers   = $this->parseAnalyzers($xpath, array_keys($charFilters), array_keys($filters));

        $defaultConfiguration = [
            self::CHAR_FILTER_TYPE_NODE => $charFilters,
            self::FILTER_TYPE_NODE      => $filters,
            self::ANALYZER_TYPE_NODE    => $analyzers,
        ];

        return $defaultConfiguration;
    }
1154679
protected function _getManifest( $filepath )
	{
		if( !file_exists( $filepath ) ) {
			throw new MW_Jsb2_Exception( sprintf( 'File does not exists: "%1$s"', $filepath ) );
		}

		if( ( $content = file_get_contents( $filepath ) ) === false ) {
			throw new MW_Jsb2_Exception( sprintf( 'Unable to read content from "%1$s"', $filepath ) );
		}

		if( ( $content = json_decode( $content ) ) === null ) {
			throw new MW_Jsb2_Exception( 'File content is not JSON encoded' );
		}

		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));
    }
1043111
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $pharArchive = new PharData($filePath, null, null, Phar::GZ);
        $pharArchive->extractTo($directory);

        return $this->createFinderFromDirectory($directory);
    }
116118
private function getClassNameFromFile($filepath)
    {
        $contents = file_get_contents($filepath);
        $namespace = $class = '';
        $getting_namespace = $getting_class = false;
        foreach (token_get_all($contents) as $token) {
            if (is_array($token) && $token[0] == T_NAMESPACE) {
                $getting_namespace = true;
            }

            if (is_array($token) && in_array($token[0], [T_CLASS, T_TRAIT, T_INTERFACE])) {
                $getting_class = true;
            }

            if ($getting_namespace === true) {
                if (is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) {
                    $namespace .= $token[1];
                } elseif ($token === ';') {
                    $getting_namespace = false;
                }
            }

            if ($getting_class === true) {
                if (is_array($token) && $token[0] == T_STRING) {
                    $class = $token[1];
                    break;
                }
            }
        }

        return $namespace ? $namespace.'\\'.$class : $class;
    }
533342
public static function getRelative($filePath, $rootPath = null, $forceDS = DIRECTORY_SEPARATOR, $toRealpath = true)
    {
        // Cleanup file path
        if ($toRealpath && !self::isReal($filePath)) {
            $filePath = self::real($filePath);
        }
        $filePath = self::clean($filePath, $forceDS);


        // Cleanup root path
        $rootPath = $rootPath ?: Sys::getDocRoot();
        if ($toRealpath && !self::isReal($rootPath)) {
            $rootPath = self::real($rootPath);
        }
        $rootPath = self::clean($rootPath, $forceDS);


        // Remove root part
        $relPath = preg_replace('#^' . preg_quote($rootPath, null) . '#i', '', $filePath);
        $relPath = ltrim($relPath, $forceDS);

        return $relPath;
    }
715960
protected function getCachedConfiguration($filePaths)
    {
        // Return cached version if available
        if (!$this->cache->isFresh()) {
            return;
        }

        // If the files the configuration was cached from
        // match the ones we have, return the cache
        $cache = $this->cache->getContents();
        if (Arr::get($cache, 'meta') === $filePaths) {
            return $cache;
        }
    }
726357
protected function loadConfigurationFile(string $configurationPath): array
    {
        $configurations = [];

        if ($configurationPath && is_dir($configurationPath)) {
            if (is_dir($configurationPath)) {
                $configurationFiles = new FilesystemIterator($configurationPath, FilesystemIterator::SKIP_DOTS);

                /** @var SplFileInfo $configurationFiles */
                foreach ($configurationFiles as $file) {
                    $configurations += $this->getConfigurationFile($file);
                }
            } else {
                if (is_file($configurationPath)) {
                    $configurations += $this->getConfigurationFile($configurationPath);
                }
            }
        }

        return $configurations;
    }
907332
protected static function getMimetypeFromLocalFilePath($filePath) {
		$mimetype = getMimeType($filePath);
		if( $mimetype !== 'text/plain' ) {
			return $mimetype;
		}
		return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION));
	}
1260897
static function fetchListByFilePath( $filePath )
    {
        return eZPersistentObject::fetchObjectList(
            eZImageFile::definition(),
            array( 'contentobject_attribute_id', 'filepath' ),
            array( 'filepath' => $filePath ),
            null,
            null,
            false
        );
    }
1170208
public static function GetXmlReaderInstanceForSourceFile($filePath, $fileName = null) {
        if (!isset($fileName)) {
            $fileName = substr($filePath, strrpos($filePath, "/") + 1);
        }
        $xmlFilesLoaded = apc_fetch(\Puzzlout\Framework\Enums\CacheKeys::XmlFilesLoaded);
        if (array_key_exists($fileName, $xmlFilesLoaded)) {
            $this->xmlReader = $xmlFilesLoaded[$fileName];
        } else {
            $this->xmlReader = isset($fileName) ?
                    new \Puzzlout\Framework\Core\XmlReader(null, $configFileName) :
                    new \Puzzlout\Framework\Core\XmlReader($filePath);
            $xmlFilesLoaded[$configFileName] = $this->xmlReader;
            apc_add(\Puzzlout\Framework\Enums\CacheKeys::XmlFilesLoaded, $xmlFilesLoaded);
        }
    }
697582
protected function getFileFunctions($filePath)
    {
        $source = file_get_contents($filePath);
        $tokens = token_get_all($source);

        $functions = [];
        $nextStringIsFunc = false;
        foreach($tokens as $token) {
            switch($token[0]) {
                case T_FUNCTION:
                    $nextStringIsFunc = true;
                    break;

                case T_STRING:
                    if ($nextStringIsFunc) {
                        $nextStringIsFunc = false;
                        $functions[] = $token[1];
                    }
                    break;
            }
        }

        return $functions;
    }
1153857
protected function parseXmlFile(string $sourcePath)
    {
        $rootXmlNode = $this->getRootNode($sourcePath);

        return $this->doParsingFromRoot($rootXmlNode);
    }
268399
protected function convertToUseRealPath($filePath)
    {
        $realFilePath = $filePath;

        if ($this->isZipStream($filePath)) {
            if (preg_match('/zip:\/\/(.*)#(.*)/', $filePath, $matches)) {
                $documentPath = $matches[1];
                $documentInsideZipPath = $matches[2];
                $realFilePath = 'zip://' . realpath($documentPath) . '#' . $documentInsideZipPath;
            }
        } else {
            $realFilePath = realpath($filePath);
        }

        return $realFilePath;
    }
425772
public function scan($filepath)
    {
        $proc = new Process(sprintf('%s %s --Output=XML --Full', $this->path, $filepath));
        $proc->run();

        if (!$proc->isSuccessful()) {
            throw new \RuntimeException($proc->getErrorOutput());
        }

        $result = $proc->getOutput();

        //parse structure to turn into raw php array
        $xml = simplexml_load_string($result);
        $data = array();
        $data['version'] = (string) $xml['version'];

        foreach ($xml->File->track as $track) {
            $trackType = strtolower($track['type']);
            $trackId = isset($track['streamid']) ? $track['streamid'] : 1;
            $trackId = (string)$trackId;

            $trackData = [];
            foreach ($track as $rawKey => $rawVal) {
                $key = strtolower($rawKey);
                $val = (string)$rawVal;

                # This sometimes doesn't match streamid, so let's ignore it
                if ($key == 'stream_identifier') { continue; }

                if (!array_key_exists($key, $trackData)) {
                    $trackData[$key] = array($val);
                } elseif (!in_array($val, $trackData[$key])) {
                    $trackData[$key][] = $val;
                }
            }

            if ($trackType == 'general') {
                $data['file']['general'] = $trackData;
            } else {
                $data['file'][$trackType][$trackId] = $trackData;
            }
        }

        return $data;
    }
1355794
public function parse($filepath)
    {
        $metadata = array();

        $reflectedClass = $this->getReflection($filepath);
        $metadata['class'] = $reflectedClass->getName();

        $propertiesMetadata = $this->processPropertiesParsing($reflectedClass);
        $metadata = array_merge($metadata, $propertiesMetadata);

        return $metadata;
    }