Ignore:
Timestamp:
Dec 22, 2020, 11:34:19 PM (3 years ago)
Author:
chronos
Message:
  • Added: Install and uninstall modules models persistence using abstract classes.
File:
1 edited

Legend:

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

    r887 r889  
    2525class Model extends Base
    2626{
    27 
    2827}
    2928
    3029class View extends Base
    3130{
    32 
    3331}
    3432
    3533class Controller extends Base
    3634{
     35}
    3736
     37class ModelDesc
     38{
     39  public string $Name;
     40  public bool $Nullable;
     41  public array $Columns;
     42  public array $Indices;
     43  public string $PrimaryKey;
     44  public bool $Unique;
     45  public bool $HasDefault;
     46
     47  function __construct(string $Name, bool $Nullable = false, bool $Unique = false)
     48  {
     49    $this->Name = $Name;
     50    $this->Columns = array();
     51    $this->Nullable = $Nullable;
     52    $this->PrimaryKey = 'Id';
     53    $this->Unique = $Unique;
     54  }
     55
     56  function AddString(string $Name): ModelColumnString
     57  {
     58    $Result = new ModelColumnString($Name);
     59    $this->Columns[] = $Result;
     60    return $Result;
     61  }
     62
     63  function AddInteger(string $Name): ModelColumnInteger
     64  {
     65    $Result = new ModelColumnInteger($Name);
     66    $this->Columns[] = $Result;
     67    return $Result;
     68  }
     69
     70  function AddDateTime(string $Name): ModelColumnDateTime
     71  {
     72    $Result = new ModelColumnDateTime($Name);
     73    $this->Columns[] = $Result;
     74    return $Result;
     75  }
     76
     77  function AddReference(string $Name, string $RefTable): ModelColumnReference
     78  {
     79    $Result = new ModelColumnReference($Name, $RefTable);
     80    $this->Columns[] = $Result;
     81    return $Result;
     82  }
    3883}
     84
     85class ModelColumnType
     86{
     87  const Integer = 0;
     88  const String = 1;
     89  const Float = 2;
     90  const Text = 3;
     91  const DateTime = 4;
     92  const Reference = 5;
     93}
     94
     95class ModelColumn
     96{
     97  public string $Name;
     98  public ModelColumnType $Type;
     99  public
     100
     101  function __construct(string $Name, int $Type)
     102  {
     103    $this->Name = $Name;
     104    $this->Type = $Type;
     105  }
     106
     107  function GetDefault(): ?string
     108  {
     109    return null;
     110  }
     111}
     112
     113class ModelColumnString extends ModelColumn
     114{
     115  public ?string $Default;
     116
     117  function __construct(string $Name)
     118  {
     119    parent::__construct($Name, ModelColumnType::String);
     120    $this->HasDefault = false;
     121    $this->Default = null;
     122  }
     123
     124  function GetDefault(): ?string
     125  {
     126    return '"'.$this->Default.'"';
     127  }
     128}
     129
     130class ModelColumnText extends ModelColumn
     131{
     132  public ?string $Default;
     133
     134  function __construct(string $Name)
     135  {
     136    parent::__construct($Name, ModelColumnType::Text);
     137    $this->HasDefault = false;
     138    $this->Default = null;
     139  }
     140
     141  function GetDefault(): ?string
     142  {
     143    return '"'.$this->Default.'"';
     144  }
     145}
     146
     147class ModelColumnInteger extends ModelColumn
     148{
     149  public ?int $Default;
     150
     151  function __construct(string $Name)
     152  {
     153    parent::__construct($Name, ModelColumnType::Integer);
     154    $this->HasDefault = false;
     155    $this->Default = null;
     156  }
     157
     158  function GetDefault(): ?string
     159  {
     160    return $this->Default;
     161  }
     162}
     163
     164class ModelColumnDateTime extends ModelColumn
     165{
     166  public ?DateTime $Default;
     167
     168  function __construct(string $Name)
     169  {
     170    parent::__construct($Name, ModelColumnType::DateTime);
     171    $this->HasDefault = false;
     172    $this->Default = null;
     173  }
     174
     175  function GetDefault(): ?string
     176  {
     177    return '"'.$this->Default.'"';
     178  }
     179}
     180
     181class ModelColumnReference extends ModelColumn
     182{
     183  public string $RefTable;
     184
     185  function __construct(string $Name, string $RefTable)
     186  {
     187    parent::__construct($Name, ModelColumnType::Reference);
     188    $this->RefTable = $RefTable;
     189  }
     190}
Note: See TracChangeset for help on using the changeset viewer.