承接 weew/url 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

weew/url

Composer 安装命令:

composer require weew/url

包简介

Simple url wrapper.

README 文档

README

Build Status Code Quality Test Coverage Dependencies Version Licence

Table of contents

Installation

composer require weew/url

Overview

Currently this library is able to parse and build urls of such format and complexity:

// protocol://username:password@subdomain.domain.tld:port/path?key=value#fragment

For example:

// https://john:doe@another.domain.net:8080/my/path?query=value&some=value#hashtag

Instantiation

Creating a new url is very easy:

$url = new Url('http://username:password@subdomain.domain.com:80/some/path?query=value#fragment');

Parsing

Url containts manny segments which can be accessed trough convenient methods:

echo $url->getProtocol();
// http

echo $url->getHost();
// subdomain.domain.com

echo $url->getDomain();
// domain

echo $url->getSubdomain();
// subdomain

echo $url->getTLD();
// com

echo $url->getPort();
// 80

echo $url->getPath();
// /some/path

echo $url->getQuery();
// query=value

echo $url->getFragment();
// fragment

echo $url->getUsername();
// username

echo $url->getPassword();
// password

Building

You can modify url segments in the same manner.

$url->setProtocol('https');

$url->setHost('another.domain.net');
// or
$url->setDomain('domain');
$url->setSubdomain('another');
$url->setTLD('net');

$url->setPort(8080);
$url->setPath('my/path');
$url->addPath('here');
$url->getQuery()->set('some', 'value');
$url->setFragment('hashtag');
$url->setUsername('john');
$url->setPassword('doe');

echo $url;
// https://john:doe@another.domain.net:8080/my/path/here?query=value&some=value#hashtag

Matching

You can match url path against a pattern.

$url = new Url('users/1');
// true
$url->match('users/{id}');

$url = new Url('users');
// false
$url->match('users/{id}');

Placeholders can be optional by adding the ? sign at the end.

$url = new Url('users/1');
// true
$url->match('users/{id?}');

$url = new Url('users');
// true
$url->match('users/{id?}');

Placeholders can have custom patterns.

$url = new Url('users/1');
// true
$url->match('users/{id}', [
    'id' => '[0-9]+',
]);

$url = new Url('users/abc');
// false
$url->match('users/{id}', [
    'id' => '[0-9]+',
]);

For further documentation check out the weew/url-matcher package;

Parsing

Retrieving placeholder values is very trivial.

$url = new Url('users/1');
$dictionary = $url->parse('users/{id}');
// 1
$dictionary->get('id');

For further documentation check out the weew/url-matcher package;

Replacing

You can replace placeholders inside your path with values.

$url = new Url('{subdomain}.service.com/users/{id}/profile');
$url->replace('subdomain', 'api');
$url->replace('id', 1);

// or 
$url->replaceAll(['subdomain' => 'api', 'id' => 1]);

// api.service.com/users/1/profile
$url->toString();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固