endorphin-studio / data-object
Simple Library to Work with base object
1.0.2
2021-08-19 16:05 UTC
Requires
- php: >= 7.4
- ext-json: *
README
Create object from array and work with it with helper functions getFieldName(), setFieldName($value)
Code Status
About
Author: Serhii Nekhaienko
Email: serhii.nekhaienko@gmail.com
Stable Version: 1.0.0
License: MIT
Requirements
PHP >=7.4
JSON extension
Install via Composer
composer require endorphin-studio/data-object
Basic Usage
use EndorphinStudio\DataObject\DataObject; class Role extends DataObject { } class User extends DataObject { protected array $fieldTypeMapping = [ 'roles' => Role::class ]; protected array $listFields = [ 'roles' ]; } $userData = [ 'name' => 'Serhii', 'login' => 'serhii', 'roles' => [ [ 'name' => 'admin' ], [ 'name' => 'editor' ] ] ]; $user = new User($userData); echo $user->getName(); // Serhii echo $user->getLogin(); // serhii foreach($user->getRoles() as $role) { echo $role->getName(); // admin, editor }