{"id":23913011,"url":"https://github.com/refaltor77/typedarray","last_synced_at":"2026-02-13T05:36:04.437Z","repository":{"id":270992021,"uuid":"912097897","full_name":"Refaltor77/TypedArray","owner":"Refaltor77","description":"A PHP package for managing typed arrays, simulating TypeScript interfaces, and improving array handling in PHP projects.","archived":false,"fork":false,"pushed_at":"2025-01-04T15:47:43.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T10:51:11.162Z","etag":null,"topics":["array","array-typed","laravel","php","php7","php8","symfony","symfony-bundle","tabs","typage"],"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/Refaltor77.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":"2025-01-04T15:46:10.000Z","updated_at":"2025-01-04T15:49:44.000Z","dependencies_parsed_at":"2025-01-04T21:15:06.503Z","dependency_job_id":"d48738d4-7d44-42fa-98b9-664ad6e2e15d","html_url":"https://github.com/Refaltor77/TypedArray","commit_stats":null,"previous_names":["refaltor77/typedarray"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refaltor77%2FTypedArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refaltor77%2FTypedArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refaltor77%2FTypedArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refaltor77%2FTypedArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Refaltor77","download_url":"https://codeload.github.com/Refaltor77/TypedArray/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248420254,"owners_count":21100347,"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":["array","array-typed","laravel","php","php7","php8","symfony","symfony-bundle","tabs","typage"],"created_at":"2025-01-05T09:20:13.004Z","updated_at":"2026-02-13T05:36:04.405Z","avatar_url":"https://github.com/Refaltor77.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypedArray\n\nA PHP package for transforming associative arrays into typed objects, simulating TypeScript interfaces for better type safety in PHP projects.\n\n## Features\n\n- Convert arrays to objects based on class definitions.\n- Ensure type validation for properties.\n- Enhance code readability and maintainability with type safety.\n- Works seamlessly with any PHP project, including Laravel.\n\n---\n\n## Installation\n\nInstall the package via Composer:\n\n```SH\ncomposer require elysio/typed-array\n```\n\n---\n\n## Basic Usage\n\n### Example 1: Simple Array to Class Transformation\n\nDefine a class with typed properties:\n\n```PHP\nnamespace App\\Models;\n\nclass User {\npublic string $name;\npublic int $age;\n}\n```\n\nTransform an array into typed objects:\n\n```PHP\nuse Elysio\\TypedArray\\Transform;\nuse App\\Models\\User;\n\n$data = [\n['name' =\u003e 'Alice', 'age' =\u003e 28],\n['name' =\u003e 'Bob', 'age' =\u003e 35]\n];\n\n$users = Transform::toClass($data, User::class);\n\nforeach ($users as $user) {\necho \"{$user-\u003ename} is {$user-\u003eage} years old.\\n\";\n}\n```\n\n**Output: Alice is 28 years old. Bob is 35 years old.**\n\n\n---\n\n### Example 2: Type Validation\n\nIf the input data has missing keys or invalid types, an exception will be thrown:\n\n```PHP\n$data = [\n['name' =\u003e 'Charlie'], // Missing 'age'\n['name' =\u003e 'Diana', 'age' =\u003e 'thirty'] // Invalid type for 'age'\n];\n\ntry {\n$users = Transform::toClass($data, User::class);\n} catch (Exception $e) {\necho \"Error: \" . $e-\u003egetMessage();\n}\n```\n\n**Output: Error: The key 'age' is missing in the data.**\n\n\n---\n\n### Example 3: Nested Objects\n\nYou can use the package for nested structures by defining relationships between classes:\n\n```PHP\nnamespace App\\Models;\n\nclass Address {\npublic string $city;\npublic string $zipcode;\n}\n\nclass User {\npublic string $name;\npublic Address $address;\n}\n```\n\nTransform data with nested structures:\n\n```PHP\nuse Elysio\\TypedArray\\Transform;\nuse App\\Models\\User;\nuse App\\Models\\Address;\n\n$data = [\n[\n'name' =\u003e 'Eve',\n'address' =\u003e ['city' =\u003e 'Paris', 'zipcode' =\u003e '75000']\n]\n];\n\n$users = Transform::toClass($data, User::class);\n\nforeach ($users as $user) {\necho \"{$user-\u003ename} lives in {$user-\u003eaddress-\u003ecity} ({$user-\u003eaddress-\u003ezipcode}).\\n\";\n}\n```\n\n**Output: Eve lives in Paris (75000).**\n\n\n---\n\n## Error Handling\n\n### Common Exceptions\n\n- **Missing Key Exception**: Thrown when a required key is missing in the input data.\n- **Type Mismatch Exception**: Thrown when a property's type does not match the expected type.\n\n---\n\n## License\n\nThis package is open-sourced software licensed under the [MIT License](LICENSE).\n\n\n\nMIT License\n\nCopyright (c) 2025 Elysio Martins\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefaltor77%2Ftypedarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefaltor77%2Ftypedarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefaltor77%2Ftypedarray/lists"}