JBZoo\Utils\Url::pathToUrl PHP Method

pathToUrl() public static method

Convert file path to absolute URL
public static pathToUrl ( $path ) : string
$path
return string
    public static function pathToUrl($path)
    {
        return self::root() . '/' . self::pathToRel($path);
    }

Usage Example

示例#1
0
文件: UrlTest.php 项目: jbzoo/utils
 public function testPathToUrl()
 {
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/test.php?foo=bar';
     $_SERVER['QUERY_STRING'] = 'foo=bar';
     $_SERVER['PHP_SELF'] = '/test.php';
     $_SERVER['DOCUMENT_ROOT'] = PROJECT_ROOT;
     isSame('tests/UrlTest.php', Url::pathToRel(__FILE__));
     isSame('http://test.dev/tests/UrlTest.php', Url::pathToUrl(__FILE__));
     $_SERVER['DOCUMENT_ROOT'] = str_replace('/', '\\', PROJECT_ROOT);
     isSame('tests/UrlTest.php', Url::pathToRel(__FILE__));
     isSame('http://test.dev/tests/UrlTest.php', Url::pathToUrl(__FILE__));
 }