Populator is a simple Array-To-Object library which transforms arrays into a given object
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/
Via Composer
$ composer require sf4/populator
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
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email siim.liimand@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.