arraypress/wp-slurp

Include every PHP file in a directory, in a fixed order.

Maintainers

Package info

github.com/arraypress/wp-slurp

Homepage

pkg:composer/arraypress/wp-slurp

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-08-26 08:55 UTC

This package is auto-updated.

Last update: 2026-08-26 08:55:21 UTC


README

Include every PHP file in a directory, in a fixed order.

What it does

A plugin that grows past a handful of files ends up with a bootstrap listing every one of them by hand, and a merge conflict every time two people add a class. This replaces that list with the directory it lives in.

The ordering is the point. DirectoryIterator and glob( ..., GLOB_NOSORT ) hand back whatever the filesystem holds — creation order on APFS, hashed elsewhere — so a class extending another in the same folder loads cleanly on your machine and fatals on the server. Files here are always loaded in name order, which is something you control.

Features

  • Load every PHP file in a directory, sorted by name
  • Load several directories in the order you list them
  • Recurse into subdirectories, each still sorted
  • Skips the index.php silence stubs
  • Returns the paths it loaded, so a bootstrap can be asserted on
  • Reports what a directory would load without loading it
  • A directory that is not there is skipped, not fatal

Installation

composer require arraypress/wp-slurp

Quick start

use ArrayPress\Slurp\Slurp;

// One directory.
Slurp::dir( PLUGIN_DIR . 'includes/utils' );

// Several, in the order they have to load.
Slurp::dirs( [
    PLUGIN_DIR . 'includes/database/schemas',
    PLUGIN_DIR . 'includes/database/tables',
    PLUGIN_DIR . 'includes/database/queries',
] );

Prefix filenames to pin order within a directory — 10-base.php, 20-extends-base.php. Sorting is by string, so numbers need padding.

A note on side effects

Files are require_onced, so anything at file scope runs the moment you call this. Declare your classes and functions in these files and hook from a bootstrap that runs afterwards, or load order becomes hook order.

Requirements

  • PHP 8.3 or later

License

GPL-2.0-or-later