PHPackages                             jpi/utils - 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. jpi/utils

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

jpi/utils
=========

Library with various utility classes

v1.1.1(3mo ago)05.2k↓83.3%2GPL-3.0-onlyPHPPHP ^8.0CI passing

Since Sep 18Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jahidulpabelislam/utils)[ Packagist](https://packagist.org/packages/jpi/utils)[ RSS](/packages/jpi-utils/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (28)Used By (2)

Utilities
=========

[](#utilities)

[![CodeFactor](https://camo.githubusercontent.com/34c929c1f2177fc204d8f0ad901887ba99140f66f0cbb5e17acf27c8de7d50d6/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a61686964756c706162656c69736c616d2f7574696c732f6261646765)](https://www.codefactor.io/repository/github/jahidulpabelislam/utils)[![Latest Stable Version](https://camo.githubusercontent.com/e7122fa596fc2b280b31c5ab50fdee74722a1722c0d6c73447d23802cf24d310/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f7574696c732f762f737461626c65)](https://packagist.org/packages/jpi/utils)[![Total Downloads](https://camo.githubusercontent.com/c471e54d32e655b290383370b10a01f23220f8dcd368ffb4e0af8caafdd7352f/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f7574696c732f646f776e6c6f616473)](https://packagist.org/packages/jpi/utils)[![Latest Unstable Version](https://camo.githubusercontent.com/44d354ff8da2b59906dd6715aae7ce8868fe9c042968fa48a33565e642700b8f/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f7574696c732f762f756e737461626c65)](https://packagist.org/packages/jpi/utils)[![License](https://camo.githubusercontent.com/812970bc4d6774e8b1811799e4f57d6e84ee053f5df59923d5077991f4ce53ed/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f7574696c732f6c6963656e7365)](https://packagist.org/packages/jpi/utils)[![GitHub last commit (branch)](https://camo.githubusercontent.com/2b668d2c1df378c9c1504bb15f572fe3d268bc3c30699eeb080ba1a642b35af8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6a61686964756c706162656c69736c616d2f7574696c732f312e782e7376673f6c6162656c3d6c6173742532306163746976697479)](https://camo.githubusercontent.com/2b668d2c1df378c9c1504bb15f572fe3d268bc3c30699eeb080ba1a642b35af8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6a61686964756c706162656c69736c616d2f7574696c732f312e782e7376673f6c6162656c3d6c6173742532306163746976697479)

A tiny library that provides very simple utility classes.

This provides a simple singleton trait to go on classes, URL builder class and a few different classes/traits around collections.

Dependencies
------------

[](#dependencies)

- PHP 8.0+
- Composer

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

[](#installation)

Use [Composer](https://getcomposer.org/)

```
$ composer require jpi/utils
```

Usage
-----

[](#usage)

### Singleton

[](#singleton)

Simply add `\JPI\Utils\Singleton` to any class, this will make the constructor protected so the class can't be instantiated outside the singleton getter, also provides a `get` method which handles the class being singleton.

### URL

[](#url)

`\JPI\Utils\URL` provides 5 static helper methods (which should be self-explanatory):

- `removeLeadingSlash(string): string`
- `removeTrailingSlash(string): string`
- `removeSlashes(string): string`
- `addLeadingSlash(string): string`
- `addTrailingSlash(string): string`

`\JPI\Utils\URL` as a class instance provides building a URL, the class has a single optional string argument, which you can pass if you know what the starting URL should be. You then have the following methods to build on top of this starting URL:

- `setScheme(string|null)`
- `setHost(string|null)`
- `setPath(string|null)`
- `addPath(string)`
- `setQueryParams(array)`
- `setQueryParam(string, string|array)`
- `removeQueryParam(string)`
- `setFragment(string|null)`

They all come with equivalent getter methods:

- `getScheme: string|null`
- `getHost: string|null`
- `getPath: string|null`
- `getQueryParams: array`
- `getFragment: string|null`

Also, a `getQuery: string|null` method which transforms the query params to an encoded query string to be used in a URL (minus the `?`).

Lastly, the class implements `\Stringable` so you can cast the instance to a string or can manually call `build` method to get the URL as a string.

### Collections

[](#collections)

Here we have `\JPI\Utils\Collection`, `\JPI\Utils\Collection\Immutable` &amp; `\JPI\Utils\Collection\Paginated`.

A collection works like a normal array as it implements `\ArrayAccess`, `\Countable` &amp; `\IteratorAggregate` just with some extra methods (all should be self-explanatory):

- `isset(string|int $key)`
- `get(string|int $key, $default = null): mixed`
- `getCount(): int`
- `each(callable)`
- `pluck(string $toPluck, ?string $keyedBy = null): CollectionInterface`
- `groupBy(string $groupByKey): CollectionInterface`

The `Collection` class also has the following methods (these exist on `Immutable` and `Paginated` but will throw an exception)

- `add(mixed $item)`
- `set(string|int $key, mixed $item)`
- `unset(string|int $key)`
- `clear`

A `Paginated` instance has the following additional methods:

- `getTotalCount(): int`
- `getLimit(): int` get what limit was applied when getting the result
- `getPage(): int` get what page number was applied when getting the result

We also have interfaces in case you want to create your own versions, `\JPI\Utils\CollectionInterface`, `\JPI\Utils\Collection\ImmutableInterface` &amp; `\JPI\Utils\Collection\PaginatedInterface` (which extends `ImmutableInterface`). If you do create your own collection classes, and want to make an immutable or paginated version see `\JPI\Utils\Collection\ImmutableTrait` and `\JPI\Utils\Collection\PaginatedTrait`.

Support
-------

[](#support)

If you found this library interesting or useful please spread the word about this library: share on your socials, star on GitHub, etc.

If you find any issues or have any feature requests, you can open an [issue](https://github.com/jahidulpabelislam/utils/issues) or email [me @ jahidulpabelislam.com](mailto:me@jahidulpabelislam.com) 😏.

Authors
-------

[](#authors)

- [Jahidul Pabel Islam](https://jahidulpabelislam.com/) [](mailto:me@jahidulpabelislam.com)

Licence
-------

[](#licence)

This module is licensed under the General Public Licence - see the [licence](LICENSE.md) file for details.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance82

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 99.2% 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 ~48 days

Recently: every ~21 days

Total

27

Last Release

92d ago

Major Versions

v0.9.4 → v1.0.02024-05-03

PHP version history (4 changes)v0.1.0PHP ^7.0

v0.3.0PHP ^7.1

v0.3.1PHP ^7.1 || ^8.0

v0.7.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3eb53275639d93b5fdae3b835527fdb958dbc1214e58a97d10fa50fe66a836cd?d=identicon)[jahidulpabelislam](/maintainers/jahidulpabelislam)

---

Top Contributors

[![jahidulpabelislam](https://avatars.githubusercontent.com/u/15434150?v=4)](https://github.com/jahidulpabelislam "jahidulpabelislam (132 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

---

Tags

helpersphputilitiesurlutilityhelperscollectionutilitiessingleton

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jpi-utils/health.svg)

```
[![Health](https://phpackages.com/badges/jpi-utils/health.svg)](https://phpackages.com/packages/jpi-utils)
```

###  Alternatives

[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[brandonwamboldt/utilphp

util.php is a collection of useful functions and snippets that you need or could use every day, designed to avoid conflicts with existing projects

1.0k538.8k12](/packages/brandonwamboldt-utilphp)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8321.5M36](/packages/jbzoo-utils)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)

PHPackages © 2026

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