malenki/url 问题修复 & 功能扩展

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

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

malenki/url

Composer 安装命令:

composer require malenki/url

包简介

Simple class to deal with URL, using magic getter, multisyntaxic way, to play with URL like yoou want!

README 文档

README

Build Status

Handle URL with ease!

Introduction

To play with URL string in PHP, you have to deal with some functions, not easy at all. With my little lib, you can get/set/icomplete/avoid many part of an URL. So, quick example to give you some idea:

$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
echo $u->credential;
echo $u->host;

// you can change some parts using this way:
$u->credential->user = 'login';
$u->host = 'example.org'
$u->query->foo = 'bar';

// you can use other way too:
$u->user('login')->host('example.org')->query(array('foo', 'bar'));

// toString available:
echo $u; // http://login:password@example.org:8080/path?arg=value&foo=bar#anchor

How to use it

You can handle URL using two ways:

  • chainable methods of Url class
  • call some methods on URL's parts to have finest control.

Only URL class

Set values or complete thems

Each URL part can be called with its name as a chainable method, as you can see into the following example:

$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->user('login')->host('example.org')->query(array('foo', 'bar'));

You must notice that methods path() and query() do not remove original content, but complete it with value given as argument. You must disable respective part before, like explained into next part.

Disable parts or test their availability

Some more actions are available too, by using methods no(), disable() and has():

  • no() and disable() are both the same effect, one is alias of other, and take one argument, a string or an array of string. Argument must contain an URL part (scheme, port…). So, $u->no('port') disables port part and $u->disable(array('query', 'path')) removes query and path parts from the URL.
  • has() tests whether a part is available into the URL or not. Simple, you give the name of the part to test and the method return true if it finds the part filled.

All methods explained into this section can be called using magic getter by using method name as prefix, followed by underscore and the part's name, so, you can do this for example:

echo $u->no_port->disable_credential;
var_dump($u->has_port);

Act on URL's parts

You have finest control using method relative to URL parts:

$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->anchor->clear; // delete anchor
$u->path->add('other'); // add branch to path
$u->query->arg = 'other_value'; // Changed one arg of the query string

Common methods

Each part has at least this methods:

  • isVoid() to test whether the part has content or not
  • clear() to avoid the part
  • toString() is available

Set in one shot

You can set part directly (override original content):

$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->path = 'other/path'; //or using array
$u->anchor = 'new_anchor';

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固