private static function infoToJson(FileSystemInfo $info) { $isDir = $info instanceof DirectoryInfo; $virtualPath = Path::getVirtualPath($info->getFullName(), Config::getRootDir()); $json = array('name' => $info->getName(), 'path' => strlen($virtualPath) > 1 ? rtrim($virtualPath, '/') : $virtualPath, 'size' => $isDir ? 0 : $info->getSize(), 'last_access_time' => DateTimeUtils::toString($info->getLastAccessTime()), 'last_write_time' => DateTimeUtils::toString($info->getLastWriteTime()), 'is_dir' => $isDir); return $json; }
public function testGetVirtualPath() { $realPath = '/'; $result = Path::getVirtualPath($realPath); $expected = $realPath; $this->assertEquals($expected, $result); $realPath = '/files'; $result = Path::getVirtualPath($realPath); $expected = $realPath; $this->assertEquals($expected, $result); $rootDir = '/'; $realPath = '/'; $result = Path::getVirtualPath($realPath, $rootDir); $expected = $realPath; $this->assertEquals($expected, $result); $rootDir = '/'; $realPath = '/files'; $result = Path::getVirtualPath($realPath, $rootDir); $expected = $realPath; $this->assertEquals($expected, $result); $rootDir = __DIR__; $realPath = __DIR__ . '/files'; $result = Path::getVirtualPath($realPath, $rootDir); $expected = '/files'; $this->assertEquals($expected, $result); $rootDir = __DIR__; $realPath = __DIR__ . '/../files'; $result = Path::getVirtualPath($realPath, $rootDir); $expected = '/../files'; $this->assertEquals($expected, $result); }