{"id":40464125,"url":"https://github.com/neuron-php/data","last_synced_at":"2026-01-20T18:01:18.163Z","repository":{"id":57025768,"uuid":"258234444","full_name":"Neuron-PHP/data","owner":"Neuron-PHP","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-13T03:04:49.000Z","size":249,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2026-01-13T03:18:18.728Z","etag":null,"topics":["php8"],"latest_commit_sha":null,"homepage":"https://neuronphp.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neuron-PHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-23T14:37:00.000Z","updated_at":"2026-01-13T03:04:53.000Z","dependencies_parsed_at":"2025-01-15T21:58:32.059Z","dependency_job_id":"c9dd29e6-5f39-4649-8c8a-266aefcc37de","html_url":"https://github.com/Neuron-PHP/data","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"eed73c34b36c195533b4377105beb513d08a3b48"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/Neuron-PHP/data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Fdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Fdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Fdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Fdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neuron-PHP","download_url":"https://codeload.github.com/Neuron-PHP/data/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Fdata/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php8"],"created_at":"2026-01-20T18:01:01.755Z","updated_at":"2026-01-20T18:01:18.154Z","avatar_url":"https://github.com/Neuron-PHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/Neuron-PHP/data/actions/workflows/ci.yml/badge.svg)](https://github.com/Neuron-PHP/data/actions)\n[![codecov](https://codecov.io/gh/Neuron-PHP/data/branch/develop/graph/badge.svg)](https://codecov.io/gh/Neuron-PHP/data)\n# Neuron-PHP Data\n\nA 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.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Core Features](#core-features)\n- [Input Filtering](#input-filtering)\n- [Settings Management](#settings-management)\n- [Environment Variables](#environment-variables)\n- [Data Objects](#data-objects)\n- [Parsers](#parsers)\n- [Unit Conversion](#unit-conversion)\n- [Testing](#testing)\n- [More Information](#more-information)\n\n## Installation\n\n### Requirements\n\n- PHP 8.4 or higher\n- Extensions: curl, json, calendar\n- Composer\n\n### Install via Composer\n\n```bash\ncomposer require neuron-php/data\n```\n\n## Core Features\n\nThe Data component provides:\n\n- **Input Filtering**: Secure wrappers for PHP's filter_input functions\n- **Settings Management**: Unified configuration from multiple sources (YAML, INI, ENV)\n- **Environment Variables**: .env file loading and management\n- **Data Objects**: Specialized objects for common data structures\n- **Parsers**: CSV, positional, and name parsing utilities\n- **Array Utilities**: Advanced array manipulation functions\n- **Unit Conversion**: Common unit conversions\n- **Date Utilities**: Date range and manipulation tools\n\n## Input Filtering\n\nSecure, type-safe wrappers for PHP's filter_input functions with a consistent interface.\n\n### Available Filters\n\n- `Cookie` - Access $_COOKIE values\n- `Get` - Access $_GET values\n- `Post` - Access $_POST values\n- `Server` - Access $_SERVER values\n- `Session` - Access $_SESSION values\n\n### Filter Interface\n\nAll filters implement the `IFilter` interface:\n\n```php\ninterface IFilter\n{\n    public static function filterScalar($Data): mixed;\n    public static function filterArray(array $Data): array|false|null;\n}\n```\n\n### Usage Examples\n\n```php\nuse Neuron\\Data\\Filter\\Get;\nuse Neuron\\Data\\Filter\\Post;\nuse Neuron\\Data\\Filter\\Cookie;\n\n// Get scalar values\n$page = Get::filterScalar('page');        // From $_GET['page']\n$username = Post::filterScalar('username'); // From $_POST['username']\n$session = Cookie::filterScalar('session_id'); // From $_COOKIE['session_id']\n\n// Get array values\n$filters = Get::filterArray('filters');   // From $_GET['filters'][]\n$items = Post::filterArray('items');      // From $_POST['items'][]\n\n// With validation\n$email = Post::filterScalar('email');\nif (filter_var($email, FILTER_VALIDATE_EMAIL)) {\n    // Valid email\n}\n```\n\n## Settings Management\n\nThe `SettingManager` provides a unified interface for configuration from multiple sources with fallback support.\n\n### Supported Sources\n\n- **YAML** - YAML configuration files\n- **INI** - Traditional INI files\n- **ENV** - Environment variables\n- **Memory** - In-memory configuration\n\n### Basic Usage\n\n```php\nuse Neuron\\Data\\Settings\\SettingManager;\nuse Neuron\\Data\\Settings\\Source\\Yaml;\nuse Neuron\\Data\\Settings\\Source\\Env;\n\n// Create primary source (YAML file)\n$yamlSource = new Yaml('/path/to/neuron.yaml');\n$settings = new SettingManager($yamlSource);\n\n// Add fallback to environment variables\n$envFallback = new Env();\n$settings-\u003esetFallback($envFallback);\n\n// Get settings (checks YAML first, then ENV)\n$dbHost = $settings-\u003eget('database', 'host');\n$apiKey = $settings-\u003eget('api', 'key');\n\n// Set values\n$settings-\u003eset('cache', 'enabled', 'true');\n\n// Get all section names\n$sections = $settings-\u003egetSectionNames();\n\n// Get all settings in a section\n$dbSettings = $settings-\u003egetSectionSettingNames('database');\n```\n\n### YAML Configuration Example\n\n```yaml\n# neuron.yaml\ndatabase:\n  host: localhost\n  port: 3306\n  name: myapp\n  username: root\n  password: secret\n\ncache:\n  enabled: true\n  driver: redis\n  ttl: 3600\n\napi:\n  endpoint: https://api.example.com\n  key: your-api-key\n  timeout: 30\n```\n\n### INI Configuration Example\n\n```ini\n; config.ini\n[database]\nhost = localhost\nport = 3306\nname = myapp\n\n[cache]\nenabled = true\ndriver = file\nttl = 3600\n```\n\n### Memory Source\n\n```php\nuse Neuron\\Data\\Settings\\Source\\Memory;\n\n$memory = new Memory();\n$memory-\u003eset('app', 'name', 'My Application');\n$memory-\u003eset('app', 'version', '1.0.0');\n\n$settings = new SettingManager($memory);\n```\n\n## Environment Variables\n\nThe `Env` class provides secure .env file loading and environment variable management using a singleton pattern.\n\n### Basic Usage\n\n```php\nuse Neuron\\Data\\Env;\n\n// Get singleton instance (auto-loads .env from document root)\n$env = Env::getInstance();\n\n// Get environment variables\n$dbHost = $env-\u003eget('DB_HOST');\n$dbPort = $env-\u003eget('DB_PORT');\n$debug = $env-\u003eget('DEBUG');\n\n// Load custom .env file\n$env = Env::getInstance('/path/to/custom/.env');\n\n// Set environment variables programmatically\n$env-\u003eput('RUNTIME_CONFIG=dynamic_value');\n\n// Check if variable exists\nif ($env-\u003eget('API_KEY')) {\n    // API key is set\n}\n```\n\n### .env File Format\n\n```bash\n# Database Configuration\nDB_HOST=localhost\nDB_PORT=3306\nDB_NAME=myapp\nDB_USER=root\nDB_PASSWORD=secret\n\n# Application Settings\nAPP_ENV=development\nAPP_DEBUG=true\nAPP_URL=http://localhost:8000\n\n# API Configuration\nAPI_KEY=your-secret-key-here\nAPI_TIMEOUT=30\n\n# Comments are supported\n# DISABLED_SETTING=value\n```\n\n## Data Objects\n\nSpecialized objects for common data structures with built-in validation and manipulation.\n\n### Version\n\nWorks with semantic versioning and integrates with the [Bump](https://github.com/ljonesfl/bump) utility.\n\n```php\nuse Neuron\\Data\\Objects\\Version;\n\n$version = new Version();\n\n// Load from .version.json file\n$version-\u003eloadFromFile('.version.json');\n\n// Set version components\n$version-\u003esetMajor(2);\n$version-\u003esetMinor(1);\n$version-\u003esetPatch(5);\n$version-\u003esetPreRelease('beta');\n$version-\u003esetBuildNumber('123');\n\n// Get formatted version\necho $version-\u003egetAsString();  // \"2.1.5-beta+123\"\n\n// Increment version\n$version-\u003eincrementPatch();    // 2.1.6\n$version-\u003eincrementMinor();    // 2.2.0\n$version-\u003eincrementMajor();    // 3.0.0\n\n// Save to file\n$version-\u003esaveToFile('.version.json');\n```\n\n### DateRange\n\nManage date ranges with validation and comparison.\n\n```php\nuse Neuron\\Data\\Objects\\DateRange;\n\n$range = new DateRange(\n    new DateTime('2024-01-01'),\n    new DateTime('2024-12-31')\n);\n\n// Check if date is in range\n$date = new DateTime('2024-06-15');\nif ($range-\u003econtains($date)) {\n    // Date is within range\n}\n\n// Get duration\n$days = $range-\u003egetDays();        // Number of days\n$months = $range-\u003egetMonths();    // Number of months\n\n// Format range\necho $range-\u003eformat('Y-m-d');     // \"2024-01-01 to 2024-12-31\"\n```\n\n### NumericRange\n\nHandle numeric ranges with validation.\n\n```php\nuse Neuron\\Data\\Objects\\NumericRange;\n\n$range = new NumericRange(10, 100);\n\n// Check if value is in range\nif ($range-\u003econtains(50)) {\n    // Value is within range\n}\n\n// Get range properties\n$min = $range-\u003egetMin();          // 10\n$max = $range-\u003egetMax();          // 100\n$size = $range-\u003egetSize();        // 90\n\n// Validate range\nif ($range-\u003eisValid()) {\n    // Min is less than max\n}\n```\n\n### GpsPoint\n\nGeographic coordinate handling with distance calculations.\n\n```php\nuse Neuron\\Data\\Objects\\GpsPoint;\n\n// Create GPS points\n$point1 = new GpsPoint(40.7128, -74.0060);  // New York\n$point2 = new GpsPoint(51.5074, -0.1278);   // London\n\n// Calculate distance\n$distance = $point1-\u003edistanceTo($point2);   // Distance in kilometers\n\n// Get coordinates\n$lat = $point1-\u003egetLatitude();\n$lon = $point1-\u003egetLongitude();\n\n// Validate coordinates\nif ($point1-\u003eisValid()) {\n    // Coordinates are within valid ranges\n}\n\n// Format for display\necho $point1-\u003etoString();  // \"40.7128, -74.0060\"\n```\n\n## Parsers\n\nData parsing utilities for various formats and structures.\n\n### CSV Parser\n\nParse CSV data with custom delimiters and headers.\n\n```php\nuse Neuron\\Data\\Parsers\\CSV;\n\n$csv = new CSV();\n\n// Parse CSV string\n$data = $csv-\u003eparse(\"name,age,city\\nJohn,30,NYC\\nJane,25,LA\");\n\n// Parse with custom delimiter\n$csv-\u003esetDelimiter(';');\n$data = $csv-\u003eparse(\"name;age;city\\nJohn;30;NYC\");\n\n// Parse without headers\n$csv-\u003esetHasHeaders(false);\n$rows = $csv-\u003eparse(\"John,30,NYC\\nJane,25,LA\");\n\n// Parse from file\n$data = $csv-\u003eparseFile('/path/to/data.csv');\n```\n\n### Positional Parser\n\nParse fixed-width positional data.\n\n```php\nuse Neuron\\Data\\Parsers\\Positional;\n\n$parser = new Positional([\n    'name' =\u003e [0, 10],   // Position 0-10\n    'age' =\u003e [10, 3],    // Position 10-13\n    'city' =\u003e [13, 10]   // Position 13-23\n]);\n\n$data = $parser-\u003eparse(\"John Doe  30 New York  \");\n// Result: ['name' =\u003e 'John Doe', 'age' =\u003e '30', 'city' =\u003e 'New York']\n```\n\n### Name Parsers\n\nParse names in various formats.\n\n```php\nuse Neuron\\Data\\Parsers\\FirstMI;\nuse Neuron\\Data\\Parsers\\LastFirstMI;\n\n// Parse \"First MI Last\" format\n$parser = new FirstMI();\n$name = $parser-\u003eparse(\"John A. Smith\");\n// Result: ['first' =\u003e 'John', 'middle' =\u003e 'A', 'last' =\u003e 'Smith']\n\n// Parse \"Last, First MI\" format\n$parser = new LastFirstMI();\n$name = $parser-\u003eparse(\"Smith, John A.\");\n// Result: ['first' =\u003e 'John', 'middle' =\u003e 'A', 'last' =\u003e 'Smith']\n```\n\n## Unit Conversion\n\nCommon unit conversion utilities for measurements.\n\n```php\nuse Neuron\\Data\\UnitConversion;\n\n// Volume conversions\n$ml = UnitConversion::usFlOuncesToMilliliters(16);     // ~473.18 ml\n$oz = UnitConversion::millilitersToUsFlOunces(500);    // ~16.91 oz\n\n// Weight conversions\n$kg = UnitConversion::poundsToKilograms(150);          // ~68.04 kg\n$lbs = UnitConversion::kilogramsToPounds(75);          // ~165.35 lbs\n\n// Temperature conversions (if available)\n$celsius = UnitConversion::fahrenheitToCelsius(98.6);   // 37°C\n$fahrenheit = UnitConversion::celsiusToFahrenheit(20);  // 68°F\n\n// Distance conversions\n$km = UnitConversion::milesToKilometers(100);          // ~160.93 km\n$miles = UnitConversion::kilometersToMiles(42.195);    // ~26.22 miles\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\n# Run all tests\nvendor/bin/phpunit tests\n\n# Run with coverage\nvendor/bin/phpunit tests --coverage-html coverage\n\n# Run specific test file\nvendor/bin/phpunit tests/Data/EnvTest.php\n```\n\n### Test Structure\n\n```\ntests/\n├── Data/\n│   ├── ArrayHelperTest.php\n│   ├── DateTest.php\n│   ├── EnvTest.php\n│   ├── UnitConversionTest.php\n│   ├── Filter/\n│   │   ├── GetTest.php\n│   │   ├── PostTest.php\n│   │   └── ...\n│   ├── Object/\n│   │   ├── VersionTest.php\n│   │   ├── DateRangeTest.php\n│   │   └── ...\n│   ├── Parser/\n│   │   ├── CSVTest.php\n│   │   └── ...\n│   └── Setting/\n│       ├── SettingManagerTest.php\n│       └── Source/\n│           ├── YamlTest.php\n│           └── ...\n├── bootstrap.php\n└── phpunit.xml\n```\n\n## Best Practices\n\n### Configuration Management\n\n```php\n// Use fallback chain for flexible configuration\n$settings = new SettingManager(new Yaml('neuron.yaml'));\n$settings-\u003esetFallback(new Env());\n\n// This checks neuron.yaml first, then environment variables\n$value = $settings-\u003eget('section', 'key');\n```\n\n### Input Validation\n\n```php\n// Always validate filtered input\n$email = Post::filterScalar('email');\nif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {\n    throw new InvalidArgumentException('Invalid email');\n}\n\n// Use array filtering for multiple values\n$ids = Get::filterArray('ids');\nif ($ids) {\n    $ids = array_map('intval', $ids);\n    $ids = array_filter($ids, fn($id) =\u003e $id \u003e 0);\n}\n```\n\n### Environment Configuration\n\n```php\n// Use .env for local development\n// config/.env.development\nDB_HOST=localhost\nAPP_DEBUG=true\n\n// Use environment variables in production\n// Set via server configuration or container\n```\n\n## More Information\n\n- **Neuron Framework**: [neuronphp.com](http://neuronphp.com)\n- **GitHub**: [github.com/neuron-php/data](https://github.com/neuron-php/data)\n- **Packagist**: [packagist.org/packages/neuron-php/data](https://packagist.org/packages/neuron-php/data)\n\n## License\n\nMIT License - see LICENSE file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuron-php%2Fdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuron-php%2Fdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuron-php%2Fdata/lists"}