{"id":46236074,"url":"https://github.com/dmt-software/import-reader","last_synced_at":"2026-03-03T19:03:20.416Z","repository":{"id":59470180,"uuid":"534057406","full_name":"dmt-software/import-reader","owner":"dmt-software","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-19T09:19:52.000Z","size":141,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-19T10:07:15.180Z","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/dmt-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-09-08T05:02:43.000Z","updated_at":"2025-11-19T08:04:45.000Z","dependencies_parsed_at":"2025-05-22T13:19:11.782Z","dependency_job_id":null,"html_url":"https://github.com/dmt-software/import-reader","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":0.3278688524590164,"last_synced_commit":"871638a0160ef60dcb59e828d4219e0001505262"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/dmt-software/import-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fimport-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fimport-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fimport-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fimport-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmt-software","download_url":"https://codeload.github.com/dmt-software/import-reader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fimport-reader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30056056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2026-03-03T19:03:17.514Z","updated_at":"2026-03-03T19:03:20.407Z","avatar_url":"https://github.com/dmt-software.png","language":"PHP","readme":"# Import Reader\n\nThe reader is designed to go through a file to return chunks of its contents as objects without a high memory usage.\n\n## Installation\n`composer require dmt-software/import-reader`\n\n## Usage\n\n### Create a reader\n\nThe reader can be created manually or the [reader builder](docs/reader-builder.md) can be used to create a (default) \nreader or a pre-configured one. \n\n```php\nuse DMT\\Import\\Reader\\Decorators\\DecoratorInterface;\nuse DMT\\Import\\Reader\\Decorators\\Handler\\GenericHandlerDecorator;\nuse DMT\\Import\\Reader\\Handlers\\JsonReaderHandler;\nuse DMT\\Import\\Reader\\Reader;\nuse DMT\\Import\\Reader\\Handlers\\Sanitizers\\SanitizerInterface;\nuse pcrov\\JsonReader\\JsonReader;\n\n$internalReader = new JsonReader();\n$internalReader-\u003eopen('/path/to/some.json');\n\n/** @var DecoratorInterface[] $decorators */\n/** @var SanitizerInterface[] $sanitizers */\n$reader = new Reader(\n    new JsonReaderHandler($internalReader, ...$sanitizers),\n    new GenericHandlerDecorator(), \n    ...$decorators\n);\n```\nVisit the [reader handler](docs/reader-handler.md) documentation for more information on the handlers internal readers\nand [sanitizers](docs/output-control.md#sanitizers).\n\n### Adding decorators\n\nOnce a default reader is created, it is possible to add extra decorators to apply on each object that is returned by\nthe read method. \n\n```php\nuse DMT\\Import\\Reader\\Decorators\\ToObjectDecorator;\nuse DMT\\Import\\Reader\\Reader;\n\n/** @var Reader $reader */\n$reader-\u003eaddDecorator(new ToObjectDecorator(Customer::class, ['id' =\u003e 'id', 'name' =\u003e 'fullName', ]));\n\nforeach ($reader-\u003eread() as $customer) {\n    // import customer;\n}\n```\nMore on decorators see the [documentation](docs/output-control.md#decorators).\n\n### Adding filters\n\nBesides controlling the output by using a decorator a part of the object stream the reader returns can be skipped or \nfiltered.\n\n```php\nuse DMT\\Import\\Reader\\Reader;\n\n/** start on item 4 */ \n$skip = 3;\n/** skip all objects that has no id */\n$filter = function (object $current) { \n    return isset($current-\u003eid); \n}\n\nforeach ($reader-\u003eread($skip, $filter) as $item) {\n    // import item\n}\n```\nVisit the [filters section](docs/output-control.md#filters) for more information about filter callbacks.\n\n## Error Handling\n\n### UnreadableException\n\nThis is thrown when the given file can not be read. This can have several causes:\n\n * file is unreadable\n * can not set file pointer\n * end of file reached whilst set file pointer\n * file pointer is set to the wrong return type \n\n```php\nuse DMT\\Import\\Reader\\Exceptions\\UnreadableException;\n\ntry {\n    $readerBuilder-\u003ebuild($file, $options = []);\n} catch (UnreadableException $exception) {\n    // file can not be processed\n}\n```\n\n### ReaderReadException\n\nThis can happen when a single chunk can not be read from the file. It will stop execution of the reading process.\n\n```php\nuse DMT\\Import\\Reader\\Exceptions\\ReaderReadException;\n\ntry {\n    foreach ($reader-\u003eread() as $n =\u003e $object) {\n        // import object\n    }\n} catch (ReaderReadException $exception) {\n    // execution stopped, after $n rows\n}\n```\n\n### DecoratorException\n\nThis exception happens silently. It triggers a user warning and continues the reading process. Depending on you server \nconfiguration this warning is ignored or send to STDOUT or STDERR.   \n\n### Other Exceptions or Errors\n\nAny other kind of failures are (most likely) problems that are caused by configuration faults or when this software \nis implemented incorrect.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmt-software%2Fimport-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmt-software%2Fimport-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmt-software%2Fimport-reader/lists"}