PHPackages                             ock/class-files-iterator - 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. ock/class-files-iterator

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

ock/class-files-iterator
========================

1.x-dev(1y ago)0742MITPHPPHP &gt;=8.3CI failing

Since Apr 27Pushed 11mo agoCompare

[ Source](https://github.com/ock-php/class-files-iterator)[ Packagist](https://packagist.org/packages/ock/class-files-iterator)[ RSS](/packages/ock-class-files-iterator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (14)Used By (2)

Class files iterator
====================

[](#class-files-iterator)

This package provides IteratorAggregate implementations to iterate through class files.

Main concepts:

- [`ClassFilesIA*`](src/ClassFilesIA/ClassFilesIAInterface.php):
    IteratorAggregate that lists class names keyed by their file names.
    - [`NamespaceDirectory`](src/NamespaceDirectory.php):
        Main implementation representing a PSR-4 class files directory.
        It provides additional methods to navigate to parent or child directories.
- [`ClassNamesIA*`](src/ClassNamesIA/ClassNamesIAInterface.php)
    IteratorAggregate that lists class names by numeric keys.
    This can be used if the file path is not relevant.

Benefits
--------

[](#benefits)

There are other packages which attempt to solve the same problem in different ways.

The benefits of this package are:

- Predictable (alphabetic) order of class files.
    This is thanks to internal usage of `scandir()` with sort flag, instead of directory iterators.
- The "iterators" are stateless/immutable, and can be passed around as value objects.
    This is thanks to them extending `IteratorAggregate` instead of `Iterator`.
- Code that needs a list of classes or class files can simply depend on the interfaces, and does not need to deal with directories.

Limitations
-----------

[](#limitations)

Iterators for reflection classes are not part of this package.

Usage
-----

[](#usage)

```
use Ock\ClassFilesIterator\ClassFilesIA\ClassFilesIAInterface;
use Ock\ClassFilesIterator\ClassNamesIA\ClassNamesIAInterface;
use Ock\ClassFilesIterator\NamespaceDirectory;
use Ock\ClassFilesIterator\Tests\Fixtures\Acme\Plant\VenusFlyTrap;

// Basic creation for a PSR-4 directory.
$basic_namespace_dir = NamespaceDirectory::create($basedir . '/src', 'Acme\\Foo');

// Convenient creation with a "seed" class.
// The directory is determined automatically with ReflectionClass::getFileName().
$namespace_dir = NamespaceDirectory::fromClass(VenusFlyTrap::class);

// Iterate class names by integer key.
function foo(ClassNamesIAInterface $classNamesIA): void {
  foreach ($classNamesIA as $class) {
    assert(class_exists($class));
  }
}

// Iterate class names with file path as key.
function foo(ClassFilesIAInterface $classNamesIA): void {
  foreach ($classNamesIA as $file => $class) {
    assert(file_exists($file));
    assert(class_exists($class));
  }
}

// Get reflection classes.
function foo(ClassFilesIAInterface $classFilesIA): void {
  foreach ($classFilesIA as $file => $class) {
    try {
      $rc = new \ReflectionClass($class);
    }
    catch (\ReflectionException|\Error) {
      // Skip non-existing classes / interfaces / traits.
      // Skip if a base class or interface is missing.
      // Unfortunately, missing traits still cause fatal error.
      continue;
    }
    // Ignore if the class is defined elsewhere.
    if ($rc->getFileName() !== $file && realpath($rc->getFileName()) !== realpath($file)) {
      continue;
    }
    do_something($rc);
  }
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

387d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150032?v=4)[Andreas Hennings](/maintainers/donquixote)[@donquixote](https://github.com/donquixote)

---

Top Contributors

[![donquixote](https://avatars.githubusercontent.com/u/150032?v=4)](https://github.com/donquixote "donquixote (38 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ock-class-files-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/ock-class-files-iterator/health.svg)](https://phpackages.com/packages/ock-class-files-iterator)
```

###  Alternatives

[dachcom-digital/schema

Pimcore Schema

1075.7k](/packages/dachcom-digital-schema)

PHPackages © 2026

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