PHPackages                             elysio/typed-array - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. elysio/typed-array

ActiveLibrary

elysio/typed-array
==================

A PHP package for managing typed arrays, simulating TypeScript interfaces, and improving array handling in PHP projects.

1.0.0(1y ago)03MITPHP

Since Jan 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Refaltor77/TypedArray)[ Packagist](https://packagist.org/packages/elysio/typed-array)[ RSS](/packages/elysio-typed-array/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

TypedArray
==========

[](#typedarray)

A PHP package for transforming associative arrays into typed objects, simulating TypeScript interfaces for better type safety in PHP projects.

Features
--------

[](#features)

- Convert arrays to objects based on class definitions.
- Ensure type validation for properties.
- Enhance code readability and maintainability with type safety.
- Works seamlessly with any PHP project, including Laravel.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require elysio/typed-array
```

---

Basic Usage
-----------

[](#basic-usage)

### Example 1: Simple Array to Class Transformation

[](#example-1-simple-array-to-class-transformation)

Define a class with typed properties:

```
namespace App\Models;

class User {
public string $name;
public int $age;
}
```

Transform an array into typed objects:

```
use Elysio\TypedArray\Transform;
use App\Models\User;

$data = [
['name' => 'Alice', 'age' => 28],
['name' => 'Bob', 'age' => 35]
];

$users = Transform::toClass($data, User::class);

foreach ($users as $user) {
echo "{$user->name} is {$user->age} years old.\n";
}
```

**Output: Alice is 28 years old. Bob is 35 years old.**

---

### Example 2: Type Validation

[](#example-2-type-validation)

If the input data has missing keys or invalid types, an exception will be thrown:

```
$data = [
['name' => 'Charlie'], // Missing 'age'
['name' => 'Diana', 'age' => 'thirty'] // Invalid type for 'age'
];

try {
$users = Transform::toClass($data, User::class);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
```

**Output: Error: The key 'age' is missing in the data.**

---

### Example 3: Nested Objects

[](#example-3-nested-objects)

You can use the package for nested structures by defining relationships between classes:

```
namespace App\Models;

class Address {
public string $city;
public string $zipcode;
}

class User {
public string $name;
public Address $address;
}
```

Transform data with nested structures:

```
use Elysio\TypedArray\Transform;
use App\Models\User;
use App\Models\Address;

$data = [
[
'name' => 'Eve',
'address' => ['city' => 'Paris', 'zipcode' => '75000']
]
];

$users = Transform::toClass($data, User::class);

foreach ($users as $user) {
echo "{$user->name} lives in {$user->address->city} ({$user->address->zipcode}).\n";
}
```

**Output: Eve lives in Paris (75000).**

---

Error Handling
--------------

[](#error-handling)

### Common Exceptions

[](#common-exceptions)

- **Missing Key Exception**: Thrown when a required key is missing in the input data.
- **Type Mismatch Exception**: Thrown when a property's type does not match the expected type.

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT License](LICENSE).

MIT License

Copyright (c) 2025 Elysio Martins

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance40

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/adf85a5316a41d0ac81a3fb9b6e1c2530996b13549e29b8d068d657ad614cb8e?d=identicon)[Refaltor77](/maintainers/Refaltor77)

---

Top Contributors

[![Refaltor77](https://avatars.githubusercontent.com/u/77900181?v=4)](https://github.com/Refaltor77 "Refaltor77 (2 commits)")

---

Tags

arrayarray-typedlaravelphpphp7php8symfonysymfony-bundletabstypage

### Embed Badge

![Health badge](/badges/elysio-typed-array/health.svg)

```
[![Health](https://phpackages.com/badges/elysio-typed-array/health.svg)](https://phpackages.com/packages/elysio-typed-array)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
