PHP code example of kristijorgji / db-to-php

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

    

kristijorgji / db-to-php example snippets




return [
    'typeHint' => true,
    'databaseDriver' => 'mysql',
    'connection' => [
        'host' => '127.0.0.1',
        'port' => 3306,
        'database' => 'db_to_php',
        'username' => 'root',
        'password' => 'Test123@',
    ],
    'entities' => [
        'ludeGetters' => true,
        'fluentSetters' => true,
        'properties' => [
            'accessModifier' => \kristijorgji\DbToPhp\Rules\Php\PhpAccessModifiers::PRIVATE
        ]
    ],
    'factories' => [
        '

[
    'entities' => [
        'e' => [
            'test' => 'SuperEntity'
        ],
        'outputDirectory' => 'Entities',
        'namespace' => 'Entities',
        '        'accessModifier' => \kristijorgji\DbToPhp\Rules\Php\PhpAccessModifiers::PRIVATE
        ]
    ]
]



namespace Entities;

class UsersDemoEntity
{
    /**
     * @var int
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $surname;

    /**
     * @var string|null
     */
    private $preferences;

    /**
     * @var int
     */
    private $birthYear;

    /**
     * @var int
     */
    private $nrCars;

    /**
     * @var float
     */
    private $salary;

    /**
     * @var bool
     */
    private $active;

    /**
     * @var string
     */
    private $createdAt;

    /**
     * @param int $id
     * @return $this
     */
    public function setId(int $id)
    {
        $this->id = $id;
        return $this;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param string $name
     * @return $this
     */
    public function setName(string $name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @param string $surname
     * @return $this
     */
    public function setSurname(string $surname)
    {
        $this->surname = $surname;
        return $this;
    }

    /**
     * @return string
     */
    public function getSurname(): string
    {
        return $this->surname;
    }

    /**
     * @param string|null $preferences
     * @return $this
     */
    public function setPreferences(?string $preferences)
    {
        $this->preferences = $preferences;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getPreferences(): ?string
    {
        return $this->preferences;
    }

    /**
     * @param int $birthYear
     * @return $this
     */
    public function setBirthYear(int $birthYear)
    {
        $this->birthYear = $birthYear;
        return $this;
    }

    /**
     * @return int
     */
    public function getBirthYear(): int
    {
        return $this->birthYear;
    }

    /**
     * @param int $nrCars
     * @return $this
     */
    public function setNrCars(int $nrCars)
    {
        $this->nrCars = $nrCars;
        return $this;
    }

    /**
     * @return int
     */
    public function getNrCars(): int
    {
        return $this->nrCars;
    }

    /**
     * @param float $salary
     * @return $this
     */
    public function setSalary(float $salary)
    {
        $this->salary = $salary;
        return $this;
    }

    /**
     * @return float
     */
    public function getSalary(): float
    {
        return $this->salary;
    }

    /**
     * @param bool $active
     * @return $this
     */
    public function setActive(bool $active)
    {
        $this->active = $active;
        return $this;
    }

    /**
     * @return bool
     */
    public function getActive(): bool
    {
        return $this->active;
    }

    /**
     * @param string $createdAt
     * @return $this
     */
    public function setCreatedAt(string $createdAt)
    {
        $this->createdAt = $createdAt;
        return $this;
    }

    /**
     * @return string
     */
    public function getCreatedAt(): string
    {
        return $this->createdAt;
    }
}


'factories' => [
        'toryClassName' => [
            'test' => 'SuperEntityFactory'
        ],
        'outputDirectory' => 'Factories/Entities',
        'namespace' => 'Factories\Entities',
        '



namespace Factories\Entities;

use Entities\UsersDemoEntity;

class UsersDemoEntityFactory extends AbstractEntityFactory
{
    /**
     * @param array $data
     * @return UsersDemoEntity
     */
    public static function make(array $data = []): UsersDemoEntity
    {
        return self::makeFromData(self::makeData($data));
    }
   
    /**
     * @param array $data
     * @return UsersDemoEntity
     */
    public static function makeFromData(array $data): UsersDemoEntity
    {
        return self::mapArrayToEntity($data, UsersDemoEntity::class);
    }
 
    /**
     * @param array $data
     * @return array
     */
    public static function makeData(array $data = []): array
    {
        return [
            'id' => $data['id'] ?? self::randomInt64(),
            'name' => $data['name'] ?? self::randomString(rand(0, 20)),
            'surname' => $data['surname'] ?? self::randomString(rand(0, 20)),
            'preferences' => $data['preferences'] ?? self::randomJson(),
            'birth_year' => $data['birth_year'] ?? self::randomYear(4),
            'nr_cars' => $data['nr_cars'] ?? self::randomUnsignedInt8(),
            'salary' => $data['salary'] ?? self::randomFloat(4),
            'active' => $data['active'] ?? self::randomBoolean(),
            'created_at' => $data['created_at'] ?? self::randomDate('Y-m-d H:i:s'),
        ];
    }
}


/**
 * @param array $data
 * @return TestEntity
 */
public static function make(array $data = []): TestEntity
{
    return self::makeFromData(self::makeData($data));
}

/**
 * @param array $data
 * @return TestEntity
 */
public static function make()
{
    return self::makeFromData(self::makeData($data));
}