PHPackages                             kenny1911/populate - 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. kenny1911/populate

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

kenny1911/populate
==================

Library for automatic fill object properties from array or other object.

v1.0.2(3y ago)12.1kMITPHPPHP ^7.1 | ^8.0

Since Aug 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Kenny1911/populate)[ Packagist](https://packagist.org/packages/kenny1911/populate)[ Docs](https://github.com/Kenny1911/populate)[ RSS](/packages/kenny1911-populate/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (4)Versions (11)Used By (0)

PHP Populate
============

[](#php-populate)

`PHP Populate` is a library for fill attributes from source object to destination object.

For example, you can use this library to automatic fill properties from DTO to ORM entity.

Install
-------

[](#install)

```
composer require kenny1911/populate
```

Usage
-----

[](#usage)

### Simple usage

[](#simple-usage)

To fill in an object's fields with values from another object, use method `Kenny1911\Populate\PopulateInterface::populate()`. Arguments of method:

- `$src` - Source array or object from which values will be taken.
- `$dest` - Destination object.
- `$properties` - Array of allowed properties to be updated.
- `$ignoreProperties` - Array of denied properties not to be updated.
- `$mapping` - Key-value map to match property names from source object (`$src`) and destination object (`$dest`). Key - property name in `$src`, value - in `$dest`.

Use `PopulateBuilder` for creating new `PopulateInterface` instance:

```
use Kenny1911\Populate\PopulateBuilder;

$populate = PopulateBuilder::create()->build(); // Create new instance

class Src
{
    public $foo;
    public $bar;
    public $baz;
}

class Dest
{
    public $foo;
    public $bar;
    public $baz;
}

$src = new Src();
$src->foo = 'Foo';

$dest = new Dest();

$populate->populate(
    $src,               // Source object
    $dest,              // Destination object
    ['foo', 'bar'],     // Only properties `foo` and `bar` will be populated
    ['bar'],            // Property `bar` won't bw populated
    ['foo' => 'bar']    // Value of $src->foo will be set to $dest->bar
);

// $dest->bar === 'Foo';
```

### Advanced usage

[](#advanced-usage)

You may need to use it with preset settings of arguments `$properties`, `$ignoreProperties` and `$mapping`. You can use `AdvancedPopulate` for it:

```
use Kenny1911\Populate\PopulateBuilder;

$settings = [
    [
        'src' => 'Src',                 // Required
        'dest' => 'Dest',               // Required
        'properties' => ['foo', 'bar'], // Optional
        'ignore_properties' => ['bar'], // Optional
        'mapping' => ['foo' => 'bar']   // Optional
    ]
];

$populate = PopulateBuilder::create()->setSettings($settings)->build();

class Src
{
    public $foo;
    public $bar;
    public $baz;
}

class Dest
{
    public $foo;
    public $bar;
    public $baz;
}

$src = new Src();
$src->foo = 'Foo';

$dest = new Dest();

$populate->populate($src, $dest);

// $dest->bar === 'Foo';
```

> Preset settings won't use if you will use `$properties` and `$ignoreProperties` arguments.

> If you set `$mapping` argument, it will merge with preset mapping.

### Integrate with Symfony

[](#integrate-with-symfony)

1. Register bundle in `config/bundles.php`:

    ```
    return [
        // ...
        Kenny1911\Populate\Bridge\Symfony\PopulateBundle::class => ['all' => true]
        // ...
    ];
    ```
2. Create file `config/packages/populate.yaml`. Example:

    ```
    populate:
        settings:
            -   src: Src
                dest: Dest
                properties: [foo, bar]
                ignore_properties: [bar]
                mapping:
                    foo: bar
    ```

Now, you can inject `PopulateInterface` to your own services.

```
use Kenny1911\Populate\PopulateInterface;

class Service
{
    /** @var PopulateInterface */
    private $populate;

    public function __construct(PopulateInterface $populate)
    {
        $this->populate = $populate;
    }

    public function action($src, $dest)
    {
        $this->populate->populate($src, $dest);
    }
}
```

Also, you can use public symfony service `populate`:

```
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class Service implements ContainerAwareInterface
{
    use ContainerAwareTrait;

    public function action($src, $dest)
    {
        $populate = $this->container->get('populate');

        $populate->populate($src, $dest);
    }
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~169 days

Total

9

Last Release

1379d ago

Major Versions

v0.3.0 → v1.0.02020-11-19

PHP version history (2 changes)v0.1.0PHP ^7.1

v1.0.2PHP ^7.1 | ^8.0

### Community

Maintainers

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

---

Top Contributors

[![Kenny1911](https://avatars.githubusercontent.com/u/25887351?v=4)](https://github.com/Kenny1911 "Kenny1911 (113 commits)")

---

Tags

phparrayobjectdtofillpopulate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kenny1911-populate/health.svg)

```
[![Health](https://phpackages.com/badges/kenny1911-populate/health.svg)](https://phpackages.com/packages/kenny1911-populate)
```

PHPackages © 2026

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