PHP code example of kabunx / hydrate

1. Go to this page and download the library: Download kabunx/hydrate 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/ */

    

kabunx / hydrate example snippets



declare(strict_types=1);

namespace App\Entities;

use Carbon\Carbon;
use Kabunx\Hydrate\Entity;
use Kabunx\Hydrate\Column;

/**
 * Class UserEntity
 * @package App\Entities
 */
class UserEntity extends Entity
{
    public string $name = '';

    public string $email = '';

    public int $gender = 0;

    public string $birthday = '';

    public ?Carbon $createdAt;

     #[Column(source: "modifiedAt")]
    public ?Carbon $updatedAt;


    /**
     * @param string $value
     * @return int
     */
    public function setGender(string $value): int
    {
        return $value == 'm' ? 0 : 1;
    }
}


use App\Entities\UserEntity;

$users = [
    'id' => 1,
    'name' => 'test01',
    'email' => '[email protected]',
    'gender' => 'm',
    'birthday' => '2000-10-01',
    'createdAt' => '2021-07-23',
    'modifiedAt' => '2021-07-23 12:05:10'
];

UserEntity::instance($users);


php: ^8.0