FileNamingResolver\FileInfo::getPathnameRelativeTo PHP Method

getPathnameRelativeTo() public method

public getPathnameRelativeTo ( string $basePathname ) : string
$basePathname string
return string
    public function getPathnameRelativeTo($basePathname)
    {
        $basePathname = $this->purifyPath($basePathname) . static::SEPARATOR_DIRECTORY;
        $relativePathname = $this->getPathname();
        $prefix = mb_substr($relativePathname, 0, mb_strlen($basePathname));
        if ($prefix === $basePathname) {
            $relativePathname = mb_substr($relativePathname, mb_strlen($prefix));
        }
        return $relativePathname;
    }

Usage Example

Example #1
0
 public function testGetPathnameRelativeTo()
 {
     $fileInfo = new FileInfo('/var/www/web/uploads/products/image.jpg');
     $this->assertEquals('uploads/products/image.jpg', $fileInfo->getPathnameRelativeTo('/var/www/web'));
 }