PHP code example of widefocus / magento-zend-hydrator-adapter

1. Go to this page and download the library: Download widefocus/magento-zend-hydrator-adapter 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/ */

    

widefocus / magento-zend-hydrator-adapter example snippets



namespace Foo\Model;

use Foo\Api\Data\FooModelInterface;

class FooModel implements FooModelInterface
{
    private $date;
    
    public function setDate(DateTimeInterface $date)
    {
        $this->date = $date;
    }
    
    public function getDate(): DateTimeInterface
    {
        return $this->date;
    }
}




namespace Foo\Controller;

use Magento\Framework\EntityManager\HydratorPool;
use Foo\Api\Data\FooModelInterface;
use Foo\Model\FooModel;

class Save
{
    private $hydratorPool;
    
    public function __construct(HydratorPool $hydratorPool)
    {
        $this->hydratorPool = $hydratorPool;
    }
    
    public function execute()
    {
        $model = new FooModel();
        $this->hydratorPool
            ->getHydrator(FooModelInterface::class)
            ->hydrate($model, ['date' => '2025-12-31 23:59:59']);
    }
}