Centum\Url
This component enables you to easily change your base URI across your codebase. This can be useful in cases where the URI might change depending on the environment (for example: development and production).
Centum\Url\Url(
string $baseUri = ""
);
Centum\Url\Url
implements Centum\Interfaces\Url\UrlInterface
.
Centum\Url\Url
has 2 public methods:
public function getBaseUri(): string
public function get(string $uri = "", array $arguments = []): string
Centum\Url\Url
takes care of trailing/leading slashes:
use Centum\Url\Url;
$baseUri = "https://example.com";
$url = new Url($baseUri);
// https://example.com/path/to/something
echo $url->get("path/to/something");
// https://example.com/path/to/something
echo $url->get("/path/to/something");
You can also specify URL arguments. They are automatically sanitised and encoded by http_build_query()
:
// https://example.com/search?query=hello+world&page=123
echo $url->get(
"/search",
[
"query" => "hello world",
"page" => 123,
]
);