定制 haukurh/uri 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

haukurh/uri

Composer 安装命令:

composer require haukurh/uri

包简介

PHP library to parse URI into it's components, based on RFC 3986

README 文档

README

PHP library to parse URI into it's components, based on RFC 3986

Description

The main idea of this library is to parse a URI into it's components. It does not validate the URI in any shape or form only parse the URI, given some basic rules based on RFC 3986.

For now it acts very much like parse_url() but does not change invalid characters in the URL, like some utf8 characters that may be a part of the path and/or query.

Some validation and more functionality may be implemented in the future.

Basic usage

Some basic getters have been made available to retrieve the desired component. The components are also available as public properties to read or write, but using the getters is encouraged because some business logic maybe applied to the selected URI component, like scheme to lowercase.

<?php

require_once 'vendor/autoload.php';

use Haukurh\Uri\Uri;

$uri = new Uri('HTTPS://john.doe@www.example.com:8000/some/path?q=term#result1');

echo $uri->getScheme() . PHP_EOL; // https
echo $uri->getAuthority() . PHP_EOL; // john.doe@www.example.com:8000
echo $uri->getPath() . PHP_EOL; // /some/path
echo $uri->getQuery() . PHP_EOL; // q=term
echo $uri->getFragment() . PHP_EOL; // result1

echo $uri . PHP_EOL; // https://john.doe@www.example.com:8000/some/path?q=term#result1

var_dump($uri->toArray());
// array(5) {
//   ["scheme"]=>
//   string(5) "https"
//   ["authority"]=>
//   string(29) "john.doe@www.example.com:8000"
//   ["path"]=>
//   string(10) "/some/path"
//   ["query"]=>
//   string(6) "q=term"
//   ["fragment"]=>
//   string(7) "result1"
// }

Like previously mentioned the URI components are public properties, which can be used to manipulate the URI. For example when working with relative urls found in websites, i.e. http and https schemes or some other schemes that "allow" some loose interpretations of URI's.

<?php

use Haukurh\Uri\Uri;

$relativeAnchorLink = '/public/css/main.css?v=1.3';

$uri = new Uri($relativeAnchorLink);

echo $uri; // /public/css/main.css?v=1.3

$uri->scheme = 'https';
$uri->authority = 'www.example.com';

echo $uri; // https://www.example.com/public/css/main.css?v=1.3

Run tests

Some test have been created to ensure parsing of components are correct.

Run tests with phpunit

./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/

ToDo

  • Break down authority to it's subcomponents.
  • Add some functionality based around URL based schemes like http, https
  • Implement better tests with focus on some edge cases.
  • Refactor tests

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固