Grab directory and retrieve file.

@param string $path       Directory path.
@param string $extension 'css' or 'js'.
@param string $prefix    Handle prefix. Default empty.

@return array
189460
public static function parse_dir( $path, $extension, $prefix = '' ) {
		$extension = ltrim( $extension, '.' );
		$regexp = '#/([^._][^/]*)\.' . $extension . '$#u';
		if ( ! is_dir( $path ) ) {
			return [];
		}
		$files = [];
		$finder = new Finder();
		foreach ( $finder->in( $path )->name( "*.{$extension}" )->files() as $file ) {
			$file_path = $file->getPathname();
			if ( ! preg_match( $regexp, $file_path, $match ) ) {
				continue;
			}
			$handle = $prefix . $match[1];
			$deps = self::grab_deps( $file_path );
			$url = str_replace( ABSPATH, home_url( '/' ), $file_path );
			$files[ $handle ] = [
				'path' => $file_path,
				'deps' => $deps,
				'url'  => $url,
			];
		}
		return $files;
	}
2085
public static function getResourcesFolder(string $extensionKey, string $prefix = 'EXT:'): string {
    return self::resourcesFolder($extensionKey, $prefix);
  }
1309627
public static function fileInfo(String $dir, String $extension = NULL) : Array
    {
        $dir = self::rpath($dir);

        if( is_dir($dir) )
        {
            $files = FileList::files($dir, $extension);

            $dir = Base::suffix($dir);

            $filesInfo = [];

            foreach( $files as $file )
            {
                $filesInfo[$file]['basename']   = self::pathInfo($dir.$file, 'basename');
                $filesInfo[$file]['size']       = filesize($dir.$file);
                $filesInfo[$file]['date']       = filemtime($dir.$file);
                $filesInfo[$file]['readable']   = is_readable($dir.$file);
                $filesInfo[$file]['writable']   = is_writable($dir.$file);
                $filesInfo[$file]['executable'] = is_executable($dir.$file);
                $filesInfo[$file]['permission'] = fileperms($dir.$file);
            }

            return $filesInfo;
        }
        elseif( is_file($dir) )
        {
            return (array) self::get($dir);
        }
        else
        {
            throw new Exception\FolderNotFoundException(NULL, $dir);
        }
    }
5308
public function load($path, $prefix = '')
    {
        $config = $this->readConfig($path);

        foreach ($config as $section => $values) {
            if (in_array($section, self::$_extensionTypes)) {
                // extension section, merge in the defaults.
                $defaults = $this->get($section);
                if ($defaults) {
                    $values = array_merge($defaults, $values);
                }
                $this->addExtension($section, $values);
            } elseif (strtolower($section) === self::GENERAL) {
                if (!empty($values['timestampPath'])) {
                    $path = $this->_replacePathConstants($values['timestampPath']);
                    $values['timestampPath'] = rtrim($path, '/') . '/';
                }
                $this->set(self::GENERAL, $values);
            } elseif (strpos($section, self::FILTER_PREFIX) === 0) {
                // filter section.
                $name = str_replace(self::FILTER_PREFIX, '', $section);
                $this->filterConfig($name, $values);
            } else {
                $lastDot = strrpos($section, '.') + 1;
                $extension = substr($section, $lastDot);
                $key = $section;

                // must be a build target.
                $this->addTarget($prefix . $key, $values);
            }
        }

        $this->resolveExtends();

        return $this;
    }
20609
protected function getBuilder($prefix, $path = false)
    {
        return (
            $path
            ? $this->getPathBuilder($prefix)
            : $this->getPropertyBuilder($prefix)
        );
    }
747650
private function fillFilePathParts(string $fileName, string $extension, string $directory): array
    {
        $fileName = $fileName ? $fileName : $this->generateFilename($this->text);

        $fullFileName = $extension
            ? "$fileName.$extension"
            : sprintf("%s.%s", $fileName, $this->format->getFileExtension());

        $directory = $directory ? $directory : $this->getTtsApiFactory()->getTargetDirectory();

        return array($fileName, $fullFileName, $directory);
    }
888988
public static function getFileExtention($path)
    {

        $ext = pathinfo($path, PATHINFO_EXTENSION);

        if($ext === ''){
            $splitedPath = explode('.', $path);
            $ext = end($splitedPath);
        }

        return $ext;
    }
819925
public function getByPath($path)
    {
        $extension = pathinfo($path, PATHINFO_EXTENSION);
        if ('' === $extension) {
            $extension = null;
        }

        return $this->get($extension);
    }
772920
public function find_by_prefix($prefix) {
        $this->ensure_path_exists();
        $prefix = preg_replace('#(\*|\?|\[)#', '[$1]', $prefix);
        $files = glob($this->glob_keys_pattern($prefix), GLOB_MARK | GLOB_NOSORT);
        $return = array();
        if ($files === false) {
            return $return;
        }
        foreach ($files as $file) {
            // Trim off ".cache" from the end.
            $return[] = substr(basename($file), 0, -6);
        }
        return $return;
    }
489926
private function getFiles($path)
    {
        $files = array();

        foreach (new \DirectoryIterator($path) as $file) {
            if ($file->isDot()
                || (null != $this->scriptName && sprintf('%s.php', $this->scriptName) != $file->getFilename())
            ) {
                continue;
            }

            $files[$file->getFilename()] = sprintf('%s/%s', $file->getPath(), $file->getFilename());
        }
        sort($files);

        return $files;
    }
378908
protected static function getFilesFromPath($path)
    {
        $files = [];
        $path = rtrim($path, '/') . DIRECTORY_SEPARATOR;

        if (false !== $items = scandir($path)) {
            foreach ($items as $item) {
                $file = $path . $item;
                if (is_file($file)) {
                    $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                    if (in_array($extension, [Packager::FILE_EXTENSION, Package::FILE_EXTENSION])) {
                        $files[] = $file;
                    }
                }
            }
        }

        return $files;
    }
73431
protected function getPhpFiles($path)
    {
        if (is_dir($path)) {
            return new RegexIterator(
                new RecursiveIteratorIterator(
                    new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
                    RecursiveIteratorIterator::SELF_FIRST,
                    RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
                ),
                '/^.+\.php$/i',
                RecursiveRegexIterator::GET_MATCH
            );
        }
        else {
            return [];
        }
    }
960450
public function getDirectory($name, $ext)
	{
		if ('' === $name = '/' . trim($name, '/.') . '/')
			return true;

		$type = $this->getTypeForExt($ext);

		foreach ($this->paths as $path)
		{
			$prefixes = isset($path['prefixes']) ? $path['prefixes'] : array();
			$prefix = isset($prefixes[$type]) ? $prefixes[$type] . '/' : '';
			
			foreach ($path['directories'] as $directory)
			{
				if (file_exists($directory) && is_dir($directory))
					return $directory;
			}
		}
		
		throw new Exception\DirectoryNotFound($name);
	}
234675
private static function searchPath($prefix, $path, $conditions)
	{
		$result = [];
		
		$dir = new DirectoryIterator($path);
		foreach ( $dir as $entry ) {
			if ( $entry->isDot() ) {
				continue;
			}
			
			$de = $entry->getFilename();
			
			if ( $entry->isDir() && preg_match('/^[A-Za-z_]+$/', $de) ) {
				// it's a subdirectory, search it
				$result = array_merge($result, self::searchPath("$prefix\\$de", $path . DIRECTORY_SEPARATOR . $de, $conditions));
			}
			else if ( preg_match('/\.php$/', $de) ) {
				// FIXME I'm using a regex test here because that in theory is quicker than having
				// PHP parse the file. Also, this is deliberately designed to exclude abstract classes,
				// which will cause class_exists() to return (bool)true.
				
				$foundNamespace = $foundClass = false;
				$className = preg_replace('/\.php$/', '', $de);
				
				if ( $fp = @fopen($filePath = "$path/$de", 'r') ) {
					
					while ( !feof($fp) && ($line = fgets($fp)) ) {
						// FIXME PHP leaves pretty little room for error in the namespace declaration
						// line. This is still a little needlessly picky - if someone has a space between
						// the namespace name and the semicolon this test will fail, as well as dumber
						// stuff like the word "namespace" being mixed case/uppercase.
						if ( trim($line) === "namespace $prefix;" ) {
							$foundNamespace = true;
						}
						// This fairly complicated regexp covers "implements" with multiple inheritance,
						// "extends" and a fair amount of syntactical deviation.
						else if ( preg_match('/^\s*class ([A-Za-z0-9_]+)(?:\s+(?:extends|implements) [A-Za-z0-9_\\\\]+(?:\s*,\s*[A-Za-z0-9_]+)*)*\s*[\{,]?$/', trim($line), $match)
								&& ($match[1] === "\\$prefix\\$className" || $match[1] === $className) ) {
							$foundClass = true;
						}
						
						// if we have found the namespace declaration and the class declaration,
						// we no longer need any more information from this file, so break and
						// close the handle.
						if ( $foundNamespace && $foundClass ) {
							break;
						}
					}
					
					fclose($fp);
				}
				
				// if we found the namespace declaration and the class declaration, append
				// the discovered class to the result list.
				if ( $foundNamespace && $foundClass )
				{
					// fully qualified class name
					$fqcn = "$prefix\\$className";
					
					// conditions are an OR between each, AND within an individual condition
					$condCount = 0;
					
					// ReflectionClass instance - created only if necessary
					$rfl = null;
					foreach ( $conditions as $cond ) {
						$condResult = true;
						foreach ( $cond as $test => $value ) {
							switch($test) {
							case 'implements':
								if ( empty($rfl) ) {
									$rfl = new \ReflectionClass($fqcn);
								}
								if ( !$rfl->implementsInterface($value) ) {
									$condResult = false;
									break 2; // lazy evaluation
								}
								break;
							case 'extends':
								if ( empty($rfl) ) {
									$rfl = new \ReflectionClass($fqcn);
								}
								if ( $rfl->getParentClass()->getName() !== $value ) {
									$condResult = false;
									break 2; // lazy evaluation
								}
								break;
							case 'abstract':
								if ( empty($rfl) ) {
									$rfl = new \ReflectionClass($fqcn);
								}
								if ( $rfl->isAbstract() !== $value ) {
									$condResult = false;
									break 2; // lazy evaluation
								}
								break;
							}
						}
						if ( $condResult ) {
							$condCount++;
						}
					}
					
					if ( $condCount || count($conditions) === 0 ) {
						$result[] = $fqcn;
					}
				}
			}
		}
		
		return $result;
	}
480434
public function readFolder( $path, $extensions = array() )
	{
		$files			= array();
		$numberCodes	= 0;
		$numberDocs		= 0;
		$numberFiles	= 0;
		$numberLength	= 0;
		$numberLines	= 0;
		$numberStrips	= 0;

		$path	= preg_replace( "@^(.+)/?$@", "\\1/", $path );

		$st		= new Alg_Time_Clock();
		$lister	= new FS_Folder_RecursiveLister( $path );
		$lister->setExtensions( $extensions );
		$list	= $lister->getList();
		foreach( $list as $entry )
		{
			$fileName	= str_replace( "\\", "/", $entry->getFilename() );
			$pathName	= str_replace( "\\", "/", $entry->getPathname() );
			
			if( substr( $fileName, 0, 1 ) == "_" )
				continue;
			if( preg_match( "@/_@", $pathName ) )
				continue;

			$countData	= FS_File_CodeLineCounter::countLines( $pathName );
			
			unset( $countData['linesCodes'] );
			unset( $countData['linesDocs'] );
			unset( $countData['linesStrips'] );

			$numberLength		+= $countData['length'];
			$numberLines		+= $countData['linesTotal'];
			
			$numberFiles		++;
			$numberStrips		+= $countData['numberStrips'];
			$numberCodes		+= $countData['numberCodes'];
			$numberDocs			+= $countData['numberDocs'];
			$files[$pathName]	= $countData;
		}
		$linesPerFile	= $numberLines / $numberFiles;
		$this->data	= array(
			'number'	=> array(
				'files'		=> $numberFiles,
				'lines'		=> $numberLines,
				'codes'		=> $numberCodes,
				'docs'		=> $numberDocs,
				'strips'	=> $numberStrips,
				'length'	=> $numberLength,
			),
			'ratio'			=> array(
				'linesPerFile'		=> round( $linesPerFile, 0 ),
				'codesPerFile'		=> round( $numberCodes / $numberFiles, 0 ),
				'docsPerFile'		=> round( $numberDocs / $numberFiles, 0 ),
				'stripsPerFile'		=> round( $numberStrips / $numberFiles, 0 ),
				'codesPerFile%'		=> round( $numberCodes / $numberFiles / $linesPerFile * 100, 1 ),
				'docsPerFile%'		=> round( $numberDocs / $numberFiles / $linesPerFile * 100, 1 ),
				'stripsPerFile%'	=> round( $numberStrips / $numberFiles / $linesPerFile * 100, 1 ),
			), 
			'files'		=> $files,
			'seconds'	=> $st->stop( 6 ),
			'path'		=> $path,
		);
	}
375186
protected function removePathPrefix($path, $prefix)
    {
        if ($prefix !== '/' && mb_stripos($path, $prefix) === 0) {
            $path = mb_substr($path, mb_strlen($prefix));
        }

        return $path;
    }
206615
public static function get($path)
    {
        $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        if (!isset(self::$fileTypes[$ext])) {
            return false;
        }
        return self::$fileTypes[$ext];
    }