Extract files from a filepath

@param string $filePath File path

@return Finder
320815
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $rarArchive = RarArchive::open($filePath);
        $rarEntries = $rarArchive->getEntries();

        /**
         * @var RarEntry $rarEntiry
         */
        foreach ($rarEntries as $rarEntry) {

            $rarEntry->extract($directory);
        }

        return $this->createFinderFromDirectory($directory);
    }
760285
protected function getLockPath(FilePath $filePath)
    {
        $name = $filePath->getName();
        $relativeLockPath = $filePath->getParentPath()->appendFile('.' . $name . '.lock');

        return $relativeLockPath;
    }
1347264
protected function getReflection($filepath)
    {
        // Regexp instead of tokenizer because of the bad perf @link > https://gist.github.com/1886076
        if (!preg_match('#^namespace\s+(.+?);.*class\s+(\w+).+;$#sm', file_get_contents($filepath), $captured)) {
            throw new \RuntimeException('Unable to find namespace or class declaration');
        }

        $fqcn = $captured[1].'\\'.$captured[2];

        try {
            $reflectedClass = new \ReflectionClass($fqcn);
        } catch (\ReflectionException $exception) {
            $this->registerAutoload($fqcn, $filepath);
            $reflectedClass = new \ReflectionClass($fqcn);
        }

        return $reflectedClass;
    }
52507
public function findAllFiles(DirectoryPath $path = null)
    {
        if (null === $path) {
            $path = new DirectoryPath();
        }

        $finder = new Finder();
        $searchPath = $path->prepend($this->gitService->getRepositoryPath());

        $finder->in($searchPath->toAbsoluteString(DIRECTORY_SEPARATOR));

        $filePaths = [];

        foreach ($finder->files() as $file) {
            /** @var SplFileInfo $file */
            $filePaths[] = FilePath::parse('/' . $file->getRelativePathname())->prepend($path);
        }

        return $filePaths;
    }
1115557
public static function createFromFilePath ($filePath)
    {
        if (!is_file($filePath))
        {
            throw new \InvalidArgumentException("File does not exist");
        }
        else if (!is_readable($filePath))
        {
            throw new \InvalidArgumentException("File to download is not readable.");
        }

        return new FileDownload(fopen($filePath, "rb"));
    }
22917
protected function absoluteToFilesystemPath($filePath)
    {

        if (!$this->isWithinFilesystem($filePath)) {
            return $filePath;
        }

        $fsPath = (string)$this->filesystem->url()->path;

        return str_replace($fsPath,'', $filePath);

    }
415811
public function parseFile($filePath, array $vars = [])
    {
        if (is_file($filePath)) {
            return $this->parseString(file_get_contents($filePath), $vars);
        }

        // Try to find from filePaths
        if (count($this->filePaths)) {
            foreach ($this->filePaths as $fileDirectory) {
                if (is_file($fileDirectory . $filePath)) {
                    return $this->parseString(file_get_contents($fileDirectory . $filePath), $vars);
                    break;
                }
            }
        }

        return null;
    }
816898
public static function classes_for_file($filePath)
    {
        $absFilePath = Director::getAbsFile($filePath);
        $classManifest = ClassLoader::inst()->getManifest();
        $classes = $classManifest->getClasses();
        $classNames = $classManifest->getClassNames();

        $matchedClasses = [];
        foreach ($classes as $lowerClass => $compareFilePath) {
            if (strcasecmp($absFilePath, $compareFilePath) === 0) {
                $matchedClasses[$lowerClass] = $classNames[$lowerClass];
            }
        }

        return $matchedClasses;
    }
172754
public function setFilePath($filePath)
    {
        $this->isURI = false;
        $this->filePath = trim($filePath);

        $this->content = null;
        return $this;
    }
1002137
private function getTranslationsInFile($filePath)
    {
        
	 	// File extension ?
        $extOk = in_array(\Jig\Utils\FsUtils::getFileExtension($filePath), $this->getFileTypes());

        if ($extOk){
            foreach ($this->getBannedFileType() as $bannedExt){
                $extOk &= substr_compare($filePath, $bannedExt, strlen($filePath)-strlen($bannedExt), strlen($bannedExt)) !== 0;
            }
        }

        if ($extOk) {
            
		 	// We read the file.
		 	$lines = file($filePath);
		 	foreach ($lines as $line) {
                $strings = $this->getTranslationPhrases( $line );
                //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string);
                
                //lookup for __('to translate') or __ 'to translate'
            //    preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string);
            
                foreach($strings as $s) {
                    $tu = new tao_helpers_translation_TranslationUnit();
                    $tu->setSource(tao_helpers_translation_POUtils::sanitize($s));
                    $tus = $this->getTranslationUnits();
                    $found = false;
                    
                    // We must add the string as a new TranslationUnit only
                    // if a similiar source does not exist.
                    foreach ($tus as $t) {
                        if ($tu->getSource() == $t->getSource()) {
                            $found = true;
                            break;
                        }
                    }
                    
                    if (!$found) {
                        $tus[] = $tu;
                        $this->setTranslationUnits($tus);
                    }
                }
		 	}
		}
        
    }
603509
protected function parsePseudoIniFile($filepath)
    {
        $properties = array();
        if (($lines = @file($filepath)) === false) {
            throw new Exception("Unable to parse contents of $filepath");
        }
        foreach ($lines as $line) {
            $line = trim($line);
            if ($line == "" || $line{0} == '#' || $line{0} == ';') {
                continue;
            }
            $pos = strpos($line, '=');
            $property = trim(substr($line, 0, $pos));
            $value = trim(substr($line, $pos + 1));
            if ($value === "true") {
                $value = true;
            } elseif ($value === "false") {
                $value = false;
            }
            $properties[$property] = $value;
        }

        return $properties;
    }
8144
public function loadFile($filePath) {
        require_once (substr($filePath, 0, 1) != '/' && substr($filePath, 1, 1) != ':')
            ? $this->basePath . DIRECTORY_SEPARATOR . $filePath : $filePath;
    }
95966
public function extract($path, $files = array())
    {
        if (empty($files)) {
            return $this->zip->extractTo($path);
        }

        return $this->zip->extractTo($path, $files);
    }
465003
protected function readFile(string $filePath): string
    {
        /**
         * read bin
         */
        $handle = fopen($filePath, 'rb');
        $stream = fread($handle, $this->maxByteCacheLen);
        fclose($handle);
        return $stream;
    }
589346
public function extract( $targetPath = NULL )
	{
		$counter	= 0;
		if( $targetPath )
		{
			$cwd	= getCwd();
			Folder_Editor::createFolder( $targetPath );
			chdir( $targetPath );
		}
		foreach( $this->folders as $folder )
			Folder_Editor::createFolder( $folder['name'] );
		foreach( $this->files as $file )
		{
			if( $folder = dirname( $file['name'] ) )
				Folder_Editor::createFolder( $folder );
			$counter	+= (int)(bool) File_Writer::save( $file['name'], $file['file'] );
		}
		if( $targetPath )
			chDir( $cwd );
		return $counter;
	}
775291
public function setFilePath( $filePath )
	{
		$this->filePath      = $filePath;
		$this->shortFilePath = str_replace( base_path() , '' , $filePath );

		return $this;
	}
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;
    }