PHPackages                             dariof28/url-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dariof28/url-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dariof28/url-builder
====================

This package provides a UrlBuilder to easily generate urls specifying protocol, params, port etc

1.0.0(1y ago)17MITPHPPHP ^8.1

Since May 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dariof28/url-builder)[ Packagist](https://packagist.org/packages/dariof28/url-builder)[ RSS](/packages/dariof28-url-builder/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

UrlBuilder
==========

[](#urlbuilder)

This php package help to build urls.

[![GitHub](https://camo.githubusercontent.com/dcf55b96260a78e6e0bbabaf338e64024b4897df0f3d6165346816f1963d6208/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646172696f6632382f75726c2d6275696c646572)](https://camo.githubusercontent.com/dcf55b96260a78e6e0bbabaf338e64024b4897df0f3d6165346816f1963d6208/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646172696f6632382f75726c2d6275696c646572) [![GitHub code size in bytes](https://camo.githubusercontent.com/0ae1d36bf3ec51d6e85feec891dc5efbc62e8cf876664e44d74dc324fec27930/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646172696f6632382f75726c2d6275696c646572)](https://camo.githubusercontent.com/0ae1d36bf3ec51d6e85feec891dc5efbc62e8cf876664e44d74dc324fec27930/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646172696f6632382f75726c2d6275696c646572) [![Packagist Downloads](https://camo.githubusercontent.com/9833b61332990a46769850578aef3eeb1c0598e4eb3a93aaaa36b3bb9a8210b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646172696f6632382f75726c2d6275696c646572)](https://camo.githubusercontent.com/9833b61332990a46769850578aef3eeb1c0598e4eb3a93aaaa36b3bb9a8210b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646172696f6632382f75726c2d6275696c646572) [![Packagist Version](https://camo.githubusercontent.com/d3fba0a31c43fbe2fca46df7173b54c50b12bc492f07dec2559c2ec92b5fb68c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646172696f6632382f75726c2d6275696c646572)](https://camo.githubusercontent.com/d3fba0a31c43fbe2fca46df7173b54c50b12bc492f07dec2559c2ec92b5fb68c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646172696f6632382f75726c2d6275696c646572) [![LinkedIn](https://camo.githubusercontent.com/ff420948919f5a09c0f6b8becb4debf890761698c8df56b4df792a96180d58b9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4c696e6b6564496e2d626c75652e7376673f7374796c653d666c61742d737175617265266c6f676f3d6c696e6b6564696e)](https://linkedin.com/in/dariof28)

Installation
------------

[](#installation)

```
composer require dariof28/url-builder
```

Usage
-----

[](#usage)

The simpler case is when you want to build an url from a host. By default, protocol is automatically set to `https`.

```
use DariofDev\UrlBuilder\Url;

$url = new Url('foo.bar'); // https://foo.bar
```

The host should not contain the protocol.

### Protocol

[](#protocol)

If you want to use another protocol you can use the `->setProtocol()` method

```
use DariofDev\UrlBuilder\Url;

$url = (new Url('foo.bar'))
    ->setProtocol('sftp'); // sftp://foo.bar
```

Allowed protocols are:

- 'ftp'
- 'sftp'
- 'http'
- 'https'
- 'smtp'

If an invalid protocol is provided an `InvalidProtocolException` is thrown.

### Port

[](#port)

You can specify an arbitrary port. By default, no port is implied.

```
use DariofDev\UrlBuilder\Url;

$url = (new Url('foo.bar'))
    ->setPort(8000); // https://foo.bar:8000
```

### Path

[](#path)

To define the path you can use `setPath()` method

```
use DariofDev\UrlBuilder\Url;

$url = (new Url('foo.bar'))
    ->setPath('baz'); // https://foo.bar/baz
```

Path can also contain placeholder that will be replaced with given values

```
use DariofDev\UrlBuilder\Url;

$url = (new Url('foo.bar'))
    ->setPath('baz/%s', [1]); // https://foo.bar/baz/1
```

### Params

[](#params)

Params can be simple strings as like as arrays.

You can add params in 2 ways:

- directly in the constructor:

```
use DariofDev\UrlBuilder\Url;

$url = new Url('foo.bar', ['foo' => 'bar']); // https://foo.bar?foo=bar
```

- with fluent setter

```
use DariofDev\UrlBuilder\Url;

$url = (new Url('foo.bar'))
    ->addParam('foo', 'bar')
    ->addParam('bar', ['baz' => 'foo']); // https://foo.bar?foo=bar&bar%5Bbaz%5D=foo
```

Development
-----------

[](#development)

A simple docker container with php 8, composer and Xdebug is provided. Just run

```
docker-compose run --rm url-builder bash
```

### Code style

[](#code-style)

Ensure that style rules are applied running the cs fixer before commit

```
./vendor/bin/php-cs-fixer fix
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance40

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1332 days

Total

2

Last Release

503d ago

Major Versions

0.1.0 → 1.0.02024-12-24

PHP version history (2 changes)0.1.0PHP ^7.4|^8.0

1.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49391038?v=4)[Dario Finocchiaro](/maintainers/dariof28)[@dariof28](https://github.com/dariof28)

---

Top Contributors

[![dariof28](https://avatars.githubusercontent.com/u/49391038?v=4)](https://github.com/dariof28 "dariof28 (8 commits)")

---

Tags

urllinkbuilder

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dariof28-url-builder/health.svg)

```
[![Health](https://phpackages.com/badges/dariof28-url-builder/health.svg)](https://phpackages.com/packages/dariof28-url-builder)
```

###  Alternatives

[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[spatie/url

Parse, build and manipulate URL's

73914.3M97](/packages/spatie-url)[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[sabre/uri

Functions for making sense out of URIs.

29335.2M40](/packages/sabre-uri)[misd/linkify

Converts URLs and email addresses in text into HTML links

1122.9M10](/packages/misd-linkify)[spomky-labs/base64url

Base 64 URL Safe Encoding/Decoding PHP Library

15439.5M49](/packages/spomky-labs-base64url)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
