PHPackages                             domagoj03/object-creator - 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. domagoj03/object-creator

ActiveLibrary

domagoj03/object-creator
========================

PHP library that helps developers create objects from other data types such as arrays, serialized strings and alike.

1.0(7y ago)024MITPHPPHP ^7.2

Since Mar 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/domagoj03/object-creator)[ Packagist](https://packagist.org/packages/domagoj03/object-creator)[ RSS](/packages/domagoj03-object-creator/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Object Creator
==============

[](#object-creator)

[![Travis (.com)](https://camo.githubusercontent.com/4a222079682f43efa47927771df2781e756b93a3198806b18bef7c016e5b9725/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f646f6d61676f6a30332f6f626a6563742d63726561746f722e7376673f7374796c653d666f722d7468652d6261646765)](https://travis-ci.com/domagoj03/object-creator)

Intro
-----

[](#intro)

This simple library was first and foremost created because I noticed that I use the funcionallity it provides across several projects and instead of re-writing the logic again and again, I've decided to mold this into a library, mostly for my conveniance, but also publish it as an open-source project in order to help anyone else who might find it useful.

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

[](#installation)

[![Packagist](https://camo.githubusercontent.com/ffb92f0f0bc600d037918308c01c5c4031d7589e53869d0aabfbd8831b81b204/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f6d61676f6a30332f6f626a6563742d63726561746f722e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/ffb92f0f0bc600d037918308c01c5c4031d7589e53869d0aabfbd8831b81b204/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f6d61676f6a30332f6f626a6563742d63726561746f722e7376673f7374796c653d666f722d7468652d6261646765)[![PHP from Packagist](https://camo.githubusercontent.com/2161eeaf1f9f1729a4e4e3a50b88f14c8afadc5320d1575392265ffa0826a094/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f6d61676f6a30332f6f626a6563742d63726561746f722e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/2161eeaf1f9f1729a4e4e3a50b88f14c8afadc5320d1575392265ffa0826a094/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f6d61676f6a30332f6f626a6563742d63726561746f722e7376673f7374796c653d666f722d7468652d6261646765)

` composer require domagoj03/object-creator`

Usage
-----

[](#usage)

Intended usage is to extend the abstracts of the library and instantiate objects by passing data to your object's constructor. For example, when you receive data as a result of an API call, you might get it as an array or as \\stdClass. Then instead of accessing that data as `$data['value']`, you could acess it as `$object->getValue()` thus mitigating possible errors and additional checks like `isset($data['value'])` before using it.

You can find some inspiration inside `tests/Helpers`

This method proved very handy in situations where I had to handle different data structure received, for example, from an API calls or Webhooks. It's also useful when you have to handle multiple external API integrations.

### v1.0

[](#v10)

- Define object which represents data in your application
- Make it extend desired library abstract
- Generate getters and setters for your properties (in this case for `number`). Remember that index of an associative array is property of your class and value represents the property/key of the data you wish to create object from.

```
class DemoObject extends ArrayObjectCreator // or StdClassObjectCreator
{
    protected $propertyMapper = [
        'number' => 'SomeNumber',
    ];

    /**
     * @var int
     */
    private $number;

    /**
     * @return int
     */
    public function getNumber(): ?int
    {
        return $this->number;
    }

    /**
     * @param int $number
     * @return DemoObjectFromArray
     */
    public function setNumber(int $number): DemoObjectFromArray
    {
        $this->number = $number;

        return $this;
    }
}
```

- When you need to use that received `$data`, instantiate your object and pass the `$data` to a constructor.

#### Data as array

[](#data-as-array)

```
// Usually as a result of an API call
$data = [
    'SomeNumber' => 23
];

$object = new DemoObject($data);
$object->getNumber(); // 23
```

#### Data as stdClass

[](#data-as-stdclass)

```
$data = new \stdClass();
$data->number = 23;

$object = new DemoObject($data); // Has to extend StdClassObjectCreator
$object->getNumber(); // 23
```

- This is a fairly simple example but shows what the library does in a nutshell.

### v0.1 \[not recommended\]

[](#v01-not-recommended)

- Has only `ArrayObjectCreator`
- `ArrayObjectCreator` will not set `null` values

Tests
-----

[](#tests)

`vendor/bin/phpunit`

Contributing
------------

[](#contributing)

Contributing is always welcome.

If you have suggestions or problems with usage, you can open up an issue.

If you want to help with the issues, fork the repository, make sure you have latest version of the code and that the current tests pass, create new branch, work on the feature or bug (and add test cases), push the code to your repository and create a PR to this repository `master` branch mentioning the issue it's resolving.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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

Every ~2 days

Total

2

Last Release

2607d ago

Major Versions

0.1 → 1.02019-03-24

PHP version history (2 changes)0.1PHP ^7.3

1.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/13a63fb7c30356cf7219f75cdb19d89c3d703e96eff61547b15ee251c6bae3c5?d=identicon)[domagoj03](/maintainers/domagoj03)

---

Top Contributors

[![domagoj03](https://avatars.githubusercontent.com/u/12153805?v=4)](https://github.com/domagoj03 "domagoj03 (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/domagoj03-object-creator/health.svg)

```
[![Health](https://phpackages.com/badges/domagoj03-object-creator/health.svg)](https://phpackages.com/packages/domagoj03-object-creator)
```

###  Alternatives

[symfony/form

Allows to easily create, process and reuse HTML forms

2.8k152.1M2.8k](/packages/symfony-form)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k164.3M234](/packages/symfony-security-http)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[vich/uploader-bundle

Ease file uploads attached to entities

1.9k25.9M116](/packages/vich-uploader-bundle)

PHPackages © 2026

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