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/Modules/System/System.php

    r874 r887  
    33class PageModules extends Page
    44{
    5   function __construct($System)
     5  function __construct(System $System)
    66  {
    77    parent::__construct($System);
     
    1111  }
    1212
    13   function ShowList()
     13  function ShowList(): string
    1414  {
    1515    $Output = '';
     
    6262  }
    6363
    64   function Show()
     64  function Show(): string
    6565  {
    6666    $Output = '';
     
    6969      if ($_GET['A'] == 'SaveToDb')
    7070      {
    71         $Output .= $this->System->ModuleManager->Modules['System']->SaveToDatabase();
     71        $Output .= ModuleSystem::Cast($this->System->GetModule('System'))->SaveToDatabase();
    7272        $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován');
    7373      } else
     
    7878        if ($ModuleName != '')
    7979        {
    80           $this->System->Modules[$ModuleName]->Install();
    81           $this->System->ModuleManager->Init();
     80          $this->System->ModuleManager->GetModule($ModuleName)->Install();
    8281        } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
    8382
     
    8887        if ($ModuleName != '')
    8988        {
    90           $this->System->ModuleManager->Modules[$ModuleName]->UnInstall();
    91           $this->System->ModuleManager->Init();
     89          $this->System->ModuleManager->GetModule($ModuleName)->UnInstall();
    9290        } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
    9391      } else $Output .= 'Neplatná akce';
     
    10098class ModuleSystem extends AppModule
    10199{
    102   var $InstalledChecked;
    103 
    104   function __construct($System)
     100  public bool $InstalledChecked;
     101
     102  function __construct(System $System)
    105103  {
    106104    parent::__construct($System);
     
    113111  }
    114112
    115   function DoInstall()
     113  function DoInstall(): void
    116114  {
    117115    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
     
    164162  }
    165163
    166   function DoUnInstall()
     164  function DoUnInstall(): void
    167165  {
    168166    // Delete tables with reverse order
     
    178176  }
    179177
    180   function DoStart()
    181   {
    182     $this->System->RegisterPage('module', 'PageModules');
     178  function DoStart(): void
     179  {
     180    $this->System->RegisterPage(['module'], 'PageModules');
    183181    $this->System->FormManager->RegisterClass('Action', array(
    184182      'Title' => 'Akce',
     
    402400  }
    403401
    404   function DoStop()
    405   {
    406   }
    407 
    408   function IsInstalled()
     402  function DoStop(): void
     403  {
     404  }
     405
     406  function IsInstalled(): bool
    409407  {
    410408    if ($this->InstalledChecked == false)
     
    419417  }
    420418
    421   function ModuleChange($Module)
     419  function ModuleChange($Module): void
    422420  {
    423421    //if ($this->IsInstalled())
     
    430428  }
    431429
    432   function LoadFromDatabase()
     430  function LoadFromDatabase(): void
    433431  {
    434432    //DebugLog('Loading modules...');
     
    448446  }
    449447
    450   function SaveToDatabase()
     448  function SaveToDatabase(): string
    451449  {
    452450    $Output = '';
     
    457455      $Modules[$DbRow['Name']] = $DbRow;
    458456      if ($this->System->ModuleManager->ModulePresent($DbRow['Name']))
    459         $this->System->ModuleManager->Modules[$DbRow['Name']]->Id = $DbRow['Id'];
     457        $this->System->ModuleManager->GetModule($DbRow['Name'])->Id = $DbRow['Id'];
    460458    }
    461459
     
    470468          'Description' => $Module->Description, 'License' => $Module->License,
    471469          'Installed' => $Module->Installed));
    472         $this->System->ModuleManager->Modules[$Module->Name]->Id = $this->Database->insert_id;
     470        $this->System->ModuleManager->GetModule($Module->Name)->Id = $this->Database->insert_id;
    473471      }
    474472      else $this->Database->update('Module', 'Name = "'.$Module->Name.'"', array(
     
    512510      {
    513511        if (!array_key_exists($Module->Id, $DbDependency) or
    514         !in_array($this->System->ModuleManager->Modules[$Dependency]->Id, $DbDependency[$Module->Id]))
     512        !in_array($this->System->ModuleManager->GetModule($Dependency)->Id, $DbDependency[$Module->Id]))
    515513        {
    516           if (array_key_exists($Dependency, $this->System->ModuleManager->Modules))
    517             $DependencyId = $this->System->ModuleManager->Modules[$Dependency]->Id;
     514          if ($this->System->ModuleManager->ModulePresent($Dependency))
     515            $DependencyId = $this->System->ModuleManager->GetModule($Dependency)->Id;
    518516            else throw new Exception('Dependent module '.$Dependency.' not found');
    519517          $this->Database->insert('ModuleLink', array('Module' => $Module->Id,
     
    534532    return $Output;
    535533  }
     534
     535  static function Cast(AppModule $AppModule): ModuleSystem
     536  {
     537    if ($AppModule instanceof ModuleSystem)
     538    {
     539      return $AppModule;
     540    }
     541    throw new Exception('Expected ModuleSystem type but got '.gettype($AppModule));
     542  }
    536543}
Note: See TracChangeset for help on using the changeset viewer.