Ignore:
Timestamp:
Feb 17, 2021, 12:30:23 PM (3 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Base.php

    r898 r899  
    11<?php
    2 
    3 class System
    4 {
    5   public Database $Database;
    6 
    7   function __construct()
    8   {
    9     $this->Database = new Database();
    10   }
    11 }
    122
    133class Base
    144{
    15   public Application $System;
     5  public System $System;
    166  public Database $Database;
    177
     
    2717  }
    2818}
    29 
    30 class Model extends Base
    31 {
    32 }
    33 
    34 class View extends Base
    35 {
    36 }
    37 
    38 class Controller extends Base
    39 {
    40 }
    41 
    42 class ModelDesc
    43 {
    44   public string $Name;
    45   public array $Columns;
    46   public array $Indices;
    47   public string $PrimaryKey;
    48   public bool $Memory;
    49 
    50   function __construct(string $Name)
    51   {
    52     $this->Name = $Name;
    53     $this->Columns = array();
    54     $this->Indices = array();
    55     $this->PrimaryKey = 'Id';
    56     $this->Memory = false;
    57   }
    58 
    59   function AddString(string $Name): ModelColumnString
    60   {
    61     $Result = new ModelColumnString($Name);
    62     $this->Columns[] = $Result;
    63     return $Result;
    64   }
    65 
    66   function AddFloat(string $Name): ModelColumnFloat
    67   {
    68     $Result = new ModelColumnFloat($Name);
    69     $this->Columns[] = $Result;
    70     return $Result;
    71   }
    72 
    73   function AddText(string $Name): ModelColumnText
    74   {
    75     $Result = new ModelColumnText($Name);
    76     $this->Columns[] = $Result;
    77     return $Result;
    78   }
    79 
    80   function AddInteger(string $Name): ModelColumnInteger
    81   {
    82     $Result = new ModelColumnInteger($Name);
    83     $this->Columns[] = $Result;
    84     return $Result;
    85   }
    86 
    87   function AddBigInt(string $Name): ModelColumnBigInt
    88   {
    89     $Result = new ModelColumnBigInt($Name);
    90     $this->Columns[] = $Result;
    91     return $Result;
    92   }
    93 
    94   function AddDateTime(string $Name): ModelColumnDateTime
    95   {
    96     $Result = new ModelColumnDateTime($Name);
    97     $this->Columns[] = $Result;
    98     return $Result;
    99   }
    100 
    101   function AddDate(string $Name): ModelColumnDate
    102   {
    103     $Result = new ModelColumnDate($Name);
    104     $this->Columns[] = $Result;
    105     return $Result;
    106   }
    107 
    108   function AddBoolean(string $Name): ModelColumnBoolean
    109   {
    110     $Result = new ModelColumnBoolean($Name);
    111     $this->Columns[] = $Result;
    112     return $Result;
    113   }
    114 
    115   function AddReference(string $Name, string $RefTable, bool $Nullable = true): ModelColumnReference
    116   {
    117     $Result = new ModelColumnReference($Name, $RefTable);
    118     $this->Columns[] = $Result;
    119     $Result->Nullable = $Nullable;
    120     return $Result;
    121   }
    122 
    123   function AddEnum(string $Name, array $States): ModelColumnEnum
    124   {
    125     $Result = new ModelColumnEnum($Name, $States);
    126     $this->Columns[] = $Result;
    127     return $Result;
    128   }
    129 
    130   function AddChangeAction(): void
    131   {
    132     $Column = $this->AddEnum('ChangeAction', array('add', 'modify', 'remove'));
    133     $Column->Nullable = true;
    134     $Column = $this->AddDateTime('ChangeTime');
    135     $Column->Nullable = true;
    136     $this->AddInteger('ChangeReplaceId');
    137   }
    138 }
    139 
    140 class ModelColumnType
    141 {
    142   const Integer = 0;
    143   const String = 1;
    144   const Float = 2;
    145   const Text = 3;
    146   const DateTime = 4;
    147   const Reference = 5;
    148   const Boolean = 6;
    149   const Date = 7;
    150   const Enum = 8;
    151   const BigInt = 9;
    152 
    153   static function GetName(int $Index)
    154   {
    155     $Text = array('Integer', 'String', 'Float', 'Text', 'DateTime', 'Reference', 'Boolean', 'Date', 'Enum', 'BigInt');
    156     return $Text[$Index];
    157   }
    158 }
    159 
    160 class ModelColumn
    161 {
    162   public string $Name;
    163   public int $Type; // ModelColumnType
    164   public bool $Nullable;
    165   public bool $Unique;
    166   public bool $HasDefault;
    167 
    168   function __construct(string $Name, int $Type, bool $Nullable = false, bool $Unique = false)
    169   {
    170     $this->Name = $Name;
    171     $this->Type = $Type;
    172     $this->Nullable = $Nullable;
    173     $this->Unique = $Unique;
    174     $this->HasDefault = false;
    175   }
    176 
    177   function GetDefault(): ?string
    178   {
    179     return null;
    180   }
    181 }
    182 
    183 class ModelColumnString extends ModelColumn
    184 {
    185   public ?string $Default;
    186 
    187   function __construct(string $Name)
    188   {
    189     parent::__construct($Name, ModelColumnType::String);
    190     $this->HasDefault = false;
    191     $this->Default = null;
    192   }
    193 
    194   function GetDefault(): ?string
    195   {
    196     return '"'.$this->Default.'"';
    197   }
    198 }
    199 
    200 class ModelColumnFloat extends ModelColumn
    201 {
    202   public ?float $Default;
    203 
    204   function __construct(string $Name)
    205   {
    206     parent::__construct($Name, ModelColumnType::Float);
    207     $this->HasDefault = false;
    208     $this->Default = null;
    209   }
    210 
    211   function GetDefault(): ?string
    212   {
    213     return '"'.$this->Default.'"';
    214   }
    215 }
    216 
    217 class ModelColumnText extends ModelColumn
    218 {
    219   public ?string $Default;
    220 
    221   function __construct(string $Name)
    222   {
    223     parent::__construct($Name, ModelColumnType::Text);
    224     $this->HasDefault = false;
    225     $this->Default = null;
    226   }
    227 
    228   function GetDefault(): ?string
    229   {
    230     return '"'.$this->Default.'"';
    231   }
    232 }
    233 
    234 class ModelColumnInteger extends ModelColumn
    235 {
    236   public ?int $Default;
    237 
    238   function __construct(string $Name)
    239   {
    240     parent::__construct($Name, ModelColumnType::Integer);
    241     $this->HasDefault = false;
    242     $this->Default = null;
    243   }
    244 
    245   function GetDefault(): ?string
    246   {
    247     return $this->Default;
    248   }
    249 }
    250 
    251 class ModelColumnBigInt extends ModelColumn
    252 {
    253   public ?int $Default;
    254 
    255   function __construct(string $Name)
    256   {
    257     parent::__construct($Name, ModelColumnType::BigInt);
    258     $this->HasDefault = false;
    259     $this->Default = null;
    260   }
    261 
    262   function GetDefault(): ?string
    263   {
    264     return $this->Default;
    265   }
    266 }
    267 
    268 class ModelColumnDateTime extends ModelColumn
    269 {
    270   public ?DateTime $Default;
    271 
    272   function __construct(string $Name)
    273   {
    274     parent::__construct($Name, ModelColumnType::DateTime);
    275     $this->HasDefault = false;
    276     $this->Default = null;
    277   }
    278 
    279   function GetDefault(): ?string
    280   {
    281     return '"'.$this->Default.'"';
    282   }
    283 }
    284 
    285 class ModelColumnDate extends ModelColumn
    286 {
    287   public ?DateTime $Default;
    288 
    289   function __construct(string $Name)
    290   {
    291     parent::__construct($Name, ModelColumnType::Date);
    292     $this->HasDefault = false;
    293     $this->Default = null;
    294   }
    295 
    296   function GetDefault(): ?string
    297   {
    298     return '"'.$this->Default.'"';
    299   }
    300 }
    301 
    302 class ModelColumnReference extends ModelColumn
    303 {
    304   public string $RefTable;
    305 
    306   function __construct(string $Name, string $RefTable)
    307   {
    308     parent::__construct($Name, ModelColumnType::Reference);
    309     $this->RefTable = $RefTable;
    310   }
    311 }
    312 
    313 class ModelColumnBoolean extends ModelColumn
    314 {
    315   public ?bool $Default;
    316 
    317   function __construct(string $Name)
    318   {
    319     parent::__construct($Name, ModelColumnType::Boolean);
    320     $this->HasDefault = false;
    321     $this->Default = null;
    322   }
    323 
    324   function GetDefault(): ?string
    325   {
    326     return $this->Default;
    327   }
    328 }
    329 
    330 class ModelColumnEnum extends ModelColumn
    331 {
    332   public ?bool $Default;
    333   public array $States;
    334 
    335   function __construct(string $Name, array $States)
    336   {
    337     parent::__construct($Name, ModelColumnType::Enum);
    338     $this->HasDefault = false;
    339     $this->Default = null;
    340     $this->States = $States;
    341   }
    342 
    343   function GetDefault(): ?string
    344   {
    345     return $this->Default;
    346   }
    347 }
Note: See TracChangeset for help on using the changeset viewer.