PHPackages                             toolkit/stdlib - 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. toolkit/stdlib

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

toolkit/stdlib
==============

some stdlib tool library of the php

v2.0.14(11mo ago)9105.3k↓68.9%17MITPHPPHP &gt;=8.1CI passing

Since Jun 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/php-toolkit/stdlib)[ Packagist](https://packagist.org/packages/toolkit/stdlib)[ Docs](https://github.com/php-toolkit/stdlib)[ RSS](/packages/toolkit-stdlib/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (49)Used By (7)

StdLib
======

[](#stdlib)

[![License](https://camo.githubusercontent.com/5fc1422a04274b8c4ffb842e5c608e64a40388365309b55f49c41d47301e855f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068702d746f6f6c6b69742f7374646c6962)](LICENSE)[![Php Version Support](https://camo.githubusercontent.com/9a4e577ca4463846abe38d23105010d0a382a05ccb7ca5bcc5a448f6977c6a4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6f6c6b69742f7374646c6962)](https://packagist.org/packages/toolkit/stdlib)[![Latest Stable Version](https://camo.githubusercontent.com/837ec5cfce35cc110d8b6677f139d1e9d6adffd308d444e126d805b4d8b756dd/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6f6c6b69742f7374646c69622e737667)](https://packagist.org/packages/toolkit/stdlib)[![Unit Tests](https://github.com/php-toolkit/stdlib/actions/workflows/php.yml/badge.svg)](https://github.com/php-toolkit/stdlib/actions)[![Docs on pages](https://camo.githubusercontent.com/099ae6a7d29c2c4a3b8370c1b3d8f52f92a760d19e31b82c3ac535db861133cd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f63734f6e2d50616765732d627269676874677265656e2e7376673f6d61784167653d32353932303030)](https://php-toolkit.github.io/stdlib/)

🧰 Stdlib - Useful basic tools library for PHP development.

**Contains**:

- array, string, number, object helper
- common php, OS env information

**More Utils**

- `PhpDotEnv` Dotenv(`.env`) file load
- `AutoLoader` Simple autoloader
- `ObjectBox` simple object container
- `Optional` like java `java.util.Optional`
- and more ...

Install
-------

[](#install)

```
composer require toolkit/stdlib
```

String helper
-------------

[](#string-helper)

### StrBuffer

[](#strbuffer)

```
use Toolkit\Stdlib\Str\StrBuffer;

$buf = StrBuffer::new("c");
$buf->prepend('ab')
$buf->append('de')

$str = (string)$buf; // "abcde"
$str = $buf->toString(); // "abcde"
// get and clean.
$str = $buf->fetch(); // "abcde"
$str = $buf->join(','); // "ab,c,de"
```

Object helper
-------------

[](#object-helper)

### Object box

[](#object-box)

`ObjectBox` - Simple object container.

```
use Toolkit\Stdlib\Obj\ObjectBox;

$box = ObjectBox::global();

// set
$box->set('router', function () {
    return new MyRouter();
});

$box->set('renderer', [
    'class' => MyRenderer::class,
    'tplDir' => 'path/to/dir',
]);

// with options for create
$box->set('somObj', [
    'class' => MyObject::class,
    '__opt' => [
        // will always create new object.
        'objType' => ObjectBox::TYPE_PROTOTYPE,
    ],
]);

// get
/** @var MyRouter $router */
$router = $box->get('router');
/** @var MyRenderer $renderer */
$renderer = $box->get('renderer');
```

Util classes
------------

[](#util-classes)

### AutoLoader

[](#autoloader)

`AutoLoader` - an simple psr4 loader, can use for tests.

```
AutoLoader::addFiles([
    // alone files
]);

$loader = AutoLoader::getLoader();
$loader->addPsr4Map([
    'namespace' => 'path'
]);

$loader->addClassMap([
 'name' => 'class file'
]);
```

### Optional

[](#optional)

It aims to eliminate excessive if judgments.

Not use Optional:

```
use Toolkit\Stdlib\Util\Optional;

$userModel = UserModel::findOne(23);

if ($userModel) {
    $username = $userModel->name;
} else {
    $username = 'unknown';
}
```

Use Optional:

```
use Toolkit\Stdlib\Util\Optional;

$username = Optional::ofNullable($userModel)
    ->map(function ($userModel) {
        return $userModel->name;
    })->orElse('unknown');
```

Use arrow syntax:

```
use Toolkit\Stdlib\Util\Optional;

$username = Optional::ofNullable($userModel)
    ->map(fn($userModel) => $userModel->name)
    ->orElse('unknown');
```

### PhpDotEnv

[](#phpdotenv)

`PhpDotEnv` - a simple dont env file loader.

The env config file `.env` (must is 'ini' format):

```
APP_ENV=dev
DEBUG=true
; ... ...
```

Usage:

```
PhpDotEnv::load(__DIR__, '.env');

env('DEBUG', false);
env('APP_ENV', 'prod');
```

### Stream

[](#stream)

```
use Toolkit\Stdlib\Util\Stream\DataStream;
use Toolkit\Stdlib\Util\Stream\ListStream;

$userList = ListStream::of($userModels)
    ->filter(fn($userModel) => $userModel->age > 20) // only need age > 20
    ->map(function ($userModel) {
        // only need field: age, name
        return [
            'age'  => $userModel->age,
            'name' => $userModel->name,
        ];
    })
    ->toArray();

vdump($userList);
```

### PipeFilters

[](#pipefilters)

```
$pf = PipeFilters::newWithDefaultFilters();

$val = $pf->applyString('inhere', 'upper'); // 'INHERE'
$val = $pf->applyString('inhere', 'upper|substr:0,3'); // 'INH'
```

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance66

Regular maintenance activity

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% 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 ~37 days

Recently: every ~207 days

Total

48

Last Release

337d ago

Major Versions

v0.0.1 → v1.0.02020-06-11

v1.1.4 → v2.0.02021-11-30

1.x-dev → v2.0.22021-12-04

PHP version history (3 changes)v0.0.1PHP &gt;7.1.0

v2.0.0PHP &gt;=8.0

v2.0.13PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (199 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

dotenvenvironmentoptionalphpphp-arrayphp-libraryphp-stringsstdlibphparraystringlibrarytoolobject

### Embed Badge

![Health badge](/badges/toolkit-stdlib/health.svg)

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

###  Alternatives

[michaldudek/foundation

A set of useful PHP classes.

13111.6k12](/packages/michaldudek-foundation)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2515.8k](/packages/iteks-laravel-enum)

PHPackages © 2026

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