codezero / php-url-builder
Parse, manipulate and rebuild a URL.
Fund package maintenance!
Ko Fi
paypal.me/ivanvermeyen
Installs: 163 438
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-10-30 02:21:38 UTC
README
✅ Requirements
- PHP >= 7.2
📦 Install
Install this package with Composer:
composer require codezero/php-url-builder
📘 Usage
You create a new UrlBuilder
instance and pass it the URL you want to manipulate:
$urlBuilder = new \CodeZero\UrlBuilder\UrlBuilder('http://www.example.com/abc/def?foo=bar'); // or... $urlBuilder = \CodeZero\UrlBuilder\UrlBuilder::make('http://www.example.com/abc/def?foo=bar');
When you are done, you can build the new URL:
$url = $urlBuilder->build(); //=> Returns 'http://www.example.com/abc/def?foo=bar' $url = $urlBuilder->build(false); //=> Returns '/abc/def?foo=bar'
Updating URL Parts
There are setters and getters for the different URL parts:
$urlBuilder->setScheme('https'); $urlBuilder->getScheme(); //=> Returns 'https' $urlBuilder->setHost('www.example.com'); $urlBuilder->getHost(); //=> Returns 'www.example.com' $urlBuilder->setPort(8000); $urlBuilder->getPort(); //=> Returns '8000' $urlBuilder->setPath('/abc/def'); $urlBuilder->getPath(); //=> Returns '/abc/def' $urlBuilder->getSlugs(); //=> Returns ['abc', 'def'] $urlBuilder->setSlugs(['abc', 'def']); $urlBuilder->getPath(); //=> Returns '/abc/def' $urlBuilder->getSlugs(); //=> Returns ['abc', 'def'] $urlBuilder->setQueryString('foo=bar'); $urlBuilder->getQueryString(); //=> Returns 'foo=bar' $urlBuilder->getQuery(); //=> Returns ['foo' => 'bar'] $urlBuilder->setQuery(['foo' => 'bar']); $urlBuilder->getQueryString(); //=> Returns 'foo=bar' $urlBuilder->getQuery(); //=> Returns ['foo' => 'bar']
🚧 Testing
composer test
☕ Credits
🔒 Security
If you discover any security related issues, please e-mail me instead of using the issue tracker.
📑 Changelog
A complete list of all notable changes to this package can be found on the releases page.
📜 License
The MIT License (MIT). Please see License File for more information.