1. Go to this page and download the library: Download touki/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.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
touki / populator example snippets
useTouki\Populator\Populator;
$populator = new Populator;
useTouki\Populator\Populator;
useTouki\Populator\Hydrator;
useTouki\Populator\HydratorContextFactory;
useDoctrine\Common\Annotations\AnnotationReader;
/**
* You can instanciate your own as long as it implements HydratorInterface
*/
$hydrator = new Hydrator;
/**
* You can instanciate your own as long as it implements HydratorContextFactoryInterface
* The default one accepts Any Doctrine's Annotation Reader (Like FileCacheReader)
*
* @see https://github.com/doctrine/annotations/tree/master/lib/Doctrine/Common/Annotations
*/
$factory = new HydratorContextFactory(new AnnotationReader);
$populator = new Populator($hydrator, $factory);
namespaceAcme\Model\Foo;
classFoo{
protected $bar;
public $public;
public $publicWithSetter;
publicfunctionsetBar($bar){
$this->bar = $bar;
}
publicfunctiongetBar(){
return$this->bar;
}
publicfunctionsetPublicWithSetter($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';
$newFoo = $populator->populate($data, $foo);
echo $newFoo->getBar(); // Foobaz!echo $newFoo->public; // Public!echo $newFoo->publicWithSetter; // BySetter