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.
File:
1 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  }
Note: See TracChangeset for help on using the changeset viewer.