Changeset 887 for trunk/Packages/Common


Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (4 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
Location:
trunk/Packages/Common
Files:
16 edited

Legend:

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

    r880 r887  
    3636class AppModule
    3737{
    38   var $Id;
    39   var $Name;
    40   var $Title;
    41   var $Version;
    42   var $License;
    43   var $Creator;
    44   var $HomePage;
    45   var $Description;
    46   var $Running;
    47   var $Enabled;
    48   var $Installed;
    49   var $InstalledVersion;
    50   /** @var ModuleType */
    51   var $Type;
    52   var $Dependencies;
    53   /** @var Database */
    54   var $Database;
    55   /** @var System */
    56   var $System;
    57   /** @var AppModuleManager */
    58   var $Manager;
    59   var $OnChange;
    60 
    61   function __construct(System $System)
     38  public int $Id;
     39  public string $Name;
     40  public string $Title;
     41  public string $Version;
     42  public string $License;
     43  public string $Creator;
     44  public string $HomePage;
     45  public string $Description;
     46  public bool $Running;
     47  public bool $Enabled;
     48  public bool $Installed;
     49  public string $InstalledVersion;
     50  public int $Type;
     51  public array $Dependencies;
     52  public Database $Database;
     53  public Application $System;
     54  public AppModuleManager $Manager;
     55  public $OnChange;
     56  public array $Models;
     57
     58  function __construct(Application $System)
    6259  {
    6360    $this->System = &$System;
     
    7370    $this->Dependencies = array();
    7471    $this->Type = ModuleType::Normal;
    75   }
    76 
    77   function Install()
     72    $this->Models = array();
     73  }
     74
     75  function Install(): void
    7876  {
    7977    if ($this->Installed) return;
     
    8785  }
    8886
    89   function Uninstall()
     87  function Uninstall(): void
    9088  {
    9189    if (!$this->Installed) return;
     
    9896  }
    9997
    100   function Upgrade()
     98  function Upgrade(): void
    10199  {
    102100    if (!$this->Installed) return;
     
    108106  }
    109107
    110   function Reinstall()
     108  function Reinstall(): void
    111109  {
    112110    $this->Uninstall();
     
    115113  }
    116114
    117   function Start()
     115  function Start(): void
    118116  {
    119117    if ($this->Running) return;
     
    126124  }
    127125
    128   function Stop()
     126  function Stop(): void
    129127  {
    130128    if (!$this->Running) return;
     
    136134  }
    137135
    138   function Restart()
     136  function Restart(): void
    139137  {
    140138    $this->Stop();
     
    142140  }
    143141
    144   function Enable()
     142  function Enable(): void
    145143  {
    146144    if ($this->Enabled) return;
     
    152150  }
    153151
    154   function Disable()
     152  function Disable(): void
    155153  {
    156154    if (!$this->Enabled) return;
     
    162160  }
    163161
    164   protected function DoStart()
    165   {
    166   }
    167 
    168   protected function DoStop()
    169   {
    170   }
    171 
    172   protected function DoInstall()
    173   {
    174   }
    175 
    176   protected function DoUninstall()
    177   {
    178   }
    179 
    180   protected function DoUpgrade()
    181   {
    182 
     162  protected function DoStart(): void
     163  {
     164  }
     165
     166  protected function DoStop(): void
     167  {
     168  }
     169
     170  protected function DoInstall(): void
     171  {
     172  }
     173
     174  protected function DoUninstall(): void
     175  {
     176  }
     177
     178  protected function DoUpgrade(): void
     179  {
     180  }
     181
     182  function AddModel(Model $Model): void
     183  {
     184    $this->Models[get_class($Model)] = $Model;
    183185  }
    184186}
     
    187189class AppModuleManager
    188190{
    189   var $Modules;
    190   var $System;
    191   var $FileName;
    192   var $ModulesDir;
    193   var $OnLoadModules;
     191  public array $Modules;
     192  public System $System;
     193  public string $FileName;
     194  public string $ModulesDir;
     195  public $OnLoadModules;
    194196
    195197  function __construct(System $System)
     
    201203  }
    202204
    203   function Perform($List, $Actions, $Conditions = array(ModuleCondition::All))
     205  function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void
    204206  {
    205207    foreach ($List as $Index => $Module)
     
    227229  }
    228230
    229   function EnumDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
     231  function EnumDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All))
    230232  {
    231233    foreach ($Module->Dependencies as $Dependency)
     
    248250  }
    249251
    250   function EnumSuperiorDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
     252  function EnumSuperiorDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All))
    251253  {
    252254    foreach ($this->Modules as $RefModule)
     
    267269  }
    268270
    269   function Start()
     271  function Start(): void
    270272  {
    271273    $this->LoadModules();
     
    274276  }
    275277
    276   function StartAll()
     278  function StartAll(): void
    277279  {
    278280    $this->Perform($this->Modules, array(ModuleAction::Start));
    279281  }
    280282
    281   function StartEnabled()
     283  function StartEnabled(): void
    282284  {
    283285    $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled));
    284286  }
    285287
    286   function StopAll()
     288  function StopAll(): void
    287289  {
    288290    $this->Perform($this->Modules, array(ModuleAction::Stop));
    289291  }
    290292
    291   function InstallAll()
     293  function InstallAll(): void
    292294  {
    293295    $this->Perform($this->Modules, array(ModuleAction::Install));
     
    295297  }
    296298
    297   function UninstallAll()
     299  function UninstallAll(): void
    298300  {
    299301    $this->Perform($this->Modules, array(ModuleAction::Uninstall));
     
    301303  }
    302304
    303   function EnableAll()
     305  function EnableAll(): void
    304306  {
    305307    $this->Perform($this->Modules, array(ModuleAction::Enable));
     
    307309  }
    308310
    309   function DisableAll()
     311  function DisableAll(): void
    310312  {
    311313    $this->Perform($this->Modules, array(ModuleAction::Disable));
     
    313315  }
    314316
    315   function ModulePresent($Name)
     317  function ModulePresent(string $Name): bool
    316318  {
    317319    return array_key_exists($Name, $this->Modules);
    318320  }
    319321
    320   function ModuleEnabled($Name)
     322  function ModuleEnabled(string $Name): bool
    321323  {
    322324    return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Enabled;
    323325  }
    324326
    325   function ModuleRunning($Name)
     327  function ModuleRunning(string $Name): bool
    326328  {
    327329    return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Running;
    328330  }
    329331
    330   /* @return Module */
    331   function SearchModuleById($Id)
     332  function GetModule(string $Name): AppModule
     333  {
     334    return $this->Modules[$Name];
     335  }
     336
     337  function SearchModuleById(int $Id): string
    332338  {
    333339    foreach ($this->Modules as $Module)
     
    339345  }
    340346
    341   function LoadState()
     347  function LoadState(): void
    342348  {
    343349    $ConfigModules = array();
     
    355361  }
    356362
    357   function SaveState()
     363  function SaveState(): void
    358364  {
    359365    $Data = array();
     
    369375  }
    370376
    371   function RegisterModule(AppModule $Module)
     377  function RegisterModule(AppModule $Module): void
    372378  {
    373379    $this->Modules[$Module->Name] = &$Module;
     
    376382  }
    377383
    378   function UnregisterModule(AppModule $Module)
     384  function UnregisterModule(AppModule $Module): void
    379385  {
    380386    unset($this->Modules[array_search($Module, $this->Modules)]);
    381387  }
    382388
    383   function LoadModulesFromDir($Directory)
     389  function LoadModulesFromDir(string $Directory): void
    384390  {
    385391    $List = scandir($Directory);
     
    395401  }
    396402
    397   function LoadModules()
     403  function LoadModules(): void
    398404  {
    399405    if (is_array($this->OnLoadModules) and (count($this->OnLoadModules) == 2) and method_exists($this->OnLoadModules[0], $this->OnLoadModules[1]))
    400       $this->OnLoadModules();
     406      call_user_func($this->OnLoadModules);
    401407    else $this->LoadModulesFromDir($this->ModulesDir);
    402408  }
  • trunk/Packages/Common/Application.php

    r873 r887  
    33class ModelDef
    44{
    5   var $OnChange;
    6  
     5  public array $OnChange;
     6
    77  function __construct()
    88  {
    99    $this->OnChange = array();
    1010  }
    11  
    12   function DoOnChange()
     11
     12  function DoOnChange(): void
    1313  {
    1414    foreach ($this->OnChange as $Callback)
     
    1717    }
    1818  }
    19  
    20   function RegisterOnChange($SysName, $Callback)
     19
     20  function RegisterOnChange(string $SysName, callable $Callback): void
    2121  {
    2222    $this->OnChange[$SysName] = $Callback;
    2323  }
    24  
    25   function UnregisterOnChange($SysName)
     24
     25  function UnregisterOnChange(string $SysName): void
    2626  {
    2727    unset($this->OnChange[$SysName]);
     
    2929}
    3030
     31class Command
     32{
     33  public string $Name;
     34  public string $Description;
     35  public $Callback;
     36
     37  function __construct(string $Name, string $Description, callable $Callback)
     38  {
     39    $this->Name = $Name;
     40    $this->Description = $Description;
     41    $this->Callback = $Callback;
     42  }
     43}
     44
    3145class Application extends System
    3246{
    33   var $Name;
    34   /** @var AppModuleManager */
    35   var $ModuleManager;
    36   var $Modules;
    37   var $Models;
    38  
     47  public string $Name;
     48  public AppModuleManager $ModuleManager;
     49  public array $Models;
     50  public array $CommandLine;
     51  public array $Pages;
     52
    3953  function __construct()
    4054  {
     
    4256    $this->Name = 'Application';
    4357    $this->ModuleManager = new AppModuleManager($this);
    44     $this->Modules = array();
    4558    $this->Models = array();
     59    $this->CommandLine = array();
     60    $this->Pages = array();
     61
     62    $this->RegisterCommandLine('list', 'Prints available commands', array($this, 'ListCommands'));
    4663  }
    47  
    48   function RegisterModel($SysName, $Model)
     64
     65  function GetModule(string $Name): AppModule
     66  {
     67    return $this->ModuleManager->Modules[$Name];
     68  }
     69
     70  function RegisterModel(string $SysName, array $Model): void
    4971  {
    5072    $NewModelDef = new ModelDef();
     
    5375  }
    5476
    55   function UnregisterModel($SysName)
     77  function UnregisterModel(string $SysName): void
    5678  {
    5779    unset($this->Models[$SysName]);
    5880  }
    59  
    60   function Run()
     81
     82  function RegisterCommandLine(string $Name, string $Description, callable $Callback): void
    6183  {
     84    $this->CommandLine[$Name] = new Command($Name, $Description, $Callback);
     85  }
    6286
     87  function UnrgisterCommandLine(string $Name): void
     88  {
     89    unset($this->CommandLine[$Name]);
     90  }
     91
     92  function ListCommands(array $Parameters)
     93  {
     94    $Output = 'Available commands:'."\n";
     95    foreach ($this->CommandLine as $Command)
     96    {
     97      $Output .= ' '.$Command->Name.' - '.$Command->Description."\n";
     98    }
     99    echo($Output."\n");
     100  }
     101
     102  function RegisterPage(array $Path, string $Handler): void
     103  {
     104    $Page = &$this->Pages;
     105    $LastKey = array_pop($Path);
     106    foreach ($Path as $PathItem)
     107    {
     108      $Page = &$Page[$PathItem];
     109    }
     110    if (!is_array($Page)) $Page = array('' => $Page);
     111    $Page[$LastKey] = $Handler;
     112  }
     113
     114  function UnregisterPage(array $Path): void
     115  {
     116    $Page = &$this->Pages;
     117    $LastKey = array_pop($Path);
     118    foreach ($Path as $PathItem)
     119    {
     120      $Page = &$Page[$PathItem];
     121    }
     122    unset($Page[$LastKey]);
     123  }
     124
     125  function Run(): void
     126  {
     127  }
     128
     129  function Link(string $Target): string
     130  {
     131    return $Target;
    63132  }
    64133}
  • trunk/Packages/Common/Base.php

    r790 r887  
    33class System
    44{
    5   /* @var Database */
    6   var $Database;
     5  public Database $Database;
    76
    87  function __construct()
     
    1413class Base
    1514{
    16   /** @var Application */
    17   var $System;
    18   /* @var Database */
    19   var $Database;
     15  public Application $System;
     16  public Database $Database;
    2017
    21   function __construct(Application $System)
     18  function __construct(System $System)
    2219  {
    2320    $this->System = &$System;
  • trunk/Packages/Common/Common.php

    r874 r887  
    2626class PackageCommon
    2727{
    28   var $Name;
    29   var $Version;
    30   var $ReleaseDate;
    31   var $License;
    32   var $Creator;
    33   var $Homepage;
     28  public string $Name;
     29  public string $Version;
     30  public int $ReleaseDate;
     31  public string $License;
     32  public string $Creator;
     33  public string $Homepage;
    3434
    3535  function __construct()
     
    4646class Paging
    4747{
    48   var $TotalCount;
    49   var $ItemPerPage;
    50   var $Around;
    51   var $SQLLimit;
    52   var $Page;
     48  public int $TotalCount;
     49  public int $ItemPerPage;
     50  public int $Around;
     51  public string $SQLLimit;
     52  public int $Page;
    5353
    5454  function __construct()
     
    6060  }
    6161
    62   function Show()
     62  function Show(): string
    6363  {
    6464    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
  • trunk/Packages/Common/Database.php

    r874 r887  
    22
    33// Extended database class
    4 // Date: 2016-01-11
     4// Date: 2020-11-10
    55
    66function microtime_float()
     
    1313{
    1414  var $PDOStatement;
    15   var $num_rows = 0;
     15  public int $num_rows = 0;
    1616
    1717  function fetch_assoc()
     
    3333class Database
    3434{
    35   var $Prefix;
    36   var $Functions;
    37   var $Type;
    38   var $PDO;
    39   var $Error;
    40   var $insert_id;
    41   var $LastQuery;
    42   var $ShowSQLError;
    43   var $ShowSQLQuery;
    44   var $LogSQLQuery;
    45   var $LogFile;
     35  public string $Prefix;
     36  public array $Functions;
     37  public string $Type;
     38  public PDO $PDO;
     39  public string $Error;
     40  public string $insert_id;
     41  public string $LastQuery;
     42  public bool $ShowSQLError;
     43  public bool $ShowSQLQuery;
     44  public bool $LogSQLQuery;
     45  public string $LogFile;
    4646
    4747  function __construct()
     
    5757    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    5858  }
    59  
    60 
    61   function Connect($Host, $User, $Password, $Database)
     59
     60  function Connect(string $Host, string $User, string $Password, string $Database)
    6261  {
    6362    if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
     
    7978  }
    8079
    81   function Connected()
     80  function Connected(): bool
    8281  {
    8382    return isset($this->PDO);
    8483  }
    8584
    86   function select_db($Database)
     85  function select_db(string $Database)
    8786  {
    8887    $this->query('USE `'.$Database.'`');
    8988  }
    9089
    91   function query($Query)
     90  function query($Query): DatabaseResult
    9291  {
    9392    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
     
    9998      $Time = round(microtime_float() - $QueryStartTime, 4);
    10099      $Duration = ' ; '.$Time. ' s';
    101     } 
     100    }
    102101    if (($this->LogSQLQuery == true) and ($Time != 0))
    103102      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
     
    112111      $this->insert_id = $this->PDO->lastInsertId();
    113112    } else
    114     {     
    115       $this->Error = $this->PDO->errorInfo();
    116       $this->Error = $this->Error[2];
     113    {
     114      $Error = $this->PDO->errorInfo();
     115      $this->Error = $Error[2];
    117116      if (($this->Error != '') and ($this->ShowSQLError == true))
    118117        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     
    122121  }
    123122
    124   function select($Table, $What = '*', $Condition = 1)
     123  function select(string $Table, string $What = '*', string $Condition = '1'): DatabaseResult
    125124  {
    126125    return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
    127126  }
    128127
    129   function delete($Table, $Condition)
     128  function delete(string $Table, string $Condition)
    130129  {
    131130    $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
    132131  }
    133132
    134   function insert($Table, $Data)
     133  function insert(string $Table, array $Data)
    135134  {
    136135    $this->query($this->GetInsert($Table, $Data));
    137136    $this->insert_id = $this->PDO->lastInsertId();
    138137  }
    139  
    140   function GetInsert($Table, $Data)
     138
     139  function GetInsert(string $Table, array $Data): string
    141140  {
    142141    $Name = '';
     
    157156  }
    158157
    159   function update($Table, $Condition, $Data)
     158  function update(string $Table, string $Condition, array $Data)
    160159  {
    161160    $this->query($this->GetUpdate($Table, $Condition, $Data));
    162161  }
    163  
    164   function GetUpdate($Table, $Condition, $Data)
     162
     163  function GetUpdate(string $Table, string $Condition, array $Data): string
    165164  {
    166165    $Values = '';
     
    178177  }
    179178
    180   function replace($Table, $Data)
     179  function replace(string $Table, array $Data)
    181180  {
    182181    $Name = '';
     
    199198  }
    200199
    201   function charset($Charset)
     200  function charset(string $Charset)
    202201  {
    203202    $this->query('SET NAMES "'.$Charset.'"');
    204203  }
    205204
    206   function real_escape_string($Text)
     205  function real_escape_string(string $Text): string
    207206  {
    208207    return addslashes($Text);
    209208  }
    210209
    211   function quote($Text)
     210  function quote(string $Text): string
    212211  {
    213212    return $this->PDO->quote($Text);
     
    222221  {
    223222  }
    224  
    225   public function Transaction($Queries)
     223
     224  public function Transaction(array $Queries)
    226225  {
    227226    //echo('|'."\n");
  • trunk/Packages/Common/Error.php

    r873 r887  
    33class ErrorHandler
    44{
    5   var $Encoding;
    6   var $ShowError;
    7   var $UserErrors;
    8   var $OnError;
     5  public string $Encoding;
     6  public bool $ShowError;
     7  public int $UserErrors;
     8  public $OnError;
    99
    1010  function __construct()
     
    7575  }
    7676
    77   function ShowDefaultError($Message)
     77  function ShowDefaultError(string $Message): void
    7878  {
    7979    $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
  • trunk/Packages/Common/Generics.php

    r869 r887  
    55  var $Items = array();
    66
    7   function Add($Item)
     7  function Add($Item): void
    88  {
    99    $this->Items[] = $Item;
    1010  }
    1111
    12   function RemoveAt(int $Index)
     12  function RemoveAt(int $Index): void
    1313  {
    1414    unset($this->Items[$Index]);
  • trunk/Packages/Common/Image.php

    r874 r887  
    99class Font
    1010{
    11   var $Size;
    12   var $FileName;
    13   var $Color;
     11  public int $Size;
     12  public string $FileName;
     13  public int $Color;
    1414
    1515  function __construct()
     
    2323class Pen
    2424{
    25   var $Color;
    26   var $X;
    27   var $Y;
     25  public int $Color;
     26  public int $X;
     27  public int $Y;
    2828
    2929  function __construct()
     
    3838class Brush
    3939{
    40   var $Color;
     40  public int $Color;
    4141
    4242  function __construct()
     
    4949class Image
    5050{
    51   var $Image;
    52   var $Type;
    53   var $Font;
    54   var $Pen;
     51  public $Image;
     52  public int $Type;
     53  public Font $Font;
     54  public Pen $Pen;
     55  public Brush $Brush;
    5556
    5657  function __construct()
     
    6364  }
    6465
    65   function SaveToFile($FileName)
     66  function SaveToFile(string $FileName): void
    6667  {
    6768    if ($this->Type == IMAGETYPE_JPEG)
     
    7980  }
    8081
    81   function LoadFromFile($FileName)
     82  function LoadFromFile(string $FileName): void
    8283  {
    8384    $ImageInfo = getimagesize($FileName);
     
    9798  }
    9899
    99   function Output()
     100  function Output(): void
    100101  {
    101102    $this->SaveToFile(NULL);
    102103  }
    103104
    104   function SetSize($Width, $Height)
     105  function SetSize(int $Width, int $Height): void
    105106  {
    106107    $NewImage = imagecreatetruecolor($Width, $Height);
     
    110111  }
    111112
    112   function GetWidth()
     113  function GetWidth(): int
    113114  {
    114115    return imagesx($this->Image);
    115116  }
    116117
    117   function GetHeight()
     118  function GetHeight(): int
    118119  {
    119120    return imagesy($this->Image);
    120121  }
    121122
    122   function TextOut($X, $Y, $Text)
     123  function TextOut(int $X, int $Y, string $Text): void
    123124  {
    124125    imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text);
    125126  }
    126127
    127   function ConvertColor($Color)
     128  function ConvertColor(int $Color): int
    128129  {
    129130    return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff);
    130131  }
    131132
    132   function FillRect($X1, $Y1, $X2, $Y2)
     133  function FillRect(int $X1, int $Y1, int $X2, int $Y2): void
    133134  {
    134135    imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color));
    135136  }
    136137
    137   function Line($X1, $Y1, $X2, $Y2)
     138  function Line(int $X1, int $Y1, int $X2, int $Y2): void
    138139  {
    139140    imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color));
  • trunk/Packages/Common/Locale.php

    r874 r887  
    33class LocaleText
    44{
    5   var $Data;
    6   var $Code;
    7   var $Title;
     5  public array $Data;
     6  public string $Code;
     7  public string $Title;
    88
    99  function __construct()
     
    1414  }
    1515
    16   function Load()
    17   {
    18   }
    19 
    20   function Translate($Text, $Group = '')
     16  function Load(): void
     17  {
     18  }
     19
     20  function Translate(string $Text, string $Group = ''): string
    2121  {
    2222    if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != ''))
     
    2525  }
    2626
    27   function TranslateReverse($Text, $Group = '')
     27  function TranslateReverse(string $Text, string $Group = ''): string
    2828  {
    2929    $Key = array_search($Text, $this->Data[$Group]);
     
    3535class LocaleFile extends Model
    3636{
    37   var $Texts;
    38   var $Dir;
     37  public LocaleText $Texts;
     38  public string $Dir;
    3939
    4040  function __construct(System $System)
     
    4444  }
    4545
    46   function Load($Language)
     46  function Load(string $Language): void
    4747  {
    4848    $FileName = $this->Dir.'/'.$Language.'.php';
     
    5555  }
    5656
    57   function AnalyzeCode($Path)
     57  function AnalyzeCode(string $Path): void
    5858  {
    5959    // Search for php files
     
    9898  }
    9999
    100   function SaveToFile($FileName)
     100  function SaveToFile(string $FileName): void
    101101  {
    102102    $Content = '<?php'."\n".
     
    119119  }
    120120
    121   function LoadFromDatabase($Database, $LangCode)
     121  function LoadFromDatabase(Database $Database, string $LangCode): void
    122122  {
    123123    $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     
    132132  }
    133133
    134   function SaveToDatabase(Database $Database, $LangCode)
    135   {
    136     $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     134  function SaveToDatabase(string $LangCode): void
     135  {
     136    $DbResult = $this->Database->select('Language', '*', 'Code='.$this->Database->quote($LangCode));
    137137    if ($DbResult->num_rows > 0)
    138138    {
    139139      $Language = $DbResult->fetch_assoc();
    140       $Database->delete('Locale', '`Language`='.$Language['Id']);
     140      $this->Database->delete('Locale', '`Language`='.$Language['Id']);
    141141      foreach ($this->Texts->Data as $Index => $Item)
    142         $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
    143         'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')');
    144     }
    145   }
    146 
    147   function UpdateToDatabase(Database $Database, $LangCode)
    148   {
    149     $DbResult = $Database->select('Language', '*', '`Code`='.$Database->quote($LangCode));
     142        $this->Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
     143        'VALUES('.$Language['Id'].','.$this->Database->quote($Index).','.$this->Database->quote($Item).')');
     144    }
     145  }
     146
     147  function UpdateToDatabase(string $LangCode): void
     148  {
     149    $DbResult = $this->Database->select('Language', '*', '`Code`='.$this->Database->quote($LangCode));
    150150    if ($DbResult->num_rows > 0)
    151151    {
     
    153153      foreach ($this->Texts->Data as $Index => $Item)
    154154      {
    155         $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).
     155        $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index).
    156156          ') AND (`Language`='.($Language['Id']).')');
    157157        if ($DbResult->num_rows > 0)
    158         $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
    159           '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item));
    160         else $Database->insert('Locale', array('Language' => $Language['Id'],
     158        $this->Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
     159          '(`Original` ='.$this->Database->quote($Index).')', array('Translated' => $Item));
     160        else $this->Database->insert('Locale', array('Language' => $Language['Id'],
    161161         'Original' => $Index, 'Translated' => $Item));
    162162      }
     
    167167class LocaleManager extends Model
    168168{
    169   var $CurrentLocale;
    170   var $Codes;
    171   var $Dir;
    172   var $LangCode;
    173   var $DefaultLangCode;
    174   var $Available;
     169  public LocaleFile $CurrentLocale;
     170  public array $Codes;
     171  public string $Dir;
     172  public string $LangCode;
     173  public string $DefaultLangCode;
     174  public array $Available;
    175175
    176176  function __construct(System $System)
     
    182182    $this->DefaultLangCode = 'en';
    183183    $this->Available = array();
    184   }
    185 
    186   function LoadAvailable()
     184    $this->Dir = '';
     185  }
     186
     187  function LoadAvailable(): void
    187188  {
    188189    $this->Available = array();
     
    201202  }
    202203
    203   function UpdateAll($Directory)
     204  function UpdateAll(string $Directory): void
    204205  {
    205206    $Locale = new LocaleFile($this->System);
     
    222223          if (!array_key_exists($Index, $Locale->Texts->Data))
    223224            unset($FileLocale->Texts->Data[$Index]);
    224         $FileLocale->UpdateToDatabase($this->System->Database, $FileLocale->Texts->Code);
     225        $FileLocale->UpdateToDatabase($FileLocale->Texts->Code);
    225226        $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php';
    226227        $FileLocale->SaveToFile($FileName);
     
    230231  }
    231232
    232   function LoadLocale($Code)
     233  function LoadLocale(string $Code): void
    233234  {
    234235    if (array_key_exists($Code, $this->Available))
     
    241242
    242243// Short named global translation function
    243 function T($Text, $Group = '')
     244function T(string $Text, string $Group = ''): string
    244245{
    245246  global $GlobalLocaleManager;
  • trunk/Packages/Common/Mail.php

    r874 r887  
    99class Mail
    1010{
    11   var $Priorities;
    12   var $Subject;
    13   var $From;
    14   var $Recipients;
    15   var $Bodies;
    16   var $Attachments;
    17   var $AgentIdent;
    18   var $Organization;
    19   var $ReplyTo;
    20   var $Headers;
     11  public string $Subject;
     12  public string $From;
     13  public array $Recipients;
     14  public array $Bodies;
     15  public array $Attachments;
     16  public string $AgentIdent;
     17  public string $Organization;
     18  public string $ReplyTo;
     19  public array $Headers;
     20  private array $Priorities;
     21  private string $Boundary;
    2122
    2223  function __construct()
     
    2829  }
    2930
    30   function Clear()
     31  function Clear(): void
    3132  {
    3233    $this->Bodies = array();
     
    4142  }
    4243
    43   function AddToCombined($Address)
     44  function AddToCombined(string $Address): void
    4445  {
    4546    $this->Recipients[] = array('Address' => $Address, 'Type' => 'SendCombined');
    4647  }
    4748
    48   function AddTo($Address, $Name)
     49  function AddTo(string $Address, string $Name): void
    4950  {
    5051    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Send');
    5152  }
    5253
    53   function AddCc($Address, $Name)
     54  function AddCc(string $Address, string $Name): void
    5455  {
    5556    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Copy');
    5657  }
    5758
    58   function AddBcc($Address, $Name)
     59  function AddBcc(string $Address, string $Name): void
    5960  {
    6061    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'HiddenCopy');
    6162  }
    6263
    63   function AddBody($Content, $MimeType = 'text/plain', $Charset = 'utf-8')
     64  function AddBody(string $Content, string $MimeType = 'text/plain', string $Charset = 'utf-8'): void
    6465  {
    6566    $this->Bodies[] = array('Content' => $Content, 'Type' => strtolower($MimeType),
     
    6768  }
    6869
    69   function Organization($org)
     70  function Organization(string $org): void
    7071  {
    7172    if (trim($org != '')) $this->xheaders['Organization'] = $org;
    7273  }
    7374
    74   function Priority($Priority)
     75  function Priority(int $Priority): bool
    7576  {
    7677    if (!intval($Priority)) return false;
    7778
    78     if (!isset($this->priorities[$Priority - 1])) return false;
    79 
    80     $this->xheaders['X-Priority'] = $this->priorities[$Priority - 1];
     79    if (!isset($this->Priorities[$Priority - 1])) return false;
     80
     81    $this->xheaders['X-Priority'] = $this->Priorities[$Priority - 1];
    8182    return true;
    8283  }
    8384
    84   function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT)
     85  function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT): void
    8586  {
    8687    $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType,
     
    8889  }
    8990
    90   function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT)
     91  function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT): void
    9192  {
    9293    $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType,
     
    9495  }
    9596
    96   function Send()
     97  function Send(): bool
    9798  {
    9899    if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body'));
     
    144145    if ($this->Subject == '') throw new Exception(T('Mail message missing Subject'));
    145146
    146 
    147147    $res = mail($To, $this->Subject, $Body, $Headers);
    148148    return $res;
    149149  }
    150150
    151   function ValidEmail($Address)
    152   {
    153     if (ereg(".*<(.+)>", $Address, $regs)) $Address = $regs[1];
    154     if (ereg("^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))
     151  function ValidEmail(string $Address): bool
     152  {
     153    if (preg_match(".*<(.+)>", $Address, $regs)) $Address = $regs[1];
     154    if (preg_match("^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))
    155155      return true;
    156156      else return false;
    157157  }
    158158
    159   function CheckAdresses($Addresses)
     159  function CheckAdresses(array $Addresses): void
    160160  {
    161161    foreach ($Addresses as $Address)
    162162    {
    163163      if (!$this->ValidEmail($Address))
    164   throw new Exception(sprintf(T('Mail message invalid address %s'), $Address));
    165     }
    166   }
    167 
    168   private function ContentEncoding($Charset)
     164      {
     165        throw new Exception(sprintf(T('Mail message invalid address %s'), $Address));
     166      }
     167    }
     168  }
     169
     170  private function ContentEncoding($Charset): string
    169171  {
    170172    if ($Charset != CHARSET_ASCII) return '8bit';
     
    172174  }
    173175
    174   private function BuildAttachment($Body)
     176  private function BuildAttachment($Body): string
    175177  {
    176178    if (count($this->Attachments) > 0)
     
    206208  }
    207209
    208   private function BuildBody()
     210  private function BuildBody(): string
    209211  {
    210212    $Result = '';
     
    219221      $this->Headers['Content-Transfer-Encoding'] = $this->ContentEncoding($this->Bodies[0]['Charset']);
    220222    }
    221 
    222223
    223224    foreach ($this->Bodies as $Body)
  • trunk/Packages/Common/Page.php

    r874 r887  
    33class Page extends View
    44{
    5   var $FullTitle;
    6   var $ShortTitle;
    7   var $ParentClass;
    8   var $ClearPage;
     5  public string $FullTitle;
     6  public string $ShortTitle;
     7  public string $ParentClass;
     8  public bool $ClearPage;
    99  var $OnSystemMessage;
    10   var $Load;
    11   var $Unload;
     10  public string $Load;
     11  public string $Unload;
    1212
    13   function __construct($System)
     13  function __construct(System $System)
    1414  {
    1515    parent::__construct($System);
    1616    $this->ClearPage = false;
    1717    $this->OnSystemMessage = array();
     18    $this->FullTitle = "";
     19    $this->ShortTitle = "";
     20    $this->ParentClass = "";
    1821  }
    1922
    20   function Show()
     23  function Show(): string
    2124  {
    2225    return '';
    2326  }
    2427
    25   function GetOutput()
     28  function GetOutput(): string
    2629  {
    2730    $Output = $this->Show();
     
    2932  }
    3033
    31   function SystemMessage($Title, $Text)
     34  function SystemMessage(string $Title, string $Text): string
    3235  {
    3336    return call_user_func_array($this->OnSystemMessage, array($Title, $Text));
  • trunk/Packages/Common/RSS.php

    r874 r887  
    33class RSS
    44{
    5   var $Charset;
    6   var $Title;
    7   var $Link;
    8   var $Description;
    9   var $WebmasterEmail;
    10   var $Items;
     5  public string $Charset;
     6  public string $Title;
     7  public string $Link;
     8  public string $Description;
     9  public string $WebmasterEmail;
     10  public array $Items;
    1111
    1212  function __construct()
    1313  {
    1414    $this->Charset = 'utf8';
     15    $this->Title = '';
     16    $this->Link = '';
     17    $this->Description = '';
     18    $this->WebmasterEmail = '';
    1519    $this->Items = array();
    1620  }
    1721
    18   function Generate()
     22  function Generate(): string
    1923  {
    2024    $Result = '<?xml version="1.0" encoding="'.$this->Charset.'" ?>'."\n". //<?
  • trunk/Packages/Common/Setup.php

    r874 r887  
    33class PageSetup extends Page
    44{
    5   var $UpdateManager;
    6   var $ConfigDefinition;
    7   var $Config;
    8   var $DatabaseRevision;
    9   var $Revision;
    10   var $Updates;
    11   var $ConfigDir;
    12 
    13   function __construct($System)
     5  public UpdateManager $UpdateManager;
     6  public array $ConfigDefinition;
     7  public array $Config;
     8  public int $DatabaseRevision;
     9  public int $Revision;
     10  public string $ConfigDir;
     11  public array $YesNo;
     12
     13  function __construct(System $System)
    1414  {
    1515    parent::__construct($System);
    16     $this->Title = T('Application setup');
     16    $this->FullTitle = T('Application setup');
     17    $this->ShortTitle = T('Application setup');
    1718    //$this->ParentClass = 'PagePortal';
    1819    $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config';
     
    2021  }
    2122
    22   function LoginPanel()
     23  function LoginPanel(): string
    2324  {
    2425    $Output = '<h3>Přihlášení k instalaci</h3>'.
     
    3233  }
    3334
    34   function ControlPanel()
     35  function ControlPanel(): string
    3536  {
    3637    $Output = '<h3>'.T('Instance management').'</h3>';
     
    6263  }
    6364
    64   function Show()
     65  function Show(): string
    6566  {
    6667    global $ConfigDefinition, $DatabaseRevision, $Config, $Updates;
     
    163164  }
    164165
    165   function ShowModules()
     166  function ShowModules(): string
    166167  {
    167168    $Output = '';
     
    170171    if ($Operation == 'install')
    171172    {
    172       $this->System->ModuleManager->Modules[$_GET['name']]->Install();
     173      $this->System->ModuleManager->GetModule($_GET['name'])->Install();
    173174      $this->System->ModuleManager->SaveState();
    174175      $Output .= 'Modul '.$_GET['name'].' instalován<br/>';
     
    176177    if ($Operation == 'uninstall')
    177178    {
    178       $this->System->ModuleManager->Modules[$_GET['name']]->Uninstall();
     179      $this->System->ModuleManager->GetModule($_GET['name'])->Uninstall();
    179180      $this->System->ModuleManager->SaveState();
    180181      $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>';
     
    182183    if ($Operation == 'enable')
    183184    {
    184       $this->System->ModuleManager->Modules[$_GET['name']]->Enable();
     185      $this->System->ModuleManager->GetModule($_GET['name'])->Enable();
    185186      $this->System->ModuleManager->SaveState();
    186187      $Output .= 'Modul '.$_GET['name'].' povolen<br/>';
     
    188189    if ($Operation == 'disable')
    189190    {
    190       $this->System->ModuleManager->Modules[$_GET['name']]->Disable();
     191      $this->System->ModuleManager->GetModule($_GET['name'])->Disable();
    191192      $this->System->ModuleManager->SaveState();
    192193      $Output .= 'Modul '.$_GET['name'].' zakázán<br/>';
     
    194195    if ($Operation == 'upgrade')
    195196    {
    196       $this->System->ModuleManager->Modules[$_GET['name']]->Upgrade();
     197      $this->System->ModuleManager->GetModule($_GET['name'])->Upgrade();
    197198      $this->System->ModuleManager->SaveState();
    198199      $Output .= 'Modul '.$_GET['name'].' povýšen<br/>';
     
    203204  }
    204205
    205   function ShowList()
     206  function ShowList(): string
    206207  {
    207208    $Output = '';
     
    247248  }
    248249
    249   function PrepareConfig($Config)
     250  function PrepareConfig($Config): string
    250251  {
    251252    $Output = '';
     
    322323  }
    323324
    324   function CreateConfig($Config)
     325  function CreateConfig($Config): string
    325326  {
    326327    $Output = "<?php\n\n".
     
    359360class PageSetupRedirect extends Page
    360361{
    361   function Show()
     362  function Show(): string
    362363  {
    363364    $Output = '';
     
    377378class Setup extends Model
    378379{
    379   var $UpdateManager;
     380  public UpdateManager $UpdateManager;
    380381
    381382  function Start()
     
    383384    global $DatabaseRevision;
    384385
    385     $this->System->RegisterPage('', 'PageSetupRedirect');
    386     $this->System->RegisterPage('setup', 'PageSetup');
     386    $this->System->RegisterPage([''], 'PageSetupRedirect');
     387    $this->System->RegisterPage(['setup'], 'PageSetup');
    387388
    388389    // Check database persistence structure
     
    396397  {
    397398    unset($this->UpdateManager);
    398     $this->System->UnregisterPage('');
    399     $this->System->UnregisterPage('setup');
    400   }
    401 
    402   function CheckState()
     399    $this->System->UnregisterPage(['']);
     400    $this->System->UnregisterPage(['setup']);
     401  }
     402
     403  function CheckState(): bool
    403404  {
    404405    return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and
     
    432433  }
    433434
    434   function IsInstalled()
     435  function IsInstalled(): bool
    435436  {
    436437    $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"');
     
    438439  }
    439440
    440   function Upgrade()
     441  function Upgrade(): string
    441442  {
    442443    $Updates = new Updates();
  • trunk/Packages/Common/Table.php

    r874 r887  
    55  var $Name;
    66
    7   function Show()
     7  function Show(): string
    88  {
    99    return '';
     
    1313class Table
    1414{
    15   function GetCell($Y, $X)
     15  function GetCell($Y, $X): string
    1616  {
    1717    return '';
     
    2626  }
    2727
    28   function RowsCount()
     28  function RowsCount(): int
    2929  {
    3030    return 0;
     
    3434class TableMemory extends Table
    3535{
    36   var $Cells;
     36  public array $Cells;
    3737
    38   function GetCell($Y, $X)
     38  function GetCell($Y, $X): string
    3939  {
    4040    return $this->Cells[$Y][$X];
    4141  }
    4242
    43   function RowsCount()
     43  function RowsCount(): int
    4444  {
    4545    return count($this->Cells);
     
    4949class TableSQL extends Table
    5050{
    51   var $Query;
    52   var $Database;
    53   var $Cells;
     51  public string $Query;
     52  public Database $Database;
     53  public array $Cells;
    5454
    55   function GetCell($Y, $X)
     55  function GetCell($Y, $X): string
    5656  {
    5757    return $this->Cells[$Y][$X];
     
    7373  }
    7474
    75   function RowsCount()
     75  function RowsCount(): int
    7676  {
    7777    return count($this->Cells);
     
    8181class TableColumn
    8282{
    83   var $Name;
    84   var $Title;
     83  public string $Name;
     84  public string $Title;
    8585}
    8686
    8787class VisualTable extends Control
    8888{
    89   var $Cells;
    90   var $Columns;
    91   var $OrderSQL;
    92   var $OrderColumn;
    93   var $OrderDirection;
    94   var $OrderArrowImage;
    95   var $DefaultColumn;
    96   var $DefaultOrder;
    97   var $Table;
    98   var $Style;
     89  public array $Cells;
     90  public array $Columns;
     91  public string $OrderSQL;
     92  public string $OrderColumn;
     93  public int $OrderDirection;
     94  public array $OrderArrowImage;
     95  public string $DefaultColumn;
     96  public int $DefaultOrder;
     97  public TableMemory $Table;
     98  public string $Style;
    9999
    100100  function __construct()
     
    126126  }
    127127
    128   function Show()
     128  function Show(): string
    129129  {
    130130    $Output = '<table class="'.$this->Style.'">';
     
    148148  }
    149149
    150   function GetOrderHeader()
     150  function GetOrderHeader(): string
    151151  {
    152152    if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
  • trunk/Packages/Common/UTF8.php

    r874 r887  
    526526  }
    527527
    528   function ToUTF8($String, $Charset = 'iso2')
     528  function ToUTF8string ($String, string $Charset = 'iso2'): string
    529529  {
    530530    $Result = '';
     
    540540  }
    541541
    542   function FromUTF8($String, $Charset = 'iso2')
     542  function FromUTF8(string $String, string $Charset = 'iso2'): string
    543543  {
    544544    $Result = '';
     
    546546    for ($I = 0; $I < strlen($String); $I++)
    547547    {
    548       if (ord($String{$I}) & 0x80) // UTF control character
     548      if (ord($String[$I]) & 0x80) // UTF control character
    549549      {
    550         if (ord($String{$I}) & 0x40) // First
     550        if (ord($String[$I]) & 0x40) // First
    551551        {
    552552          if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset]));
    553           $UTFPrefix = $String{$I};
     553          $UTFPrefix = $String[$I];
    554554        }
    555         else $UTFPrefix .= $String{$I}; // Next
     555        else $UTFPrefix .= $String[$I]; // Next
    556556      } else
    557557      {
    558558        if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset]));
    559559        $UTFPrefix = '';
    560         $Result .= $String{$I};
     560        $Result .= $String[$I];
    561561      }
    562562    }
  • trunk/Packages/Common/Update.php

    r874 r887  
    33class UpdateManager
    44{
    5   var $Revision;
    6   var $Trace;
    7   var $VersionTable;
    8   /* @var Database */
    9   var $Database;
    10   var $InstallMethod;
     5  public int $Revision;
     6  public array $Trace;
     7  public string $VersionTable;
     8  public Database $Database;
     9  public string $InstallMethod;
    1110
    1211  function __construct()
     
    6362    $InstallMethod = $this->InstallMethod;
    6463    $InstallMethod($this);
    65     $this->Update();
    6664  }
    6765
     
    7775  }
    7876
    79   function Execute($Query)
     77  function Execute(string $Query): DatabaseResult
    8078  {
    8179    echo($Query.';<br/>');
Note: See TracChangeset for help on using the changeset viewer.