{"id":15487096,"url":"https://github.com/byjg/php-anydataset","last_synced_at":"2025-04-14T00:38:07.770Z","repository":{"id":35271528,"uuid":"39532150","full_name":"byjg/php-anydataset","owner":"byjg","description":"Anydataset Core Module. Anydataset is an agnostic data source abstraction layer in PHP.","archived":false,"fork":false,"pushed_at":"2025-03-23T01:07:38.000Z","size":694,"stargazers_count":12,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T18:36:34.907Z","etag":null,"topics":["anydataset","csv","json","mongodb","mysql","oracle","php","postgresql","relational-databases","sparql","sqlserver","text-file","xml"],"latest_commit_sha":null,"homepage":"","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/byjg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"byjg"}},"created_at":"2015-07-22T21:53:16.000Z","updated_at":"2024-12-31T16:14:38.000Z","dependencies_parsed_at":"2024-01-04T00:18:24.437Z","dependency_job_id":"bb6ee167-b520-437b-a550-c9476337e95c","html_url":"https://github.com/byjg/php-anydataset","commit_stats":{"total_commits":216,"total_committers":1,"mean_commits":216.0,"dds":0.0,"last_synced_commit":"dfe3a08dd767decad81de73a8690186e12ee8cb0"},"previous_names":["byjg/php-anydataset","byjg/anydataset"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byjg%2Fphp-anydataset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byjg%2Fphp-anydataset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byjg%2Fphp-anydataset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byjg%2Fphp-anydataset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byjg","download_url":"https://codeload.github.com/byjg/php-anydataset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248803811,"owners_count":21164122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["anydataset","csv","json","mongodb","mysql","oracle","php","postgresql","relational-databases","sparql","sqlserver","text-file","xml"],"created_at":"2024-10-02T06:21:17.079Z","updated_at":"2025-04-14T00:38:07.748Z","avatar_url":"https://github.com/byjg.png","language":"PHP","funding_links":["https://github.com/sponsors/byjg"],"categories":[],"sub_categories":[],"readme":"# AnyDataset\n\n[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)\n[![Build Status](https://github.com/byjg/php-anydataset/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-anydataset/actions/workflows/phpunit.yml)\n[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)\n[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-anydataset/)\n[![GitHub license](https://img.shields.io/github/license/byjg/anydataset.svg)](https://opensource.byjg.com/opensource/licensing.html)\n[![GitHub release](https://img.shields.io/github/release/byjg/anydataset.svg)](https://github.com/byjg/php-anydataset/releases/)\n\nAnydataset Core Module. Anydataset is an agnostic data source abstraction layer in PHP.\n\n## Features\n\n- Access different data sources using the same interface.\n- Iterable results\n- Convert results to array\n\n## Current Implementations\n\n| Object                 | Data Source           | Read | Write | Reference                                           |\n|------------------------|-----------------------|:----:|:-----:|-----------------------------------------------------|\n| DbDriverInterface      | Relational DB         | yes  |  yes  | [Github](https://github.com/byjg/anydataset-db)     |\n| AnyDataSet             | Anydataset            | yes  |  yes  | [Github](https://github.com/byjg/anydataset)        |\n| ArrayDataSet           | Array                 | yes  |  no   | [Github](https://github.com/byjg/anydataset-array)  |\n| TextFileDataSet        | Delimited Fields      | yes  |  no   | [Github](https://github.com/byjg/anydataset-text)   |\n| FixedTextFileDataSet   | Fixed Size fields     | yes  |  no   | [Github](https://github.com/byjg/anydataset-text)   |\n| XmlDataSet             | Xml                   | yes  |  no   | [Github](https://github.com/byjg/anydataset-xml)    |\n| JSONDataSet            | Json                  | yes  |  no   | [Github](https://github.com/byjg/anydataset-json)   |\n| SparQLDataSet          | SparQl Repositories   | yes  |  no   | [Github](https://github.com/byjg/anydataset-sparql) |\n| NoSqlDocumentInterface | NoSql Document Based  | yes  |  yes  | [Github](https://github.com/byjg/anydataset-nosql)  |\n| KeyValueInterface      | NoSql Key/Value Based | yes  |  yes  | [Github](https://github.com/byjg/anydataset-nosql)  |\n\n## Examples\n\n### Iterating with foreach\n\n```php\n\u003c?php\n$dataset = new \\ByJG\\AnyDataset\\Core\\AnyDataset(\"example\");\n\n$iterator = $dataset-\u003egetIterator();\nforeach ($iterator as $row) {\n    print $row-\u003etoArray();\n}\n```\n\n### Filtering results\n\n```php\n\u003c?php\n$filter = new \\ByJG\\AnyDataset\\Core\\IteratorFilter();\n$filter-\u003eaddRelation(\"field1\", \\ByJG\\AnyDataset\\Core\\Enum\\Relation::EQUAL, 10);\n$iterator2 = $dataset-\u003egetIterator($filter);\n```\n\n### Converting to Array\n\n```php\n\u003c?php\n$iterator = $dataset-\u003egetIterator();\nprint_r($iterator-\u003etoArray());\n```\n\n### Iterating with While\n\n```php\n\u003c?php\n$iterator = $dataset-\u003egetIterator();\nwhile ($iterator-\u003ehasNext()) {\n    $row = $iterator-\u003emoveNext();\n\n    print_r($row-\u003eget(\"field1\"));\n}\n```\n\nor\n\n```php\nforeach ($iterator as $row) {\n    print_r($row-\u003eget(\"field1\"));\n}\n```\n\n## Additional Classes\n\n### RowOutpout - Format Field Output\n\nThis class defines custom format for the field output.\n\n```php\n\u003c?php\n$output = RowOutput::getInstance()\n    -\u003eaddFormat(\"field1\", \"Test {field1}\")\n    -\u003eaddFormat(\"field2\", \"Showing {} and {field3}\");\n    -\u003eaddCustomFormat(\"field3\", function ($row, $field, $value) {\n        // return the formatted output.\n        // $row: The row object with all values\n        // $field: The field has been processed\n        // $value: The field value\n    });\n\n// This will output the field1 formatted:\necho $output-\u003eprint($row, \"field1\");\n\n// This will apply the format defintion to all fields at once:\n$ouput-\u003eapply($row);\n```\n\nNotes about the format pattern:\n\n- `{}` represents the current value\n- `{.}` represents the field name\n- `{field_name}` return the value of $row-\u003eget(field_name)\n\n### RowValidator - Validate Field contents\n\n```php\n\u003c?php\n$validator = RowValidator::getInstance()\n    -\u003erequiredFields([\"field1\", \"field2\"])\n    -\u003enumericFields(['field1', 'field3'])\n    -\u003eregexValidation(\"field4\", '/\\d{4}-\\d{2}-\\d{2}/')\n    -\u003ecustomValidation(\"field3\", function($value) {\n        // Return any string containing the error message if validation FAILS\n        // otherwise, just return null and the valition will pass.\n    });\n\n$validator-\u003evalidate($row) // Will return an array with the error messages. Empty array if not errors.\n```\n\n## Formatters\n\nAnyDataset comes with an extensible set to format the AnyDataset. The interface is:\n\n```php\nnamespace ByJG\\AnyDataset\\Core\\Formatter;\n\ninterface FormatterInterface\n{\n    /**\n     * Return the object in your original format, normally as object\n     *\n     * @return mixed\n     */\n    public function raw();\n\n    /**\n     * Return the object transformed to string.\n     *\n     * @return string\n     */\n    public function toText();\n\n    /**\n     * Save the contents to a file\n     *\n     * @param string $filename\n     * @return void\n     */\n    public function saveToFile($filename);\n}\n```\n\nAnyDataset implements two formatters:\n\n- JsonFormatter\n- XmlFormatter\n\nExample:\n\n```php\n\u003c?php\n$formatter = new XmlFormatter($anydataset-\u003egetIterator());\n$formatter-\u003eraw(); // Return a DOM object\n$formatter-\u003etoText(); // Return the XML as a text\n$formatter-\u003esaveToFile(\"/path/to/file.xml\");  // Save the XML Text to a file.\n```\n\n## Install\n\n```bash\ncomposer require \"byjg/anydataset\"\n```\n\n## Running Unit tests\n\n```bash\nvendor/bin/phpunit\n```\n\n## Dependencies\n\n```mermaid\nflowchart TD\n    byjg/anydataset --\u003e byjg/serializer\n    byjg/anydataset --\u003e byjg/xmlutil\n```\n\n----\n[Open source ByJG](http://opensource.byjg.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyjg%2Fphp-anydataset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyjg%2Fphp-anydataset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyjg%2Fphp-anydataset/lists"}