webignition/absolute-url-deriver

从相对和源URL派生绝对URL

3.0 2019-01-09 18:03 UTC

This package is auto-updated.

Last update: 2024-09-10 05:57:36 UTC


README

概览

从相对和源URL派生绝对URL。

适用场景

  • 提取HTML文档中链接的完整HREF URL
  • 确定301重定向的绝对新URL,其中HTTP服务器返回了相对位置值

用法

"Hello World" 示例

<?php
use webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver;
use webignition\Uri\Uri;

$base = 'https://example.com';
$relative = '/path?query#fragment';

$this->assertEquals(
    'https://example.com/path?query#fragment', 
    AbsoluteUrlDeriver::derive(new Uri($base), new Uri($relative))
);

构建

在项目中作为库使用

如果另一个项目将其用作依赖项,请更新该项目的composer.json文件并更新您的依赖项。

"require": {
    "webignition/absolute-url-deriver": ">=3,<4"      
}

开发

该项目使用composer管理外部依赖项。首先获取并安装此软件。

# Make a suitable project directory
mkdir ~/absolute-url-deriver && cd ~/absolute-url-deriver

# Clone repository
git clone git@github.com:webignition/absolute-url-deriver.git .

# Retrieve/update dependencies
composer install

测试

查看travis上的项目以获取最新的构建状态,或者亲自运行测试。

cd ~/absolute-url-deriver
phpunit tests