madkom/uri 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

madkom/uri

Composer 安装命令:

composer require madkom/uri

包简介

Uniform Resource Identifier (URI) and Uniform Resource Locator (URL)

README 文档

README

This library implements URI and URL specification and URI Templates, based on RFC3986 and RFC6570 (depends on external lib).

PHP 7.0 Build Status Latest Stable Version Total Downloads License Coverage Status Code Climate Issue Count

Features

This library can create objects like:

  • Uri RFC3986 - includes wide abstraction with: Scheme, Authority, Path, Query, Fragment
  • UriReference RFC3986 - can be resolved with valid Uri (eg. $resolvedUri = $uriReference->resolve($uri);)
  • UriTemplate RFC6570 - produces Uri or UriReference objects (depends on template)

Installation

Install with Composer

composer require madkom/uri

Requirements

This library requires PHP in ~7 version. At this point this library depends on another own library madkom/collection and some external packages:

  1. rize/uri-template: for UriTemplate impl
  2. true/punycode: for IDNA domain names conversion

Usage

Parsing url string:

use Madkom\Uri\UriFactory;
use Madkom\Uri\Uri;

$factory = new UriFactory();

/** @var Uri $uri */
$uri = $factory->createUri('http://user:pass@host.tld/some/path?and=query&param=2#fragment');

$uri->getScheme(); // Instance of \Madkom\Uri\Scheme\Http
$uri->getAuthority(); // Instance of \Madkom\Uri\Authority
$uri->getPath(); // Instance of \Madkom\Uri\Path
$uri->getQuery(); // Instance of \Madkom\Uri\Query

TODO Missing fragment impl yet.

Parsing and resolving UriReference:

use Madkom\Uri\UriFactory;
use Madkom\Uri\Uri;
use Madkom\Uri\UriReference;

$factory = new UriFactory();

/** @var Uri $uri */
$uri = $factory->createUri('http://user:pass@host.tld/some/path?and=query&param=2#fragment');

/** @var UriReference $uriReference */
$uriReference = $factory->createUriReference('../another/path?and=different');
(string)$uriReference->resolveUri($uri); // http://user:pass@host.tld/some/another/path?and=different

Parsing isbn uri:

use Madkom\Uri\UriFactory;
use Madkom\Uri\Uri;

$factory = new UriFactory();

/** @var Uri $uri */
$uri = $factory->createUri('isbn:978-83-283-0525-0'); // Instance of \Madkom\Uri\Uri

$uri->getScheme(); // Instance of \Madkom\Uri\Scheme\Custom
$uri->getAuthority(); // NULL
$uri->getPath(); // Instance of \Madkom\Uri\Path with "978-83-283-0525-0"
$uri->getQuery(); // Instance of \Madkom\Uri\Query which is empty

Creating URI object:

use Madkom\Uri\Uri;
use Madkom\Uri\Scheme\Https;
use Madkom\Uri\Authority;
use Madkom\Uri\Authority\Host\IPv6;
use Madkom\Uri\Authority\UserInfo;
use Madkom\Uri\Path;
use Madkom\Uri\Query;
use Madkom\Uri\Query\Parameter;

/** @var Uri $uri */
$uri = new Uri(
    new Https(),
    new Authority(
        new IPv6('::1'),
        443,
        new UserInfo('user', 'pass')
    ),
    new Path([
        'some',
        'path'
    ]),
    new Query([
        new Parameter('name', 'value')
    ])
);

$uri->toString(); // https://user:pass@[::1]:443/some/path?name=value
(string)$uri; // same as above

TODO

  • Implement Uri to string conversion
  • Implement fragment component
  • Replace IRI library with RFC Regex in \Madkom\Uri\Parser
  • Implement additional parsing modes in \Madkom\Uri\Parser\Query for various languages (parameter duplicate problem)
  • Implement normalization
  • Implement UriReference based on RFC3986

License

The MIT License (MIT)

Copyright (c) 2016 Madkom S.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固