sf4/populator

Populator is a simple Array-To-Object library which transforms arrays into a given object

v1.1.8 2019-02-04 14:47 UTC

This package is not auto-updated.

Last update: 2024-12-17 19:46:03 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Populator is a simple Array-To-Object library which transforms arrays into a given object

Structure

If any of the following are applicable to your project, then the directory structure should follow industry best practices by being named the following.

bin/        
config/
src/
tests/
vendor/

Install

Via Composer

$ composer require sf4/populator

Usage

namespace Acme\Model;

class Foo
{
    protected $bar;
    public $public;
    public $publicWithSetter;

    public function setBar($bar)
    {
        $this->bar = $bar;
    }

    public function getBar()
    {
        return $this->bar;
    }

    public function setPublicWithSetter($var)
    {
        $this->publicWithSetter = $var;
    }
}

$data = array(
    'bar' => 'Foobaz!',
    'public' => 'Public!'
    'publicWithSetter' => 'BySetter'
);

/**
 * You can give either classname or an instance
 */
$foo = new Acme\Model\Foo();
$foo = 'Acme\Model\Foo';

$populator = new Sf4\Populator();
$newFoo = $populator->populate($data, $foo);

echo $newFoo->getBar();         // Foobaz!
echo $newFoo->public;           // Public!
echo $newFoo->publicWithSetter; // BySetter

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email siim.liimand@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.