PHPackages                             entropyphp/utils - 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. entropyphp/utils

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

entropyphp/utils
================

Utility classes for PHP

0.1.5(9mo ago)01782MITPHPPHP ^8.2 || ^8.3 || ^8.4CI passing

Since Jul 29Pushed 9mo agoCompare

[ Source](https://github.com/Entropyphp/utils)[ Packagist](https://packagist.org/packages/entropyphp/utils)[ RSS](/packages/entropyphp-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (7)Used By (2)

Utils
=====

[](#utils)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://php.net)[![Coverage Status](https://camo.githubusercontent.com/a689be3092680e81bd592cc78b05415a7d5b16e1f5b8257b1331d897405cc9ca/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f456e74726f70797068702f7574696c732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/Entropyphp/utils?branch=main)[![Continuous Integration](https://github.com/Entropyphp/utils/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Entropyphp/utils/actions/workflows/ci.yml)

Utility classes for PHP. A collection of PHP utility classes for file operations, attribute handling, and PHP code parsing.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Composer

Installation
------------

[](#installation)

Install via Composer:

```
composer require entropyphp/utils
```

Components
----------

[](#components)

### AttributeLoader

[](#attributeloader)

A utility class for working with PHP 8 attributes (annotations). It provides methods to retrieve attributes from classes and methods.

#### Usage

[](#usage)

```
use Koriym\Attributes\AttributeReader;
use Pg\Utils\Attribute\AttributeLoader;
use ReflectionClass;
use ReflectionMethod;

// Initialize the AttributeLoader
$attributeLoader = new AttributeLoader(new AttributeReader());

// Get a single attribute from a method
$reflectionMethod = new ReflectionMethod(MyClass::class, 'myMethod');
$attribute = $attributeLoader->getMethodAttribute($reflectionMethod, MyAttribute::class);

// Get multiple attributes from a method
$attributes = $attributeLoader->getMethodAttributes($reflectionMethod, MyAttribute::class);
foreach ($attributes as $attribute) {
    // Process each attribute
}

// Get a single attribute from a class
$reflectionClass = new ReflectionClass(MyClass::class);
$attribute = $attributeLoader->getClassAttribute($reflectionClass, MyAttribute::class);

// Get multiple attributes from a class
$attributes = $attributeLoader->getClassAttributes($reflectionClass, MyAttribute::class);
foreach ($attributes as $attribute) {
    // Process each attribute
}

// Access the underlying AttributeReader
$reader = $attributeLoader->getReader();
```

### FileUtils

[](#fileutils)

A utility class for file system operations.

#### Usage

[](#usage-1)

```
use Pg\Utils\File\FileUtils;

// Get all PHP files in a directory (recursively)
$files = FileUtils::getFiles('/path/to/directory', 'php');
foreach ($files as $file) {
    echo $file->getPathname() . PHP_EOL;
}

// Get all PHP files excluding those containing 'test' in the filename
$files = FileUtils::getFiles('/path/to/directory', 'php', 'test');

// Find the project root directory (where composer.json is located)
$projectDir = FileUtils::getProjectDir(__DIR__);

// Get the root path of the installed package
$rootPath = FileUtils::getRootPath();
```

### RequestUtil

[](#requestutil)

a utility class for working with HTTP requests.

#### Usage

[](#usage-2)

```
use Pg\Utils\HttpUtils\RequestUtils;

// Get if the request Ajax call?
$isAjax = RequestUtils::IsAjax($request);

// Get if Request is a JSON request
$isJson = RequestUtils::isJson($request);

// Get the request body as an array if it is a JSON or std POST request, if JSON is malformed, returns an empty array
$body = RequestUtils::getPostParams($request);

// Get the request accept format, defaults to 'html' if not set, or 'json' if the request is a JSON request
$acceptFormat = RequestUtils::getAcceptFormat($request);

// Get if the request accepts JSON
$acceptsJson = RequestUtils::wantJson($request);

// Get the absolute domain URL of the request, with eventually the port number
$url = RequestUtils::getDomain($request);
```

### PhpTokenParser

[](#phptokenparser)

A utility class for parsing PHP code to extract class information.

#### Usage

[](#usage-3)

```
use Pg\Utils\Parser\PhpTokenParser;

// Get the fully qualified class name from PHP code
$phpCode = file_get_contents('/path/to/file.php');
$className = PhpTokenParser::findClass($phpCode);

if ($className) {
    echo "Found class: " . $className . PHP_EOL;
} else {
    echo "No class found in the file." . PHP_EOL;
}
```

Testing
-------

[](#testing)

Run the test suite:

```
composer run tests
```

Generate code coverage report:

```
composer run coverage
```

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance58

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

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

Total

6

Last Release

277d ago

PHP version history (2 changes)v0.1.0PHP ^8.2

0.1.5PHP ^8.2 || ^8.3 || ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/61d9649796b4226f0a5f2e1bfe5bcbb844ebd485b72a7543f19195199b288f96?d=identicon)[Entropyphp](/maintainers/Entropyphp)

---

Top Contributors

[![willy68](https://avatars.githubusercontent.com/u/34144331?v=4)](https://github.com/willy68 "willy68 (24 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/entropyphp-utils/health.svg)

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

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[google/cloud-functions-framework

Google Cloud Functions Framework for PHP

21313.4M](/packages/google-cloud-functions-framework)[wallabag/wallabag

open source self hostable read-it-later web application

12.6k2.2k](/packages/wallabag-wallabag)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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