Plank\Mediable\Helpers\File::cleanDirname PHP Method

cleanDirname() public static method

Get the directory name of path, trimming unecessary . and / characters.
public static cleanDirname ( string $path ) : string
$path string
return string
    public static function cleanDirname($path)
    {
        $dirname = pathinfo($path, PATHINFO_DIRNAME);
        if ($dirname == '.') {
            return '';
        }
        return trim($dirname, '/');
    }

Usage Example

Example #1
0
 public function test_it_provides_a_cleaned_dirname()
 {
     $this->assertEquals('', File::cleanDirname(''));
     $this->assertEquals('', File::cleanDirname('/'));
     $this->assertEquals('', File::cleanDirname('foo.jpg'));
     $this->assertEquals('foo', File::cleanDirname('/foo/bar/'));
     $this->assertEquals('foo/bar', File::cleanDirname('/foo/bar/baz.jpg'));
 }
All Usage Examples Of Plank\Mediable\Helpers\File::cleanDirname