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

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

elegantmedia/php-toolkit
========================

Utility and helper toolkit based on PHP best practises. No dependencies.

v2.0.0(1y ago)012.5k↑65.5%11MITPHPPHP ^7.4 || ^8.0CI passing

Since Sep 21Pushed 1y ago2 watchersCompare

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

READMEChangelog (8)Dependencies (3)Versions (11)Used By (1)

PHP Toolkit - Utility and Helper Library for Business Applications
==================================================================

[](#php-toolkit---utility-and-helper-library-for-business-applications)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cfa55ea3b371155844f9287e1b5d963d92ff9b269e7b3e6cf509d5d49e67ffc3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6567616e746d656469612f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elegantmedia/php-toolkit)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/e95b24f91e19638df8fff03634307846cbcb303f569dcf3a74a039d4d80559f8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f656c6567616e746d656469612f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/elegantmedia/php-toolkit)[![Build Status](https://camo.githubusercontent.com/22e88631016058bececdd10cf5b902f31d67b96d776e72432cec7fc944303255/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f656c6567616e746d656469612f7068702d746f6f6c6b69742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/elegantmedia/php-toolkit)[![Coverage Status](https://camo.githubusercontent.com/1245bada52cd8776e2c64360a080a390fa856dcb9e1b6eaa367e11b58c1726ea/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f656c6567616e746d656469612f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/elegantmedia/php-toolkit/code-structure)

This library holds commonly used helper functions used in many business applications. All features used PHP's native APIs and there are no third party dependencies.

### Installation

[](#installation)

Install via composer

```
composer require elegantmedia/php-toolkit

```

### Available Commands

[](#available-commands)

#### Array Helpers

[](#array-helpers)

```
use \ElegantMedia\PHPToolkit\Arr;

// Check if an array is an associative array
Arr::isAssoc($array);

// get matching subset of array. Similar to `array_intersect`, but does recursively.
Arr::intersectRecursive($source, $subset);

// Implode, but exclude empty values
Arr::implodeIgnoreEmpty($glue, $array);

// Sway a key on an associative array
Arr::swapKey($array, $oldKey, $newKey, $recursive = false);

// Key values of an array to another key
Arr::keyBy($array, $key);
```

#### Conversions

[](#conversions)

```
use \ElegantMedia\PHPToolkit\Conversion;

// Convert bytes to a human readble format
// Example output: '200 KB', '1 MB', '3 TB' etc
Conversion::bytesToHumans($bytes, $precision = 2);

// Converts a string with numbers to a full number
// Example: 1,232.12 -> becomes -> (int) 1232
Conversion::stringToInt($string);

// Convert a string numeric to a float
// Example: 1,232.12 -> becomes -> (float) 1232.12
Conversion::stringToFloat($value);
```

#### Directory Handling

[](#directory-handling)

```
use \ElegantMedia\PHPToolkit\Dir;

// Create a directory if it doesn't exist
Dir::makeDirectoryIfNotExists($dirPath, $permissions = 0775, $recursive = true);

// Delete a directory
Dir::deleteDirectory($dirPath);

// Delete files in a directory by extension
Dir::cleanDirectoryByWildcard('/my-dir-path/', 'txt');

// Delete files in a directory by (glob) wildcard
Dir::cleanDirectoryByWildcard('/my-dir-path/', '*.txt');
```

#### File Editor

[](#file-editor)

```
use \ElegantMedia\PHPToolkit\FileEditor;

// Append a stub to a file, identified by the unique first line
FileEditor::appendStubIfSectionNotFound($filePath, $stubPath)

// Append a stub to a file
FileEditor::appendStub($filePath, $stubPath, $verifyPathsExists = true)

// Check if a string is in file
FileEditor::isTextInFile($filePath, $string, $caseSensitive = true)

// Find and replace text in a file
$bytes = FileEditor::findAndReplace($filePath, $search, $replace)

// Find and replace text in a file by regex
$text = FileEditor::findAndReplaceRegEx($filePath, $searchRegEx, $replaceRegEx)

// Check if two files are similar (by size and hash)
FileEditor::areFilesSimilar($path1, $path2)

// Read the first line from a file
FileEditor::readFirstLine($filePath, $trim = true);

// Get the classname and namespace from a while (by reading the file)
FileEditor::getClassname('/my-path/file.php');
```

#### Loader

[](#loader)

```
use \ElegantMedia\PHPToolkit\Loader;

// Include all php files from a given directory
Loader::includeAllFilesFromDir($dirPath);

// Include all files recursively
Loader::includeAllFilesFromDirRecursive($dirPath);
```

#### Path

[](#path)

```
use \ElegantMedia\PHPToolkit\Path;

Path::withEndingSlash($path);
Path::withStartingSlash($path);
Path::withoutEndingSlash($path);
Path::withoutStartingSlash($path);

// remove dot segments from paths
// Example: Convert `/folder1/folder2/./../folder3` to `/folder1/folder3`
Path::canonical($path);
```

#### Reflector

[](#reflector)

```
use ElegantMedia\PHPToolkit\Reflector;

// Get an inherited class' directory path
Reflector::classPath($object, $pathSuffix = null);
```

#### Text

[](#text)

```
use \ElegantMedia\PHPToolkit\Text;

// Convert a block of text and split it into lines
/*
Example:
one, two,   three
four
five

Returns:
['one', 'two', 'three', 'four', 'five']
*/
Text::textToArray($text, $delimiters = null);

// Convert an 'existing_snake_case' to 'existing snake case'
Text::reverseSnake($string);

// Generate a random string without any ambiguous characters
// So it'll be easier to spell or read. For example, `AIilO01` will not be generated.
Text::randomUnambiguous($length = 16)
```

#### Timing

[](#timing)

```
use \ElegantMedia\PHPToolkit\Timing;

// Get formatted microtimestamp. Example: `2008_07_14_010813.98232`
Timing::microTimestamp()
```

### Global Functions

[](#global-functions)

#### Validation

[](#validation)

```
// Check all values are !empty. Throws an exception if at least one value is empty
// if APP_DEBUG=true ENV variable is set, you'll be able to see which variable was missing
validate_all_present();

// Example: validate_all_present($var1, $var2, $var5)
```

Development Setup
-----------------

[](#development-setup)

### Running Tests Locally

[](#running-tests-locally)

Run the test suite:

```
composer test
```

### Code Quality Tools

[](#code-quality-tools)

This project uses GitHub Actions for CI/CD instead of external services. You can run the same checks locally:

#### Code Style Fixing

[](#code-style-fixing)

Fix code style issues automatically:

```
# Install PHP CS Fixer globally (first time only)
composer global require friendsofphp/php-cs-fixer

# Run the fixer
php-cs-fixer fix --config=.php-cs-fixer.php
```

Check for style issues without fixing:

```
php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php
```

#### Static Analysis

[](#static-analysis)

Run PHPStan for static analysis:

```
# Install PHPStan (included in composer dev dependencies)
composer install

# Run analysis
vendor/bin/phpstan analyse
```

#### Code Coverage

[](#code-coverage)

Generate code coverage report:

```
# Run tests with coverage (requires Xdebug)
vendor/bin/phpunit --coverage-html coverage/

# View the report
open coverage/index.html
```

### GitHub Actions CI

[](#github-actions-ci)

The project includes GitHub Actions workflows that automatically:

- Run tests on multiple PHP versions (7.3, 7.4, 8.0, 8.1, 8.2)
- Check and fix code style issues
- Perform static analysis with PHPStan
- Generate and upload code coverage reports to Codecov

These checks run on every push and pull request to the `master` or `main` branches.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Copyright (c) 2025 Elegant Media.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance47

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~427 days

Total

9

Last Release

390d ago

Major Versions

v0.1.3 → v1.0.42020-10-04

v1.0.7 → v2.0.02025-06-09

PHP version history (2 changes)v0.1.0PHP &gt;=7.2.0

v2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![shanecp](https://avatars.githubusercontent.com/u/1654017?v=4)](https://github.com/shanecp "shanecp (10 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[afarkas/html5shiv

Defacto way to enable use of HTML5 sectioning elements in legacy Internet Explorer.

9.8k579.8k14](/packages/afarkas-html5shiv)

PHPackages © 2026

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