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/Search/Search.php

    r874 r887  
    33class PageSearch extends Page
    44{
    5   function __construct($System)
     5  function __construct(System $System)
    66  {
    77    parent::__construct($System);
     
    1111  }
    1212
    13   function Show()
     13  function Show(): string
    1414  {
    1515    $Output = '';
     
    2121    '</form>';
    2222    if ($Text != '')
    23     foreach ($this->System->ModuleManager->Modules['Search']->Items as $Item)
     23    foreach (ModuleSearch::Cast($this->System->GetModule('Search'))->Items as $Item)
    2424    {
    2525      $Columns = '';
     
    3333      $Condition = substr($Condition, 3);
    3434      $DbResult = $this->Database->Select($Item['Table'], $Columns, $Condition.' LIMIT '.
    35         $this->System->ModuleManager->Modules['Search']->MaxItemCount);
     35        ModuleSearch::Cast($this->System->GetModule('Search'))->MaxItemCount);
    3636      if ($DbResult->num_rows > 0) $Output .= '<strong>'.$Item['Name'].'</strong><br/>';
    3737      while ($Row = $DbResult->fetch_assoc())
     
    4949class ModuleSearch extends AppModule
    5050{
    51   var $Items;
    52   var $MaxItemCount;
     51  public array $Items;
     52  public int $MaxItemCount;
    5353
    54   function __construct($System)
     54  function __construct(System $System)
    5555  {
    5656    parent::__construct($System);
     
    6565  }
    6666
    67   function DoStart()
     67  function DoStart(): void
    6868  {
    6969    $this->System->Pages['search'] = 'PageSearch';
    7070  }
    7171
    72   function DoInstall()
     72  function DoInstall(): void
    7373  {
    7474  }
    7575
    76   function DoUnInstall()
     76  function DoUnInstall(): void
    7777  {
    7878  }
    7979
    80   function RegisterSearch($Title, $TableName, $Columns)
     80  function RegisterSearch(string $Title, string $TableName, array $Columns): void
    8181  {
    8282    $this->Items[] = array('Name' => $Title, 'Table' => $TableName, 'Columns' => $Columns);
    8383  }
     84
     85  static function Cast(AppModule $AppModule): ModuleSearch
     86  {
     87    if ($AppModule instanceof ModuleSearch)
     88    {
     89      return $AppModule;
     90    }
     91    throw new Exception('Expected ModuleSearch type but got '.gettype($AppModule));
     92  }
    8493}
Note: See TracChangeset for help on using the changeset viewer.