PHPackages                             neuron-php/data - 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. neuron-php/data

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

neuron-php/data
===============

PHP data utility classes.

0.9.14(4mo ago)040.0k↓39%5MITPHPCI failing

Since Apr 23Pushed 4mo agoCompare

[ Source](https://github.com/Neuron-PHP/data)[ Packagist](https://packagist.org/packages/neuron-php/data)[ RSS](/packages/neuron-php-data/feed)WikiDiscussions develop Synced 1w ago

READMEChangelogDependencies (4)Versions (48)Used By (5)

[![CI](https://github.com/Neuron-PHP/data/actions/workflows/ci.yml/badge.svg)](https://github.com/Neuron-PHP/data/actions)[![codecov](https://camo.githubusercontent.com/edff15f485be7f2425b3924ecd44abe91504321dcd54d16fc41169ba3d857d2c/68747470733a2f2f636f6465636f762e696f2f67682f4e6575726f6e2d5048502f646174612f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/Neuron-PHP/data)

Neuron-PHP Data
===============

[](#neuron-php-data)

A comprehensive data handling and utility component for PHP 8.4+ that provides essential data manipulation, filtering, parsing, and configuration management tools for the Neuron framework.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Core Features](#core-features)
- [Input Filtering](#input-filtering)
- [Settings Management](#settings-management)
- [Environment Variables](#environment-variables)
- [Data Objects](#data-objects)
- [Parsers](#parsers)
- [Unit Conversion](#unit-conversion)
- [Testing](#testing)
- [More Information](#more-information)

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

[](#installation)

### Requirements

[](#requirements)

- PHP 8.4 or higher
- Extensions: curl, json, calendar
- Composer

### Install via Composer

[](#install-via-composer)

```
composer require neuron-php/data
```

Core Features
-------------

[](#core-features)

The Data component provides:

- **Input Filtering**: Secure wrappers for PHP's filter\_input functions
- **Settings Management**: Unified configuration from multiple sources (YAML, INI, ENV)
- **Environment Variables**: .env file loading and management
- **Data Objects**: Specialized objects for common data structures
- **Parsers**: CSV, positional, and name parsing utilities
- **Array Utilities**: Advanced array manipulation functions
- **Unit Conversion**: Common unit conversions
- **Date Utilities**: Date range and manipulation tools

Input Filtering
---------------

[](#input-filtering)

Secure, type-safe wrappers for PHP's filter\_input functions with a consistent interface.

### Available Filters

[](#available-filters)

- `Cookie` - Access $\_COOKIE values
- `Get` - Access $\_GET values
- `Post` - Access $\_POST values
- `Server` - Access $\_SERVER values
- `Session` - Access $\_SESSION values

### Filter Interface

[](#filter-interface)

All filters implement the `IFilter` interface:

```
interface IFilter
{
    public static function filterScalar($Data): mixed;
    public static function filterArray(array $Data): array|false|null;
}
```

### Usage Examples

[](#usage-examples)

```
use Neuron\Data\Filter\Get;
use Neuron\Data\Filter\Post;
use Neuron\Data\Filter\Cookie;

// Get scalar values
$page = Get::filterScalar('page');        // From $_GET['page']
$username = Post::filterScalar('username'); // From $_POST['username']
$session = Cookie::filterScalar('session_id'); // From $_COOKIE['session_id']

// Get array values
$filters = Get::filterArray('filters');   // From $_GET['filters'][]
$items = Post::filterArray('items');      // From $_POST['items'][]

// With validation
$email = Post::filterScalar('email');
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Valid email
}
```

Settings Management
-------------------

[](#settings-management)

The `SettingManager` provides a unified interface for configuration from multiple sources with fallback support.

### Supported Sources

[](#supported-sources)

- **YAML** - YAML configuration files
- **INI** - Traditional INI files
- **ENV** - Environment variables
- **Memory** - In-memory configuration

### Basic Usage

[](#basic-usage)

```
use Neuron\Data\Settings\SettingManager;
use Neuron\Data\Settings\Source\Yaml;
use Neuron\Data\Settings\Source\Env;

// Create primary source (YAML file)
$yamlSource = new Yaml('/path/to/neuron.yaml');
$settings = new SettingManager($yamlSource);

// Add fallback to environment variables
$envFallback = new Env();
$settings->setFallback($envFallback);

// Get settings (checks YAML first, then ENV)
$dbHost = $settings->get('database', 'host');
$apiKey = $settings->get('api', 'key');

// Set values
$settings->set('cache', 'enabled', 'true');

// Get all section names
$sections = $settings->getSectionNames();

// Get all settings in a section
$dbSettings = $settings->getSectionSettingNames('database');
```

### YAML Configuration Example

[](#yaml-configuration-example)

```
# neuron.yaml
database:
  host: localhost
  port: 3306
  name: myapp
  username: root
  password: secret

cache:
  enabled: true
  driver: redis
  ttl: 3600

api:
  endpoint: https://api.example.com
  key: your-api-key
  timeout: 30
```

### INI Configuration Example

[](#ini-configuration-example)

```
; config.ini
[database]
host = localhost
port = 3306
name = myapp

[cache]
enabled = true
driver = file
ttl = 3600
```

### Memory Source

[](#memory-source)

```
use Neuron\Data\Settings\Source\Memory;

$memory = new Memory();
$memory->set('app', 'name', 'My Application');
$memory->set('app', 'version', '1.0.0');

$settings = new SettingManager($memory);
```

Environment Variables
---------------------

[](#environment-variables)

The `Env` class provides secure .env file loading and environment variable management using a singleton pattern.

### Basic Usage

[](#basic-usage-1)

```
use Neuron\Data\Env;

// Get singleton instance (auto-loads .env from document root)
$env = Env::getInstance();

// Get environment variables
$dbHost = $env->get('DB_HOST');
$dbPort = $env->get('DB_PORT');
$debug = $env->get('DEBUG');

// Load custom .env file
$env = Env::getInstance('/path/to/custom/.env');

// Set environment variables programmatically
$env->put('RUNTIME_CONFIG=dynamic_value');

// Check if variable exists
if ($env->get('API_KEY')) {
    // API key is set
}
```

### .env File Format

[](#env-file-format)

```
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=myapp
DB_USER=root
DB_PASSWORD=secret

# Application Settings
APP_ENV=development
APP_DEBUG=true
APP_URL=http://localhost:8000

# API Configuration
API_KEY=your-secret-key-here
API_TIMEOUT=30

# Comments are supported
# DISABLED_SETTING=value
```

Data Objects
------------

[](#data-objects)

Specialized objects for common data structures with built-in validation and manipulation.

### Version

[](#version)

Works with semantic versioning and integrates with the [Bump](https://github.com/ljonesfl/bump) utility.

```
use Neuron\Data\Objects\Version;

$version = new Version();

// Load from .version.json file
$version->loadFromFile('.version.json');

// Set version components
$version->setMajor(2);
$version->setMinor(1);
$version->setPatch(5);
$version->setPreRelease('beta');
$version->setBuildNumber('123');

// Get formatted version
echo $version->getAsString();  // "2.1.5-beta+123"

// Increment version
$version->incrementPatch();    // 2.1.6
$version->incrementMinor();    // 2.2.0
$version->incrementMajor();    // 3.0.0

// Save to file
$version->saveToFile('.version.json');
```

### DateRange

[](#daterange)

Manage date ranges with validation and comparison.

```
use Neuron\Data\Objects\DateRange;

$range = new DateRange(
    new DateTime('2024-01-01'),
    new DateTime('2024-12-31')
);

// Check if date is in range
$date = new DateTime('2024-06-15');
if ($range->contains($date)) {
    // Date is within range
}

// Get duration
$days = $range->getDays();        // Number of days
$months = $range->getMonths();    // Number of months

// Format range
echo $range->format('Y-m-d');     // "2024-01-01 to 2024-12-31"
```

### NumericRange

[](#numericrange)

Handle numeric ranges with validation.

```
use Neuron\Data\Objects\NumericRange;

$range = new NumericRange(10, 100);

// Check if value is in range
if ($range->contains(50)) {
    // Value is within range
}

// Get range properties
$min = $range->getMin();          // 10
$max = $range->getMax();          // 100
$size = $range->getSize();        // 90

// Validate range
if ($range->isValid()) {
    // Min is less than max
}
```

### GpsPoint

[](#gpspoint)

Geographic coordinate handling with distance calculations.

```
use Neuron\Data\Objects\GpsPoint;

// Create GPS points
$point1 = new GpsPoint(40.7128, -74.0060);  // New York
$point2 = new GpsPoint(51.5074, -0.1278);   // London

// Calculate distance
$distance = $point1->distanceTo($point2);   // Distance in kilometers

// Get coordinates
$lat = $point1->getLatitude();
$lon = $point1->getLongitude();

// Validate coordinates
if ($point1->isValid()) {
    // Coordinates are within valid ranges
}

// Format for display
echo $point1->toString();  // "40.7128, -74.0060"
```

Parsers
-------

[](#parsers)

Data parsing utilities for various formats and structures.

### CSV Parser

[](#csv-parser)

Parse CSV data with custom delimiters and headers.

```
use Neuron\Data\Parsers\CSV;

$csv = new CSV();

// Parse CSV string
$data = $csv->parse("name,age,city\nJohn,30,NYC\nJane,25,LA");

// Parse with custom delimiter
$csv->setDelimiter(';');
$data = $csv->parse("name;age;city\nJohn;30;NYC");

// Parse without headers
$csv->setHasHeaders(false);
$rows = $csv->parse("John,30,NYC\nJane,25,LA");

// Parse from file
$data = $csv->parseFile('/path/to/data.csv');
```

### Positional Parser

[](#positional-parser)

Parse fixed-width positional data.

```
use Neuron\Data\Parsers\Positional;

$parser = new Positional([
    'name' => [0, 10],   // Position 0-10
    'age' => [10, 3],    // Position 10-13
    'city' => [13, 10]   // Position 13-23
]);

$data = $parser->parse("John Doe  30 New York  ");
// Result: ['name' => 'John Doe', 'age' => '30', 'city' => 'New York']
```

### Name Parsers

[](#name-parsers)

Parse names in various formats.

```
use Neuron\Data\Parsers\FirstMI;
use Neuron\Data\Parsers\LastFirstMI;

// Parse "First MI Last" format
$parser = new FirstMI();
$name = $parser->parse("John A. Smith");
// Result: ['first' => 'John', 'middle' => 'A', 'last' => 'Smith']

// Parse "Last, First MI" format
$parser = new LastFirstMI();
$name = $parser->parse("Smith, John A.");
// Result: ['first' => 'John', 'middle' => 'A', 'last' => 'Smith']
```

Unit Conversion
---------------

[](#unit-conversion)

Common unit conversion utilities for measurements.

```
use Neuron\Data\UnitConversion;

// Volume conversions
$ml = UnitConversion::usFlOuncesToMilliliters(16);     // ~473.18 ml
$oz = UnitConversion::millilitersToUsFlOunces(500);    // ~16.91 oz

// Weight conversions
$kg = UnitConversion::poundsToKilograms(150);          // ~68.04 kg
$lbs = UnitConversion::kilogramsToPounds(75);          // ~165.35 lbs

// Temperature conversions (if available)
$celsius = UnitConversion::fahrenheitToCelsius(98.6);   // 37°C
$fahrenheit = UnitConversion::celsiusToFahrenheit(20);  // 68°F

// Distance conversions
$km = UnitConversion::milesToKilometers(100);          // ~160.93 km
$miles = UnitConversion::kilometersToMiles(42.195);    // ~26.22 miles
```

Testing
-------

[](#testing)

Run the test suite:

```
# Run all tests
vendor/bin/phpunit tests

# Run with coverage
vendor/bin/phpunit tests --coverage-html coverage

# Run specific test file
vendor/bin/phpunit tests/Data/EnvTest.php
```

### Test Structure

[](#test-structure)

```
tests/
├── Data/
│   ├── ArrayHelperTest.php
│   ├── DateTest.php
│   ├── EnvTest.php
│   ├── UnitConversionTest.php
│   ├── Filter/
│   │   ├── GetTest.php
│   │   ├── PostTest.php
│   │   └── ...
│   ├── Object/
│   │   ├── VersionTest.php
│   │   ├── DateRangeTest.php
│   │   └── ...
│   ├── Parser/
│   │   ├── CSVTest.php
│   │   └── ...
│   └── Setting/
│       ├── SettingManagerTest.php
│       └── Source/
│           ├── YamlTest.php
│           └── ...
├── bootstrap.php
└── phpunit.xml

```

Best Practices
--------------

[](#best-practices)

### Configuration Management

[](#configuration-management)

```
// Use fallback chain for flexible configuration
$settings = new SettingManager(new Yaml('neuron.yaml'));
$settings->setFallback(new Env());

// This checks neuron.yaml first, then environment variables
$value = $settings->get('section', 'key');
```

### Input Validation

[](#input-validation)

```
// Always validate filtered input
$email = Post::filterScalar('email');
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    throw new InvalidArgumentException('Invalid email');
}

// Use array filtering for multiple values
$ids = Get::filterArray('ids');
if ($ids) {
    $ids = array_map('intval', $ids);
    $ids = array_filter($ids, fn($id) => $id > 0);
}
```

### Environment Configuration

[](#environment-configuration)

```
// Use .env for local development
// config/.env.development
DB_HOST=localhost
APP_DEBUG=true

// Use environment variables in production
// Set via server configuration or container
```

More Information
----------------

[](#more-information)

- **Neuron Framework**: [neuronphp.com](http://neuronphp.com)
- **GitHub**: [github.com/neuron-php/data](https://github.com/neuron-php/data)
- **Packagist**: [packagist.org/packages/neuron-php/data](https://packagist.org/packages/neuron-php/data)

License
-------

[](#license)

MIT License - see LICENSE file for details

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance74

Regular maintenance activity

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

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

Recently: every ~0 days

Total

46

Last Release

147d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1099983?v=4)[Lee Jones](/maintainers/ljonesfl)[@ljonesfl](https://github.com/ljonesfl)

---

Top Contributors

[![ljonesfl](https://avatars.githubusercontent.com/u/1099983?v=4)](https://github.com/ljonesfl "ljonesfl (251 commits)")

---

Tags

php8

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/neuron-php-data/health.svg)

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

###  Alternatives

[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k44](/packages/friendsoftypo3-content-blocks)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)[blackfire/player

A powerful web crawler and web scraper with Blackfire support

49517.1k](/packages/blackfire-player)[altis/local-server

Local Server module for Altis

18217.0k2](/packages/altis-local-server)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1715.6k12](/packages/2lenet-crudit-bundle)

PHPackages © 2026

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