romeoz/rock-url

A simple PHP library to parse and builder URLs

0.12.1 2015-11-07 05:28 UTC

README

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License

Installation

From the Command Line:

composer require romeoz/rock-url

In your composer.json:

{
    "require": {
        "romeoz/rock-url": "*"
    }
}

Quick Start

use rock\url\Url;

// example URL: http://site.com/foo/?page=1

// returns relative URL
(new Url)->getRelative(); // output: /foo/?page=1

// modify URL
Url::set('https://site.com/?page=2#name')->removeFragment()->getRelative(); 
//output: /?page=2

Url::set('https://site.com/?page=2#name')->removeQueryParams(['page'])->getAbsolute(); 
//output: https://site.com/#name

###Short method modify()

Url::modify(['https://site.com/', 'foo' => 'test', '#' => 'name']);
//output: /?foo=test#name

Url::modify(['https://site.com/?foo=test#name', '!foo', '!#', '@scheme' => Url::ABS]);
//output: https://site.com/

// modify current url
Url::modify([foo' => 'test]);
//output: /?foo=test

Requirements

  • PHP 5.4+
  • For generating CSRF-token (security) required Rock CSRF: composer require romeoz/rock-csrf

All unbolded dependencies is optional

License

Rock URL library is open-sourced software licensed under the MIT license.