2017 © Pedro Peláez
 

library url

Simple url wrapper.

image

weew/url

Simple url wrapper.

  • Wednesday, February 22, 2017
  • by weew
  • Repository
  • 1 Watchers
  • 1 Stars
  • 314 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

URL wrapper

Build Status Code Quality Test Coverage Dependencies Version Licence, (*1)

Table of contents

Installation

composer require weew/url, (*2)

Overview

Currently this library is able to parse and build urls of such format and complexity:, (*3)

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

For example:, (*4)

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

Instantiation

Creating a new url is very easy:, (*5)

$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:, (*6)

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., (*7)

$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., (*8)

$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., (*9)

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

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

Placeholders can have custom patterns., (*10)

$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;, (*11)

Parsing

Retrieving placeholder values is very trivial., (*12)

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

For further documentation check out the weew/url-matcher package;, (*13)

Replacing

You can replace placeholders inside your path with values., (*14)

$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();

The Versions

23/05 2016

v1.5.1

1.5.1.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1
  • weew/php-collections ^1.0
  • weew/php-url-matcher ^1.0

 

The Development Requires

by Maxim Kott

30/03 2016

v1.5.0

1.5.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1
  • weew/php-collections ^1.0
  • weew/php-url-matcher ^1.0

 

The Development Requires

by Maxim Kott

10/03 2016

v1.4.0

1.4.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1
  • weew/php-collections ^1.0
  • weew/php-url-matcher ^1.0

 

The Development Requires

by Maxim Kott

10/03 2016

v1.3.0

1.3.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1
  • weew/php-collections ^1.0
  • weew/php-url-matcher ^1.0

 

The Development Requires

by Maxim Kott

25/01 2016

v1.2.0

1.2.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1
  • weew/php-collections ^1.0
  • weew/php-url-matcher ^1.0

 

The Development Requires

by Maxim Kott

17/11 2015

v1.1.0

1.1.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-contracts ^1.1

 

The Development Requires

by Maxim Kott

16/11 2015

v1.0.0

1.0.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-foundation ^1.0.0

 

The Development Requires

by Maxim Kott

30/10 2015

v0.1.2

0.1.2.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

24/08 2015

v0.1.0

0.1.0.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

24/08 2015

v0.1.1

0.1.1.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

19/08 2015

v0.0.7

0.0.7.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

14/08 2015

v0.0.6

0.0.6.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maxim Kott

14/08 2015

v0.0.5

0.0.5.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maxim Kott

14/08 2015

v0.0.4

0.0.4.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maxim Kott

14/08 2015

v0.0.3

0.0.3.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

31/07 2015

v0.0.2

0.0.2.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott

21/07 2015

v0.0.1

0.0.1.0

Url wrapper for php.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-foundation 0.*

 

The Development Requires

by Maxim Kott