PHPackages                             nikolas-lada/reflection-factory - 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. nikolas-lada/reflection-factory

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

nikolas-lada/reflection-factory
===============================

The tiny Factory static class which loads parameters and injects them into constructors by reflection.

v1.0.0(6y ago)08GPL-2.0PHPPHP &gt;= 7.1

Since Mar 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nikolaslada/reflection-factory)[ Packagist](https://packagist.org/packages/nikolas-lada/reflection-factory)[ RSS](/packages/nikolas-lada-reflection-factory/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Reflection factory - repeat your code less!
===========================================

[](#reflection-factory---repeat-your-code-less)

The factory class which loads parameters and injects them into constructors by reflection.

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

[](#installation)

```
composer require nikolas-lada/reflection-factory
```

It requires PHP version 7.1+.

Usage
-----

[](#usage)

For \\stdClass:

```
use \NikolasLada\ReflectionFactory\ReflectionFactory;

$data = new \stdClass;

/**
 * no matter of property order
 */
$data->created = '2018-03-20 12:00:00';
$data->id = 1;
$data->updated = \null;

$beforeCreate = function() use ($data) {
  $data->created = new \DateTime($data->created);

  if (!\is_null($data->updated)) {
    $data->updated = new \DateTime($data->updated);
  }

  return $data;
};

$article = ReflectionFactory::createFromStdClass(
    \NikolasLada\ReflectionFactory\Tests\Domain\Article::class,
    $data,
    $beforeCreate
);

// or

$article = ReflectionFactory::create(
    \NikolasLada\ReflectionFactory\Tests\Domain\Article::class,
    $data,
    $beforeCreate
);
```

For array:

```
use \NikolasLada\ReflectionFactory\ReflectionFactory;

$data = [];

/**
 * The createFromArray method depends on order items in array!
 */
$data['id'] = 1;
$data['created'] = '2018-03-20 12:00:00';
$data['updated'] = '2018-03-20 12:01:13';

$data['created'] = new \DateTime($data['created']);

if (!\is_null($data['updated'])) {
  $data['updated'] = new \DateTime($data['updated']);
}

$article = ReflectionFactory::createFromArray(
    \NikolasLada\ReflectionFactory\Tests\Domain\Article::class,
    $data
);

// or

$beforeCreate = function() use ($data) {
  $data['created'] = new \DateTime($data['created']);

  return $data;
};

$article = ReflectionFactory::create(
    \NikolasLada\ReflectionFactory\Tests\Domain\Article::class,
    $data,
    $beforeCreate
);
```

License
-------

[](#license)

The Reflection factory library is open-sourced software licensed under:

- [GNU GPL 2.0](https://opensource.org/licenses/GPL-2.0),
- [GNU GPL 3.0](https://opensource.org/licenses/GPL-3.0),
- [GNU LGPL 3.0](https://opensource.org/licenses/LGPL-3.0) and
- [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~683 days

Total

2

Last Release

2239d ago

Major Versions

0.0.0 → v1.0.02020-02-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/4da1eb2fa72fc311d62e5dc002aea70ff6ad03b6d0008f9fbe4448d137d1501e?d=identicon)[nikolas-lada](/maintainers/nikolas-lada)

---

Top Contributors

[![nikolaslada](https://avatars.githubusercontent.com/u/11044967?v=4)](https://github.com/nikolaslada "nikolaslada (18 commits)")

---

Tags

factoryreflectionutil

### Embed Badge

![Health badge](/badges/nikolas-lada-reflection-factory/health.svg)

```
[![Health](https://phpackages.com/badges/nikolas-lada-reflection-factory/health.svg)](https://phpackages.com/packages/nikolas-lada-reflection-factory)
```

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k289.0M2.2k](/packages/symfony-property-access)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12619.7M88](/packages/phpdocumentor-reflection)[php-di/phpdoc-reader

PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)

7731.1M52](/packages/php-di-phpdoc-reader)[minime/annotations

The KISS PHP annotations library

233374.8k34](/packages/minime-annotations)[jansenfelipe/utils

Uma simples classe utilitária com métodos que podem salvar sua vida (ou não)

66144.1k10](/packages/jansenfelipe-utils)[thecodingmachine/class-explorer

Find the list of all your classes and more.

122.0M2](/packages/thecodingmachine-class-explorer)

PHPackages © 2026

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