{"id":18315539,"url":"https://github.com/mathieutu/exporter","last_synced_at":"2025-04-05T16:09:54.620Z","repository":{"id":52420551,"uuid":"116229701","full_name":"mathieutu/exporter","owner":"mathieutu","description":"Export the attributes you need from all your objects and arrays.","archived":false,"fork":false,"pushed_at":"2024-10-07T04:10:40.000Z","size":1272,"stargazers_count":43,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T15:10:05.531Z","etag":null,"topics":["api","arrays","laravel","objects","resources","symfony","transformer"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathieutu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2018-01-04T07:34:06.000Z","updated_at":"2023-11-22T14:02:10.000Z","dependencies_parsed_at":"2024-06-12T15:44:07.865Z","dependency_job_id":"2d7205a0-da95-4ff8-960d-1d36d4124311","html_url":"https://github.com/mathieutu/exporter","commit_stats":{"total_commits":44,"total_committers":4,"mean_commits":11.0,"dds":"0.36363636363636365","last_synced_commit":"5aba7dd6eff5b5399d43e2ba00eb97aa18ee667e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Fexporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Fexporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Fexporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Fexporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathieutu","download_url":"https://codeload.github.com/mathieutu/exporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361693,"owners_count":20926643,"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":["api","arrays","laravel","objects","resources","symfony","transformer"],"created_at":"2024-11-05T16:41:30.862Z","updated_at":"2025-04-05T16:09:54.603Z","avatar_url":"https://github.com/mathieutu.png","language":"PHP","readme":"# Exporter: Export the attributes you need from all your objects and arrays.\n\n\u003ca href=\"https://travis-ci.org/mathieutu/exporter\"\u003e\u003cimg src=\"https://img.shields.io/travis/mathieutu/exporter/master.svg?style=flat-square\" alt=\"Build Status\"\u003e\u003c/img\u003e\u003c/a\u003e \n\u003ca href=\"https://scrutinizer-ci.com/g/mathieutu/exporter\"\u003e\u003cimg src=\"https://img.shields.io/scrutinizer/g/mathieutu/exporter.svg?style=flat-square\" alt=\"Quality Score\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/mathieutu/exporter\"\u003e\u003cimg src=\"https://img.shields.io/scrutinizer/coverage/g/mathieutu/exporter.svg?style=flat-square\" alt=\"Code Coverage\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/mathieutu/exporter\"\u003e\u003cimg src=\"https://poser.pugx.org/mathieutu/exporter/d/total.svg?format=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/mathieutu/exporter\"\u003e\u003cimg src=\"https://poser.pugx.org/mathieutu/exporter/v/stable.svg?format=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/mathieutu/exporter\"\u003e\u003cimg src=\"https://poser.pugx.org/mathieutu/exporter/license.svg?format=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\n## Installation\n\nRequire this package with composer:\n```bash\ncomposer require mathieutu/exporter\n```\n\n## Use cases\n\nBecause pictures are worth thousands words:\n\nThe Exporter package let you write this:\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"./.github/assets/after.png\"\u003e\n        \u003cimg height=\"400\" src=\"./.github/assets/after.png\" alt=\"Exporter use case: After\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\ninstead of that:\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"./.github/assets/before.png\"\u003e\n        \u003cimg height=\"600\" src=\"./.github/assets/before.png\" alt=\"Exporter use case: Before\"\u003e\n    \u003c/a\u003e \n\u003c/p\u003e\n\nFor example, I use it a lot with Laravel Eloquent Resources, or as an easier alternative of Symfony Normalizer:\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"./.github/assets/resource.png\"\u003e\n        \u003cimg height=500 src=\"./.github/assets/resource.png\" alt=\"Exporter use case: Resource\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## Usage\n\nUse the `\\MathieuTu\\Exporter\\Exporter` trait on your classes. \nYou also can use directly the `\\MathieuTu\\Exporter\\ExporterService::exportFrom($exportable, $attributes)` static method on basic arrays or objects, or if you can't add the trait.\n\nYou can export from arrays, objects with `ArrayAccess` interface, or any standard objects.\n\nThe response will be a [Laravel Collection](https://laravel.com/docs/collections) (but you absolutely don't need Laravel, **this package is totally framework agnostic**). \nIf you don't know how to use collections, you can **use it exactly like an array**, or use `toArray()` method to get a real one.\n\n### Examples\n_(You can find all this examples and more in the [package tests](./tests/ExporterServiceTest.php))_\n\nFor the examples, and to cover all the possible ways to use this package, we'll consider this object as input:\n\n```php\n$object = new class\n{\n    use \\MathieuTu\\Exporter\\Exporter;\n\n    public $foo = 'testFoo';\n    private $bar = ['bar1' =\u003e 'testBar1', 'bar2' =\u003e 'testBar2', 'bar3' =\u003e 'testBar3'];\n    public $baz = [\n        (object) ['baz1' =\u003e 'baz1A', 'baz2' =\u003e 'baz2A', 'baz3' =\u003e 'baz3A'],\n        (object) ['baz1' =\u003e 'baz1B', 'baz2' =\u003e 'baz2B', 'baz3' =\u003e 'baz3B'],\n        (object) ['baz1' =\u003e 'baz1C', 'baz2' =\u003e 'baz2C', 'baz3' =\u003e 'baz3C'],\n    ];\n\n    public function testWithParam(string $param): string\n    {\n        return 'test' . $param;\n    }\n\n    public function test(): string\n    {\n        return 'test' . date(\"l\");\n    }\n    \n    public function getBar(): array\n    {\n        return $this-\u003ebar;\n    }\n};\n```\n\nand a standard array as output (in comment), instead of a Collection (result from the `$collection-\u003etoArray()` method).\n\n\n\n#### Export public and private (with getter) root attributes\n\n```php\n$object-\u003eexport(['foo']); // ['foo' =\u003e testFoo]\n$object-\u003eexport(['foo', 'bar']); \n/* \n[\n    'foo' =\u003e testFoo,\n    'bar' =\u003e ['bar1' =\u003e 'testBar1', 'bar2' =\u003e 'testBar2'],\n]\n*/\n```\n\n\n#### Export from nested array/object\n\n- ##### In an array:\n\n```php\n$object-\u003eexport(['bar' =\u003e ['bar2', 'bar3']]);\n/* \n[\n    'bar' =\u003e [\n        'bar2' =\u003e testBar2',\n        'bar3' =\u003e testBar3',\n    ],\n]\n*/\n```\n\n- ##### Only one attribute:\n\n```php\n$object-\u003eexport(['bar' =\u003e 'bar1']); // ['bar' =\u003e 'testBar1']\n```\n\n- ##### With dot notation:\n\n```php\n$object-\u003eexport(['bar.bar1']); // ['bar.bar1' =\u003e 'testBar1']\n```\n\n- ##### Using a wildcard to export from lists:\n\n```php\n$object-\u003eexport(['baz' =\u003e ['*' =\u003e ['baz1', 'baz3']]]); \n/* \n[\n    'baz' =\u003e [\n        ['baz1' =\u003e 'baz1A', 'baz3' =\u003e 'baz3A'],\n        ['baz1' =\u003e 'baz1B', 'baz3' =\u003e 'baz3B'],\n        ['baz1' =\u003e 'baz1C', 'baz3' =\u003e 'baz3C'],\n    ],\n]\n*/        \n```\n\n\n\n#### Set an alias as key:\n\n```php\n$object-\u003eexport(['foo', 'bar.bar2 as secondBar']); \n/* \n[\n    'foo' =\u003e testFoo,\n    'secondBar' =\u003e 'testBar2',\n]\n*/\n```\n\n\n\n#### Export result of a function\n\n```php\n$object-\u003eexport(['testWithParam(Mathieu)']); // ['testWithParam' =\u003e testMathieu]\n$object-\u003eexport(['test()']); // ['test' =\u003e testFriday]\n```\n\n\n\n### License\n\nThis Exporter package is an open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n### Contributing\n\nIssues and PRs are obviously welcomed and encouraged, both for bugs and new features as well as documentation.\nEach piece of code added should be fully tested, but we can do that all together, so please don't be afraid by that. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieutu%2Fexporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathieutu%2Fexporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieutu%2Fexporter/lists"}