Dirname function that mimics PHP7 dirname() enhancements so that we can enable PHP5.6 support.

@param string $path Path to this specific plugins directory.
@param int    $count How many directories to look upwards.

@return string
545062
public static function dirname( $path, $count = 1 ) {
		if ( $count > 1 ) {
			return dirname( static::dirname( $path, -- $count ) );
		} else {
			return dirname( $path );
		}
	}
968290
public static function basename($path) {
        $pos = strrpos($path, '/');
        if ($pos === false) {
            return $path;
        }
        return substr($path, $pos + 1);
    }
646825
public static final function ppath ($path){
		while (!is_dir($path) && strlen($path) > 0){
			$path = preg_replace('/[^\/]+\/?$/', null, $path);
		}

		return !empty($path) ? $path : false;
	}
569818
public function read(int $count): string
    {
        $this->lastAccessed = time();
        return $this->content->read($count);
    }
771298
public function hit($count = 1)
	{
		if (file_exists($this->path))
		{
			$expires = $this->getPathContent('expires');
			if ( ! is_null($expires))
			{
				$hits = $this->getPathContent('hits');
				$hits += $count;
				if ($hits > $this->hits)
				{
					// we reached the limit
					return false;
				}
				$size = $this->writePathContent($expires, $hits);

				return $size !== false;
			}
		}

		// first hit
		$expires = time() + $this->seconds;
		$size    = $this->writePathContent($expires, $count);

		return $size !== false;
	}
1023108
public static function dirsize(string $path) {
		$size = 0;
		$files = static::scandir($path, true, false);
		foreach ($files as $v) {
			$size += @\filesize($v);
		}
		return $size;
	}
643941
protected function gettmb($path, $stat) {
		if ($this->tmbURL && $this->tmbPath) {
			// file itself thumnbnail
			if (strpos($path, $this->tmbPath) === 0) {
				return basename($path);
			}

			$name = $this->tmbname($stat);
			if (file_exists($this->tmbPath.DIRECTORY_SEPARATOR.$name)) {
				return $name;
			}
		}
		return false;
	}
787325
public function getPath(string $path = ''): string
    {
        return $this->dirPath.($path ? DIRECTORY_SEPARATOR.$path : $path);
    }
1196227
public function dirname(string $path, int $levels = 1): string
    {
        [$scheme, $path] = $this->getSchemeAndHierarchy($path);

        if ($this->normalize || ($scheme && null === $this->normalize)) {
            $path = $this->normalizePathPart($path);
        }

        [$scheme, $path] = $this->dirnameInternal($scheme, $path, $levels);

        return $this->toString($scheme, $path);
    }
1173684
private function walk($count = 1)
    {
        $token = $nextToken = $this->lexer->token;

        for ($i = 0; ($i < $count) || ($token === $nextToken); ++$i) {
            $this->lexer->moveNext();
            $nextToken = $this->lexer->token;
        }

        return $nextToken;
    }
664897
public function getFileName($path, $filename)
	{
		if (file_exists("$path/$filename")) {
			$filename = Nette\Utils\Random::generate() . '_' . $filename;
			$filename = $this->getFileName($path, $filename);
		} else {
			$filename;
		}

		return $filename;
	}
816436
public static function createFolder($path)
    {
        if (!file_exists($path)) {
            self::createFolder(dirname($path));
            mkdir($path, 0777);
        }
    }
610476
public function getDirectoryName(string $path) : string
    {
        if (!$this->exists($path)) {
            throw new FileSystemException("File at path $path not found");
        }

        return pathinfo($path, PATHINFO_DIRNAME);
    }
1243305
private function appendTabulationCharacter($text, $count): string
    {
        $lines = \explode("\n", $text);

        foreach ($lines as $index => $line) {
            $lines[$index] = \str_repeat("    ", $count).rtrim($line);
        }

        return \implode(PHP_EOL, $lines);
    }
945918
public static function dirFormat(string $path)
    {
        $path = str_replace('\\', '/', $path);
        $path = preg_replace_callback('/(\{.+\})/U', function ($matches) {
            return date(rtrim(ltrim($matches[0], '{'), '}'));
        }, $path);
        return $path;
    }
30968
protected function getAlterMigrationName($name, $count)
    {
        $filename = sprintf('%s_alter_%s_table_%s.php', date('Y_m_d_His'), strtolower($name), $count);

        return Helpers::postFixWith($filename, '.php');
    }
504421
public static function getDirectoryFilenames($path, $subfolder=NULL, $fileList=array()) {
	
		// list of files to exclude
		$excludes = array('..', '.', '.DS_Store', 'thumbs.db', '.htaccess');
		
		try {
			
			// reads folders file and dirs as plain array
			$filenames = array_diff(scandir($path, 0), $excludes);
			
			// we look at each file/dir
			foreach ($filenames as $filename) {
	
				// relative file-path
				$file = $path . '/' . $filename;
		
				// it’s a directory, scan it
				if (is_dir($file)) {
	
					// recursive callback to scan new directory
					$fileList = self::getDirectoryFilenames($file, $subfolder . $filename . '/', $fileList);
						
				// it’s file, add it
				} else {
	
					$fileList[] = $subfolder . $filename;
						
				}
					
			}
	
		} catch (\Exception $e) {

			trigger_error($e->getMessage());
			return array();
			
		}
	
		return $fileList;
	
	}