This works this way
Do it Like a PRO 🆗
composer require transprime-research/php-url
Use it like this...
$url = new Url(
fullDomain: 'http://localhost:8080',
path: '/api/hello',
query: ['name' => 'John', 'public' => 'yes'],
);
// Or
$url = Url::make(
scheme: 'http://',
domain: 'localhost',
port: '8080',
path: '/api/hello',
query: ['name' => 'John', 'public' => 'yes'],
);
(string) $url; // http://localhost:8080/api/hello?name=John&public=yes
$url->toString(); // http://localhost:8080/api/hello?name=John&public=yes
$url = Url::make()
->setScheme('http://')
->setDomain('localhost')
->setPort('8080')
->setPath('/api/hello')
->addToQuery('name', 'John')
->addToQuery('public', 'yes');
(string) $url; // http://localhost:8080/api/hello?name=John&public=yes
Api implementation to be decided
See other packages in this series here:
- https://github.com/omitobi/conditional [A smart PHP if...elseif...else statement]
- https://github.com/transprime-research/piper [A functional PHP pipe in object-oriented way]
- https://github.com/transprime-research/arrayed [Array now an object]
- https://github.com/transprime-research/attempt [A smart PHP try...catch statement]
- https://github.com/omitobi/corbonate [A smart Carbon + Collection package]
- https://github.com/omitobi/laravel-habitue [Jsonable Http Request(er) package with Collections response]
- luzzardi/php-url
- martinmdev/php-url
- simlux/php-url
- thesmart/php-url
MIT (See LICENCE file)