Download the PHP package thinktomorrow/url without Composer
On this page you can find all versions of the php package thinktomorrow/url. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thinktomorrow/url
More information about thinktomorrow/url
Files in thinktomorrow/url
Package url
Short Description A simple php url utility class.
License MIT
Homepage https://github.com/thinktomorrow/url
Informations about the package url
Url
A URL helper class to easily extract certain parts of the url. It is basically a wrapper around the native parse_url
function.
Currently, parse_url
has no solid support for parsing uri strings. This package aims to
provide that support.
This small package is framework agnostic and has no dependencies.
Install via composer
Usage
Create an Url instance
Create a new url instance by calling the static fromString
method with your url string.
In case of a malformed url string, an InvalidUrl
exception will be thrown. This
validation is based on what the native parse_url
considers a malformed url string.
Parts of the url
Via the Url instance, you have access to all the different parts of the url string. You can retrieve the following parts:
Altering the url string
Securing a url
You can secure an url with the secure()
method.
You can force a non-secure scheme with the nonSecure
method.
Changing url root
In the case you need to change the url root, you can use the setCustomRoot
method.
This expects a \Thinktomorrow\Url\Root
object as argument.
Localizing the url
In case you use the url path segment for localization purposes, you can inject the locale segment with the localize
method
The localize
method also accepts a second parameter to enlist all available locales. In the case that passed url
contains any of these locales, the existing locale will be replaced by the new locale.
If you pass null
as the locale parameter, any locale segment will be removed.
Testing
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Ben Cavens [email protected]
- Philippe Damen [email protected]
License
The MIT License (MIT). Please see License File for more information.