webmozart / path-util
2.3.0
2015-12-17 08:42 UTC
Requires
- php: >=5.3.3
- webmozart/assert: ~1.0
Requires (Dev)
- phpunit/phpunit: ^4.6
- sebastian/version: ^1.0.1
README
最新版本: 2.3.0
PHP >= 5.3.3
此包提供健壮的跨平台实用函数,用于规范、比较和修改文件路径和URL。
弃用
此包已被合并到 Symfony 文件系统组件 5.4 中。它不再维护。
安装
可以使用 Composer 安装此工具。
$ composer require webmozart/path-util
使用
使用 Path
类处理文件路径
use Webmozart\PathUtil\Path; echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini'); // => /var/www/vhost/config.ini echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini'); // => C:/Programs/config.ini echo Path::canonicalize('~/config.ini'); // => /home/webmozart/config.ini echo Path::makeAbsolute('config/config.yml', '/var/www/project'); // => /var/www/project/config/config.yml echo Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads'); // => ../config/config.yml $paths = array( '/var/www/vhosts/project/httpdocs/config/config.yml', '/var/www/vhosts/project/httpdocs/images/banana.gif', '/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif', ); Path::getLongestCommonBasePath($paths); // => /var/www/vhosts/project/httpdocs Path::getFilename('/views/index.html.twig'); // => index.html.twig Path::getFilenameWithoutExtension('/views/index.html.twig'); // => index.html Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig'); Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig'); // => index Path::getExtension('/views/index.html.twig'); // => twig Path::hasExtension('/views/index.html.twig'); // => true Path::hasExtension('/views/index.html.twig', 'twig'); // => true Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif')); // => true Path::changeExtension('/images/profile.jpeg', 'jpg'); // => /images/profile.jpg Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json'); // => phar://C:/Documents/projects/my-project.phar/composer.json Path::getHomeDirectory(); // => /home/webmozart
使用 Url
类处理URL
use Webmozart\PathUtil\Url; echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli'); // => ../css/style.css echo Url::makeRelative('http://cdn.example.com/css/style.css', 'http://example.com/puli'); // => http://cdn.example.com/css/style.css
作者
文档
阅读 文档 了解更多关于包含函数的信息。
贡献
欢迎贡献!
支持
如果您遇到问题,请发送邮件至 [email protected] 或在 Twitter 上联系 @webmozart。
许可
此包的所有内容均受 MIT 许可 许可。