PHP code example of sf4 / populator
1. Go to this page and download the library: Download sf4/populator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sf4 / populator example snippets
php
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