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

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

endrilala/utils
===============

Generic utilities for application development

1.0(9mo ago)00MITPHP

Since Aug 11Pushed 9mo agoCompare

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

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

Utils
=====

[](#utils)

Generic utility classes for application development

[![Travis](https://camo.githubusercontent.com/0b814ce0a2cd0cd1a6b5ac16eef2169a5ba598e01504ebd00851cbf4cdba7378/68747470733a2f2f6170692e7472617669732d63692e6f72672f656e6472696c616c612f7574696c732e737667)](https://travis-ci.org/endrilala/utils)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7defee02e65283d2a29feda80d9b200d303aee224f155bd6b7646c72dc878506/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656e6472696c616c612f7574696c732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/endrilala/utils/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/fc200d3059d469188329d1eac097cd9f8d9666aa1011d12374637cdcb878f942/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656e6472696c616c612f7574696c732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/endrilala/utils/?branch=master)

Installation
============

[](#installation)

This library requires PHP 5.3 or later. It is available and downloadable as a custom repository through composer.

Classes
=======

[](#classes)

---

### Pagination

[](#pagination)

Provides easy generation of pagination content for large datasets.

```
$pagination = new Pagination($total_rows, $rows_per_page, $current_page, $visible_pages);

$pagination_html = $pagination->getHTML(function ($page, $label) {
    return sprintf("", $page, $label);
});

// somewhere in your favourite templating engine

 {{ pagination_html }}
```

---

### SimplePagination

[](#simplepagination)

Simplifies the pagination class even further. Constructor accepts 3 arguments

`total_rows`, `current_page`, and `pagination_url` which serves as a formatting string to replace page numbers into. Place a `%d` symbol at the place where you want your page number to be put. The generated HTML is Bootstrap-ready.

```
$pagination_html = new SimplePagination($total_rows, $current_page, "users/list?p=%d");
```

That was too easy now, was it?

---

### Cart

[](#cart)

Allows management of a shopping cart (no way!)

##### Add an item to the cart

[](#add-an-item-to-the-cart)

The add method returns a unique string which can be used to access this specific item in the future. The data property is meant to be used as a means to store any information related to the added item.

```
$rowid = $cart->add(new CartItem('SKU', 10 /* price */, 15 /* quantity */));
```

##### Remove an item from the cart

[](#remove-an-item-from-the-cart)

This will remove an item from the cart variable.

```
$cart->remove($rowid);
```

##### Update an item

[](#update-an-item)

To update an item, simply change it's properties.

```

##### Get an item from the shopping cart

```php
$item = $cart->get($rowid);

```

`$item` variable is of the `CartItem` type and it supports the following properties:

- rowId - *denotes the rowid assigned to it by the parent `Cart` class*
- identifier
- quantity
- price
- data

###### Nb: The `update`, `remove` and `get` methods will throw an `ItemNotFoundException` in case the specified rowid is not found. If you want to safely check the existence of a rowid use the `has` method

[](#nb-the-update-remove-and-get-methods-will-throw-an-itemnotfoundexception-in-case-the-specified-rowid-is-not-found-if-you-want-to-safely-check-the-existence-of-a-rowid-use-the-has-method)

---

### PersistentCart

[](#persistentcart)

All of the above is nice and all but sort of not useful if you can't persist the data across requests. To our rescue comes the `CartPersistentInterface` interface, which is passed to the `PersistentCart` class constructor.

Out of the box the following persistence methods are supported

- Session based storage via the `SessionPersistenceStrategy` class
- File based sessions via the `FilePersistenceStrategy` class

You can implement your own storage mechanisms by implementing the persistence interface and passing the class to the `Cart` constructor. To persist data after updating an item the method `save` must be manually invoked.

```
// session based persistence
$cart = new PersistentCart(new SessionPersistenceStrategy(new SessionManager(...), 'shopping_cart');

// file based
$cart = new PersistentCart(new FilePersistenceStrategy("temp/sessions/" . $user_id));
```

---

### Session Management

[](#session-management)

The default cookie-based sessions tend to be a mess when multiple applications hosted on the same domain try and access the same keys ending up overwriting each-other's data. This problem is solved by the `SessionManager` class.

```
$session = new SessionManager($_SESSION, 'some_unique_session_key');
```

The session manager supports the following methods

- `get($key, $default = null)` - get an item
- `set($key, $value)` - set an item
- `forget($key)` - remove an item
- `pull($key, $default = null)` - get an item and remove it
- `flush` - clear all stored data
- `all` - get all the stored data
- `has($key)` - check existence

All the methods support the dot(`.`) character as a separator which allows reading/writing to multi-dimensional arrays.

```
$session->set('user.name', 'endrilala'); // ['user' => ['name' => 'endrilala']]

/* session data

array(
    'user' => [
        'role' => [
            'id'   => 1,
            'name' => 'Developers'
        ],
        'name' => 'endrilala'
    ]
);
*/
$name = $session->get('user.name'); // endrilala
$role_name = $session->get('user.role.name'); // Developers
```

---

If of course you do not want to use the actual session for this, but would rather have database based, file based or whatever based sessions, really - you could implement `SessionManagementInterface` and then simply create an instance of your class rather than a `SessionManager` which should mean that your application works with just this change. Preferably you want to use a singleton pattern alongside this to make sure that you only have to replace one line in the whole application.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance62

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

271d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c83cf7b6bd6f2be9d5b77d0472913d9e90b47829c4763497663ca91da8f1e362?d=identicon)[endrilala](/maintainers/endrilala)

---

Top Contributors

[![endrilala](https://avatars.githubusercontent.com/u/6499290?v=4)](https://github.com/endrilala "endrilala (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[vmwarephp/vmwarephp

Vmware vSphere bindings for PHP

7818.8k](/packages/vmwarephp-vmwarephp)[orrison/cumulus

Import DNS records from Laravel Vapor into Cloudflare

3817.1k](/packages/orrison-cumulus)[friends-of-hyva/magento2-crawler-session

Prevent crawlers from creating a session

155.8k](/packages/friends-of-hyva-magento2-crawler-session)

PHPackages © 2026

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