Parse the given file to find the namespace.

@param $filePath
@return string
497692
private function parseNamespace($filePath): string
    {
        preg_match('/namespace(.*);/', file_get_contents($filePath), $result);
        return isset($result[1]) ? $result[1] . "\\" : '';
    }
465003
protected function readFile(string $filePath): string
    {
        /**
         * read bin
         */
        $handle = fopen($filePath, 'rb');
        $stream = fread($handle, $this->maxByteCacheLen);
        fclose($handle);
        return $stream;
    }
874096
public function getCorePath(string $filePath): string
    {
        $rootPath = $this->getRootApplicationDirectoryPathByFilePath($filePath);
        $corePath = mb_substr($filePath, 0, mb_strpos($filePath, 'src'));
        $corePath = rtrim($corePath, DIRECTORY_SEPARATOR);
        $corePath = explode(DIRECTORY_SEPARATOR, $corePath);

        array_pop($corePath);
        $corePath = implode(DIRECTORY_SEPARATOR, $corePath);

        return rtrim($corePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    }
824144
public static function getClassName($filePath)
    {
        $className = preg_replace('/\.php$/i', '', $filePath);
        $className = preg_replace('/^(application|custom)(\/|\\\)/i', '', $className);
        $className = '\\'.static::toFormat($className, '\\');

        return $className;
    }
561191
protected function doParseFromString($stringPath)
    {
        #! Parse string may give:
        #- . and .. in some cases
        #- when you iterate over directory lists

        ## reset everything
        $parsed = array(
            'path'      => '',
            'filename'  => '',
            'extension' => '',
        );

        $stringPath = str_replace('\\', '/', $stringPath);
        if ( substr($stringPath, -1) == $this->getSeparator() )
            ## trick to have "/path/to/directory/" considered as directory
            #- back slash on end of string
            $stringPath .= '.';


        $m          = pathinfo($stringPath);

        if ($m['basename'] == '.' || $m['basename'] == '..') {
            $m['basename'] = '';
            $m['filename'] = '';
        }

        (!isset($m['dirname']))   ?: $parsed['path']      = $m['dirname'];
        (!isset($m['filename']))  ?: $parsed['filename']  = $m['filename'];
        (!isset($m['extension'])) ?: $parsed['extension'] = $m['extension'];

        if (isset($parsed['extension']) && $m['filename'] === '') {
            ## for directories similar to .ssh
            $parsed['extension'] = '';
            $parsed['filename']  = $m['basename'];
        }

        if ($parsed['path'] === '.')
            ## no path to uri detected, happen when "file.ext" given
            $parsed['path'] = '';

        $parsed = array_merge($parsed, parent::doParseFromString($parsed['path']));
        return $parsed;
    }
1119871
public static function parseFile ($filePath, $xmlValidationEnabled=true)
    {
        // Extract content first
        $fileContent = self::getXmlContentFromFile($filePath);

        // Validate
        if ($xmlValidationEnabled) {
            if (!self::validateXmlContent($fileContent)) {
                throw new Exception("XML validation against rua.xsd failed");
            }
        }

        // Parse
        return self::parseXmlContent($fileContent);
    }
266572
public static function getFileName($filePath) {
        $lastIndex = strripos($filePath, DIRECTORY_SEPARATOR);
        $fileName = substr($filePath, $lastIndex + 1);
        return substr($fileName, 0, strripos($fileName, "."));
    }
1155186
public function getParsedData(string $sourcePath)
    {
        if (!isset($this->parsedFiles[$sourcePath])) {
            $this->parsedFiles[$sourcePath] = $this->parseXmlFile($sourcePath);
        }

        return $this->parsedFiles[$sourcePath];
    }
1043111
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $pharArchive = new PharData($filePath, null, null, Phar::GZ);
        $pharArchive->extractTo($directory);

        return $this->createFinderFromDirectory($directory);
    }
236103
public function getLeafObject( string $filepath ) : Leaf
	{
		$leafObject = new $this->leafObjectClass( $this->search, $filepath );

		if ( $leafObject instanceof Leaf )
		{
			return $leafObject;
		}

		throw new \RuntimeException( sprintf( '%s is not a subclass of %s\\Leaf', $this->leafObjectClass, __NAMESPACE__ ) );
	}
1166392
public function loadFile($filePath)
    {
        if ($filePath instanceof \SplFileInfo) {
            $filePath = $filePath->getRealPath();
        }

        if (isset($this->sourceFileDirectory)) {
            if (is_file($this->sourceFileDirectory . $filePath)) {
                $filePath = $this->sourceFileDirectory . $filePath;
            }
        }

        if (is_file($filePath)) {
            $this->sourceFilePath = realpath($filePath);
            $this->sourceFileDirectory = pathinfo($this->sourceFilePath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR;

            return $this->loadString(file_get_contents($filePath));
        }

        return false;
    }
907332
protected static function getMimetypeFromLocalFilePath($filePath) {
		$mimetype = getMimeType($filePath);
		if( $mimetype !== 'text/plain' ) {
			return $mimetype;
		}
		return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION));
	}
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;
    }
886575
public function locate($filePath)
    {
        $file = $filePath;
        if (!is_file($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" does not exist.',
                                            $filePath));
        }

        if (!is_readable($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" is not readable.',
                                            $filePath));
        }

        $pathInfo = pathinfo($filePath);
        if (!isset($pathInfo['extension'])
            || !in_array($pathInfo['extension'], $this->supportedExtensions)
        )
        {
            throw new FileException(sprintf('Invalid file extension! Supported file extensions: %s',
                implode(', ', $this->supportedExtensions)));
        }

        return realpath($file);
    }
1100047
public static function firstLine($filepath)
    {
        if (file_exists($filepath)) {
            $cacheRes = fopen($filepath, 'rb');
            $firstLine = fgets($cacheRes);
            fclose($cacheRes);

            return $firstLine;
        }

        return null;
    }
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;
    }
445875
public function getExtensionByFileName($filepath)
    {
        $path = pathinfo($filepath);

        // check if the file has the extenison and we need
        // to lower down the extension (caused unknown extension for uppercased extension)
        if (isset($path['extension'])) {
            return strtolower($path['extension']);
        } else if (is_string($this->getMime())) {
            return str_replace("image/", "", $this->getMime());
        } else if ($this->format != "") {
            return $this->format;
        } else {
            // fallback to enable save image on empty extension. ImageMagick has no problem with this.
            return "jpg";
        }
    }