{"id":20838005,"url":"https://github.com/fusonic/php-csv-reader","last_synced_at":"2025-05-08T20:34:44.840Z","repository":{"id":62508223,"uuid":"337356071","full_name":"fusonic/php-csv-reader","owner":"fusonic","description":"A powerful library for PHP 8 that allows you to map data from CSV files to a strongly typed data model.","archived":false,"fork":false,"pushed_at":"2024-09-16T12:38:40.000Z","size":44,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-08T04:57:03.911Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fusonic.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}},"created_at":"2021-02-09T09:40:27.000Z","updated_at":"2024-09-16T12:25:56.000Z","dependencies_parsed_at":"2024-02-12T15:13:38.757Z","dependency_job_id":"0bd23425-f8bf-4a9e-a554-52082444637c","html_url":"https://github.com/fusonic/php-csv-reader","commit_stats":{"total_commits":11,"total_committers":4,"mean_commits":2.75,"dds":0.5454545454545454,"last_synced_commit":"403476e879515088799637010f2d781e540bcf39"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fphp-csv-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fphp-csv-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fphp-csv-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fphp-csv-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fusonic","download_url":"https://codeload.github.com/fusonic/php-csv-reader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253145973,"owners_count":21861309,"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":[],"created_at":"2024-11-18T01:09:09.838Z","updated_at":"2025-05-08T20:34:44.789Z","avatar_url":"https://github.com/fusonic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSV Reader\n\n[![License](https://img.shields.io/packagist/l/fusonic/csv-reader?color=blue)](https://github.com/fusonic/php-csv-reader/blob/master/LICENSE)\n[![Latest Version](https://img.shields.io/github/tag/fusonic/php-csv-reader.svg?color=blue)](https://github.com/fusonic/php-csv-reader/releases)\n[![Total Downloads](https://img.shields.io/packagist/dt/fusonic/csv-reader.svg?color=blue)](https://packagist.org/packages/fusonic/csv-reader)\n![php 8.2+](https://img.shields.io/badge/php-min%208.0-blue.svg)\n\nCSV Reader is a powerful library for PHP 8 that allows you to map data from CSV files to a strongly typed data model. It does this by utilizing PHP 8's typed properties / arguments and automatically converts string values to the types defined for your class fields.\n\n## Install\n\nUse composer to install the lib from Packagist.\n\n```bash\ncomposer require fusonic/csv-reader\n```\n\nRequirements:\n\n- PHP 8.2+\n\n## Usage\n\nJust define a class that represents your CSV's data structure and use the [`IndexMapping`](src/Attributes/IndexMapping.php) or [`TitleMapping`](src/Attributes/TitleMapping.php) attributes to define the mapping. You don't have to map all the columns, just the ones you need on your model.\n\n```php\nclass Foo\n{\n    #[TitleMapping('Price')]\n    public float $price;\n\n    #[TitleMapping('Price')]\n    public function setPrice(float $value): void\n    {\n        // Not implemented\n    }\n}\n```\n\nNow use the `CsvReader` class to convert CSV data to your object model:\n\n```php\n$reader = new CsvReader('myfile.csv');\nforeach ($reader-\u003ereadObjects(Foo::class) as $item) {\n    var_dump($item);\n}\n```\n\n**Hint:** You can also pass a `resource` instead of a file's path to `CsvReader`. This way you can also access files from remote filesystems, for example if you are using [`league/flysystem`](https://github.com/thephpleague/flysystem). \n\n## Supported types\n\n- `int`\n- `float`\n- `string`\n- `bool` (uses `filter_var()` with `FILTER_VALIDATE_BOOLEAN` and supports values like `on`, `true`, `1`)\n- `DateTime`\n- `DateTimeInterface`\n- `DateTimeImmutable`\n\nIf you choose to use a **nullable type like `?string``** it will be mapped as `null` if the CSV value is an empty string or 'null' (case insensitive).\n\n## Options\n\nRefer to the [`CsvReaderOptions`](src/CsvReaderOptions.php) class to learn about options.\n\n### `IntlValueConverter`\n\nIf you need to unserialize floating point numbers from a specific culture, you can use the `IntlValueConverter` like this:\n\n```php\n$options = new CsvReaderOptions();\n$options-\u003evalueConverter = new IntlValueConverter('de-AT');\n\n$reader = new CsvReader($options);\n```\n\n**Note:** parsing German date format is done implicitely by the default `ValueConverter` implementation since PHP supports passing German date formats to `DateTimeInterface` derivates.\n\n## Contributing\n\nThis is a subtree split of [fusonic/php-extensions](https://github.com/fusonic/php-extensions) repository. Please create your pull requests there. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusonic%2Fphp-csv-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusonic%2Fphp-csv-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusonic%2Fphp-csv-reader/lists"}