PHPackages                             koriym/loop - 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. koriym/loop

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

koriym/loop
===========

Converts iterable data sets (e.g., database results, CSV files) into an entity list generator with loop context (isFirst, isLast, index, iteration).

1.0.0(1y ago)716.4k↑90.7%1MITPHPPHP ^7.2 || ^8.0CI failing

Since Jan 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/koriym/Koriym.Loop)[ Packagist](https://packagist.org/packages/koriym/loop)[ RSS](/packages/koriym-loop/feed)WikiDiscussions master Synced 1mo ago

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

Koriym.Loop
===========

[](#koriymloop)

[![codecov](https://camo.githubusercontent.com/448022e2bf78d23220c5ee1a816f962b5fc8e2d6e1652b19ed827b34086b8fa2/68747470733a2f2f636f6465636f762e696f2f67682f6b6f7269796d2f4b6f7269796d2e4c6f6f702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d65683363394146344d72)](https://codecov.io/gh/koriym/Koriym.Loop)[![Type Coverage](https://camo.githubusercontent.com/40c26f4a7b5d5b9e44fb80c1cc946653d71c69eb04ce8881869f2d784bdaf685/68747470733a2f2f73686570686572642e6465762f6769746875622f6b6f7269796d2f4b6f7269796d2e4c6f6f702f636f7665726167652e737667)](https://shepherd.dev/github/koriym/Koriym.Loop)[![Continuous Integration](https://github.com/koriym/Koriym.Loop/workflows/Continuous%20Integration/badge.svg)](https://github.com/koriym/Koriym.Loop/workflows/Continuous%20Integration/badge.svg)

Koriym.Loop is a PHP library that converts various iterable data sets, such as database result sets, CSV files, or any other iterable structures, into an entity list generator. This makes it easy to use in views by providing looping information such as isFirst, isLast, index, and iteration, similar to the loop processing found in template engines like Twig.

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

[](#installation)

```
composer require koriym/loop
```

Usage
-----

[](#usage)

Basic Example
-------------

[](#basic-example)

The following example demonstrates how to use Koriym.Loop with a simple User class and a result set:

```
class User
{
    public function __construct(
        public readonly int $id,
        public readonly string $name
    ){}
}

// Database result sets or csv content
$resultSet = [
    ['id' => 1, 'name' => 'ray'],
    ['id' => 2, 'name' => 'bear'],
    ['id' => 3, 'name' => 'alps'],
];

/** @var Generator $users */
$users = (new LoopGen)($resultSet, User::class);
foreach ($users as $user) {
    echo $user->name;
}
```

### Loop information

[](#loop-information)

Loop information can be accessed from the array keys, providing details such as whether the current item is the first or last in the list:

```
/** @var Loop $loop */
foreach ($users as $loop => $user) {
    echo match(true) {
        $loop->isFirst && $loop->isLast => "{$user->name}",
        $loop->isFirst => "{$user->name}",
        $loop->isLast => "{$user->name}",
        default => "{$user->name}"
    };
}
```

### Loop Properties

[](#loop-properties)

propertytypeDescriptionisFirstboolIs first on the list?isLastboolIs last on the list?indexintLoop count of 0 originiterationintLoop count of 1 originInjection
---------

[](#injection)

Dependent instances can be injected into the entity by specifying them as the third argument. Specify the key as the name of the parameter and the value as the instance.

```
$dependencies = [
    $varName => $insntance,
    'dateTime' => new DateTime(), // DateTime instance is injected
];
$users = (new LoopGen)($resultSet, User::class, $dependencies);
```

Iterator Support
----------------

[](#iterator-support)

Koriym.Loop supports iterators as well as arrays. Here's an example using a CSV iterator:

```
class Row
{
    public function __construct(
        public readonly int $id,
        public readonly string $name
    ){}
}

// Retrieve contents of csv file as list
$csvIterator = new ogrrd\CsvIterator\CsvIterator($csvFilePath);
/** @var list $csvRowList */
$csvRowList = (new LoopGen)($csvIterator, Row::class);

foreach ($csvRowList as $loop => $row) {
    if ($loop->isFirst) {
        continue; // Skip header
    }
    echo $row->name;
}
```

This library provides a flexible and convenient way to handle looping through result sets and other iterable data structures in PHP, with additional context information about the loop's state.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.1% 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

709d ago

### Community

Maintainers

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

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (52 commits)")[![kenjis](https://avatars.githubusercontent.com/u/87955?v=4)](https://github.com/kenjis "kenjis (1 commits)")

---

Tags

entitygeneratorphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/koriym-loop/health.svg)

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

###  Alternatives

[doublesecretagency/craft-siteswitcher

Easily switch between sites on any page of your website.

6688.1k](/packages/doublesecretagency-craft-siteswitcher)[jomweb/ringgit

Malaysia Ringgit implementation on top of Money PHP

30182.3k1](/packages/jomweb-ringgit)

PHPackages © 2026

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