PHPackages                             simon-downes/spl - 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. simon-downes/spl

ActiveLibrary

simon-downes/spl
================

Simon's PHP Library

0113PHP

Since Mar 23Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/simon-downes/spl)[ Packagist](https://packagist.org/packages/simon-downes/spl)[ RSS](/packages/simon-downes-spl/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Simon's PHP/Prototyping Library
===============================

[](#simons-phpprototyping-library)

What
----

[](#what)

My collection of utility classes for prototyping PHP 8+ apps.

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE.md)

Why
---

[](#why)

Sometimes I just wanna get shit done in the old school hacky way - quick, dirty and fun.

I don't need massive libraries that cover every possibly scenario or use case, just something simple that's Good Enough.

Plus, I like tinkering with code, so get off my lawn! 🤣

How
---

[](#how)

You probably shouldn't, it's almost certainly various degrees broken for all sorts of cases (that I don't care about, yet) 🤣

```
composer require simon-downes/spl

```

Overview
--------

[](#overview)

### General

[](#general)

**The following constants are defined automatically:**

- `SPL_CLI` - true if running in a CLI environment, false otherwise
- `SPL_REQUEST_ID` - a random 8-character hex string
- `SPL_START_TIME` - time that the request started, or (if not available) when the autoloader was called

**Initialise the framework for a particular directory and load a `.env` file if it exists:**

```
SPL::init(directory: getcwd(), load_env: true );
```

> This will set the `SPL_ROOT` and `SPL_DEBUG` constants. `SPL_DEBUG` is set based on:
>
> - the value in the `APP_DEBUG` environment variable
> - the value of the `APP_ENV` environment variable (false for production, true for others)
> - false if set to anything other than true, false or an empty string

**Output debug representations of variables:**

```
    // dump and continue
    d($my_var, $my_other_var, ...);

    // dump and die after...
    dd($my_var, $my_other_var, ...);
```

The above commands will only output something if `SPL_DEBUG` is set to `true`.

When calling `dd()` in non-CLI contexts a `text/plain` content-type header will be sent if no headers have yet been sent.

**Get the value of an environment variable (or a default):**

```
    env("MY_ENV_VAR_NAME", "Default Value");
```

**Show an error message/page:**

```
SPL::error($exception);
```

For CLI output, a stack trace is shown.

For web output, a debug page is shown if `SPL_DEBUG` is `true`, otherwise a generic `503` error page is shown. A stack trace is also logged (see Logging below).

### Command Line Interface (CLI)

[](#command-line-interface-cli)

**Parse command line arguments:**

```
// Assuming $argv = ['script.php', '-a', '--foo-bar', '-x=value', '--option=value']
$options = CLI::parseArgs($argv);
// $options = ['a' => true, 'foo-bar' => true, 'x' => 'value', 'option' => 'value']

// Check if an option exists
if (CLI::hasOption('a')) {
    // Do something
}

// Get an option value with a default
$value = CLI::getOption('option', 'default');

// Get all positional arguments (non-option arguments)
$args = CLI::getArgs();
```

**Output formatted text:**

```
// Print without newline
CLI::print("Hello [green]World[reset]!");

// Print with newline
CLI::println("This is [bold][blue]blue and bold[reset] text.");

// Available formatting tokens:
// Colors: [black], [red], [green], [yellow], [blue], [magenta], [cyan], [white]
// Bright colors: [bright_black], [bright_red], [bright_green], etc.
// Background colors: [bg_black], [bg_red], [bg_green], etc.
// Background bright colors: [bg_bright_black], [bg_bright_red], etc.
// Styles: [bold], [dim], [italic], [underline], [blink], [reverse], [hidden]
// Reset: [reset]
```

**Get user input:**

```
// Basic prompt
$name = CLI::prompt("Enter your name");

// Prompt with default value
$path = CLI::prompt("Enter path", "/var/www");

// Yes/no confirmation
if (CLI::confirm("Are you sure?", true)) {
    // User confirmed
}

// Selection from options
$choice = CLI::select("Choose a color", [
    'r' => 'Red',
    'g' => 'Green',
    'b' => 'Blue',
], 'g');
```

**Create a CLI application with commands:**

```
// In config/commands.php
return [
    'hello' => function($options, $args) {
        $name = $args[0] ?? 'World';
        CLI::println("[green]Hello, {$name}![reset]");
    },
    'help' => function($options, $args) {
        CLI::println("Available commands:");
        CLI::println("  hello [name] - Say hello to someone");
        CLI::println("  help - Show this help message");
    },
];

// In your entry script (e.g., cli.php)
SPL::run(getcwd());

// Run with: php cli.php hello Simon
```

### Database

[](#database)

### Logging

[](#logging)

**The following levels are supported:**

- `DEBUG`
- `INFO`
- `WARNING`
- `ERROR`
- `CRITICAL`

**Log a message to a file:**

```
Log::message(message: "Hello World", level: "INFO", file: = '' );
```

Will output the message in this format:

```
Date Time Request-ID [LEVEL] Message
2023-07-13 17:38:10 deee16e2 [INFO] Hello World

```

`file` can be:

- `php` - send output to `error_log()`
- a filename
- an empty string - use the value of `env('APP_LOG_FILE')`, with fallback to `php`

**Convenience methods:**

```
Log::debug(message: "", file: "");
Log::info(message: "", file: "");
Log::warning(message: "", file: "");
Log::error(message: "", file: "");
Log::critical(message: "", file: "");
```

### HTTP Requests

[](#http-requests)

`TODO`

### Random Data

[](#random-data)

**Generate some random data:**

```
Random::hex(length: 40);
Random::string(length: 10 , allowed = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
```

Strings
-------

[](#strings)

`TODO`

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance54

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed0f7e8dc7c113e752674163bb779ca54730aa1533f9444d00f88940b52916a8?d=identicon)[simon-downes](/maintainers/simon-downes)

---

Top Contributors

[![simon-downes](https://avatars.githubusercontent.com/u/1052903?v=4)](https://github.com/simon-downes "simon-downes (13 commits)")

### Embed Badge

![Health badge](/badges/simon-downes-spl/health.svg)

```
[![Health](https://phpackages.com/badges/simon-downes-spl/health.svg)](https://phpackages.com/packages/simon-downes-spl)
```

PHPackages © 2026

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