PHP code example of siburuxue / doctrine-helper

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

    

siburuxue / doctrine-helper example snippets


// src/Entity/Test.php
namespace App\Entity;

use App\Repository\TestRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Table(name: 'test')]
#[ORM\UniqueConstraint(name: 'I_int_2', columns: ['int_2'])]
#[ORM\Index(name: 'I_int_1', columns: ['int_1'])]
#[ORM\Index(name: 'I_int_3', columns: ['int_3', 'int_4', 'int_5'])]
#[ORM\Index(name: 'I_int_4', columns: ['int_6'])]
#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
    #[ORM\Column(name: "int_5", type: Types::BIGINT, options: ["comment" => "bigint"])]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: "NONE")]
    private ?string $int5 = null;

    #[ORM\Column(name: "id")]
    private ?int $id = null;

    #[ORM\Column(name: "int_1", options: ["comment" => "int", "default" => 1])]
    private ?int $int1 = 1;

    #[ORM\Column(name: "int_2", type: Types::SMALLINT, nullable: true, options: ["comment" => "smallint", "default" => 2])]
    private ?int $int2 = 2;

    #[ORM\Column(name: "int_3", nullable: true, options: ["comment" => "tinyint", "default" => 3])]
    private ?int $int3 = 3;

    #[ORM\Column(name: "int_4", nullable: true, options: ["comment" => "mediumint", "default" => 4])]
    private ?int $int4 = 4;

    #[ORM\Column(name: "int_6", nullable: true, options: ["comment" => "float", "default" => 6])]
    private ?float $int6 = 6;

    #[ORM\Column(name: "int_7", nullable: true, options: ["comment" => "double", "default" => 7])]
    private ?float $int7 = 7;

    #[ORM\Column(name: "int_8", type: Types::DECIMAL, precision: 10, scale: 0, nullable: true, options: ["comment" => "decimal", "default" => 8])]
    private ?string $int8 = '8';

    #[ORM\Column(name: "date_1", type: Types::DATE_MUTABLE, nullable: true, options: ["comment" => "date", "default" => 'curdate()'])]
    private ?\DateTimeInterface $date1 = null;

    #[ORM\Column(name: "date_2", type: Types::TIME_MUTABLE, nullable: true, options: ["comment" => "time", "default" => 'curtime()'])]
    private ?\DateTimeInterface $date2 = null;

    #[ORM\Column(name: "date_3", type: Types::DATETIME_MUTABLE, nullable: true, options: ["comment" => "datetime", "default" => 'now()'])]
    private ?\DateTimeInterface $date3 = null;

    #[ORM\Column(name: "date_4", type: Types::DATETIME_MUTABLE, nullable: true, options: ["comment" => "timestamp", "default" => 'now()'])]
    private ?\DateTimeInterface $date4 = null;

    #[ORM\Column(name: "date_5", type: Types::DATETIME_MUTABLE, nullable: true, options: ["comment" => "year", "default" => 'now()'])]
    private ?\DateTimeInterface $date5 = null;

    #[ORM\Column(name: "str_1", length: 1, nullable: true, options: ["comment" => "char", "fixed" => true, "default" => 'a'])]
    private ?string $str1 = 'a';

    #[ORM\Column(name: "str_2", length: 255, nullable: true, options: ["comment" => "varchar(255)", "default" => 'b'])]
    private ?string $str2 = 'b';

    #[ORM\Column(name: "str_3", type: Types::BINARY, length: 1, nullable: true, options: ["comment" => "binary", "default" => '0x63'])]
    private $str3 = 0x63;

    #[ORM\Column(name: "str_4", type: Types::BINARY, length: 1, nullable: true, options: ["comment" => "varbinary(1)", "default" => '0x64'])]
    private $str4 = 0x64;

    #[ORM\Column(name: "str_8", type: Types::SIMPLE_ARRAY, nullable: true, options: ["comment" => "set", "default" => 'a,b'])]
    private ?array $str8 = ["a","b"];

    #[ORM\Column(name: "json_1", nullable: true, options: ["comment" => "json"])]
    private ?array $json1 = null;

    #[ORM\Column(name: "bool_1", nullable: true, options: ["comment" => "bool", "default" => 0])]
    private ?int $bool1 = 0;

    // ...getter and setter
}