PHPackages                             marvin255/data-getter-helper - 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. marvin255/data-getter-helper

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

marvin255/data-getter-helper
============================

Helper which allows to get typed data from mixed sources.

v0.6.3(3mo ago)0204[1 PRs](https://github.com/marvin255/data-getter-helper/pulls)2MITPHPPHP &gt;=8.3CI passing

Since Aug 18Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/marvin255/data-getter-helper)[ Packagist](https://packagist.org/packages/marvin255/data-getter-helper)[ RSS](/packages/marvin255-data-getter-helper/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (8)Versions (14)Used By (2)

DataGetterHelper
================

[](#datagetterhelper)

Type-safe helper for extracting and validating typed data from mixed sources in PHP.

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

[](#installation)

Install the package via Composer:

```
composer require marvin255/data-getter-helper
```

Extract string value
--------------------

[](#extract-string-value)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

$data = [
    'user' => [
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ],
];

// Extract with default value
$name = DataGetterHelper::string('user.name', $data);           // 'John Doe'
$phone = DataGetterHelper::string('user.phone', $data, '');     // ''

// Require the value (throws exception if not found)
$email = DataGetterHelper::requireString('user.email', $data);  // 'john@example.com'
```

Extract numeric values
----------------------

[](#extract-numeric-values)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

$data = [
    'product' => [
        'id' => 123,
        'price' => 99.99,
        'quantity' => '5',
    ],
];

// Int extraction
$id = DataGetterHelper::int('product.id', $data);               // 123
$quantity = DataGetterHelper::int('product.quantity', $data);   // 5
$stock = DataGetterHelper::int('product.stock', $data, 0);      // 0

// Float extraction
$price = DataGetterHelper::float('product.price', $data);       // 99.99
$discount = DataGetterHelper::float('product.discount', $data, 0.0);  // 0.0

// Require numeric values
$productId = DataGetterHelper::requireInt('product.id', $data);
$productPrice = DataGetterHelper::requireFloat('product.price', $data);
```

Extract boolean values
----------------------

[](#extract-boolean-values)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

$data = [
    'settings' => [
        'enabled' => true,
        'debug' => 1,
    ],
];

// Bool extraction
$enabled = DataGetterHelper::bool('settings.enabled', $data);      // true
$notify = DataGetterHelper::bool('settings.notify', $data, false); // false

// Require bool value
$debugMode = DataGetterHelper::requireBool('settings.debug', $data);
```

Extract array values
--------------------

[](#extract-array-values)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

$data = [
    'users' => [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ],
    'tags' => [],
];

// Extract array
$users = DataGetterHelper::array('users', $data);        // [['id' => 1, ...], ...]
$tags = DataGetterHelper::array('tags', $data);          // []
$categories = DataGetterHelper::array('categories', $data, ['default']); // ['default']

// Map array values with callback
$userIds = DataGetterHelper::arrayOf('users', $data, fn($user) => $user['id']); // [1, 2]
```

Extract object instances
------------------------

[](#extract-object-instances)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

class User {
    public function __construct(public string $name) {}
}

$user = new User('John');
$data = ['current_user' => $user];

// Extract object of specific class
$currentUser = DataGetterHelper::objectOf('current_user', $data, User::class);
```

Get mixed data
--------------

[](#get-mixed-data)

```
use Marvin255\DataGetterHelper\DataGetterHelper;

$data = [
    'config' => [
        'settings' => [
            'theme' => 'dark',
            'version' => 2,
        ],
    ],
];

// Get any value
$theme = DataGetterHelper::get('config.settings.theme', $data);          // 'dark'
$unknown = DataGetterHelper::get('config.unknown', $data, 'fallback');   // 'fallback'
```

Working with objects
--------------------

[](#working-with-objects)

All methods work with both arrays and objects:

```
use Marvin255\DataGetterHelper\DataGetterHelper;

class Config {
    public array $database = ['host' => 'localhost'];
}

$config = new Config();

$host = DataGetterHelper::string('database.host', $config); // 'localhost'
```

Error handling
--------------

[](#error-handling)

Methods throw `DataGetterException` when:

- Required values are not found
- Values cannot be cast to the requested type (scalar methods)
- Values are not of the expected type (array, object methods)

```
use Marvin255\DataGetterHelper\DataGetterHelper;
use Marvin255\DataGetterHelper\DataGetterException;

try {
    $value = DataGetterHelper::requireInt('user.age', []);
} catch (DataGetterException $e) {
    echo $e->getMessage(); // "Item isn't found by path user.age"
}
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance87

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.3% 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 ~120 days

Recently: every ~239 days

Total

9

Last Release

90d ago

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

v0.6.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c29b776ac327dcfcdfc20619a65826ad94a0cb554503386fb080299edfbe3e8?d=identicon)[marvin255](/maintainers/marvin255)

---

Top Contributors

[![marvin255](https://avatars.githubusercontent.com/u/2802915?v=4)](https://github.com/marvin255 "marvin255 (21 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

data-extractionphptype-safephpgetter

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/marvin255-data-getter-helper/health.svg)

```
[![Health](https://phpackages.com/badges/marvin255-data-getter-helper/health.svg)](https://phpackages.com/packages/marvin255-data-getter-helper)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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