PHPackages                             drieschel/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. drieschel/object-creator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

drieschel/object-creator
========================

Initialize and instantiate (data structure) objects recursively

v0.1.0(4y ago)03MITPHPPHP &gt;=7.4

Since May 21Pushed 4y ago2 watchersCompare

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

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

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

[](#object-creator)

The Object Creator can be used to instantiate and initialize objects from classes which represent a data structure. It is possible to add instantiators which know how to instantiate objects of a specific class. In this way it can be ensured that all objects are getting instantiated properly.

### Usage

[](#usage)

```
use Drieschel\ObjectCreator\ObjectCreator;
use Drieschel\ObjectCreator\Instantiator\DateTimeInstantiator;

// Example data from various source
$data = [
    'int' => 42,
    'float' => 0.7,
    'string' => 'yeeeehaaa',
    'bool' => true,
    'datetime' => 'Sat Jan 30 1988 12:22:22 GMT+0100'
];

// Example data structure class
class Entity {
    protected int $int;

    protected float $float;

    protected string $string;

    protected bool $bool;

    protected \DateTimeInterface $datetime;

    public function __construct(int $int, string $string) {
        $this->int = $int;
        $this->string = $string;
    }

    public function setFloat(float $float): self
    {
        $this->float = $float;
        return $this;
    }

    public function setBool(bool $bool): self
    {
        $this->bool = $bool;
        return $this;
    }

    public function setDatetime(\DateTimeInterface $datetime): self
    {
        $this->datetime = $datetime;
        return $this;
    }
}

// Instantiate the creator
$creator = new ObjectCreator();

// Add a class mapping for arguments from type DateTimeInterface.
// All arguments from type DateTimeInterface will be instantiated as DateTimeImmutable
$creator->setClassMapping(\DateTimeInterface::class, \DateTimeImmutable::class);

// Register a DateTime instantiator which knows how to
// instantiate objects that implements the DateTimeInterface
$creator->registerInstantiator(new DateTimeInstantiator());

// Instantiate an object
$entity = $creator->instantiate(Entity::class, $data);

// Initialize an object
$creator->initialize($entity, $data);

// Or instantiate and initialize an object together
$entity = $creator->instantiateAndInitialize(Entity::class, $data);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

1821d ago

### Community

Maintainers

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

---

Top Contributors

[![drieschel](https://avatars.githubusercontent.com/u/852291?v=4)](https://github.com/drieschel "drieschel (8 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

PHPackages © 2026

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