Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (3 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/Log/Log.php

    r874 r887  
    33class ModuleLog extends AppModule
    44{
    5   function __construct($System)
     5  function __construct(System $System)
    66  {
    77    parent::__construct($System);
     
    1414  }
    1515
    16   function DoInstall()
     16  function DoInstall(): void
    1717  {
    1818  }
    1919
    20   function DoUnInstall()
     20  function DoUnInstall(): void
    2121  {
    2222  }
    2323
    24   function DoStart()
     24  function DoStart(): void
    2525  {
    2626    $this->System->FormManager->RegisterClass('Log', array(
     
    3838      ),
    3939    ));
    40     $this->System->ModuleManager->Modules['RSS']->RegisterRSS(array('Title' => 'Logs',
    41       'Channel' => 'log', 'Callback' => array('ModuleLog', 'ShowRSS'),
     40    ModuleRSS::Cast($this->System->GetModule('RSS'))->RegisterRSS(array('Title' => 'Logs',
     41      'Channel' => 'log', 'Callback' => array($this, 'ShowRSS'),
    4242      'Permission' => array('Module' => 'Log', 'Operation' => 'RSS')));
    4343  }
    4444
    45   function DoStop()
     45  function DoStop(): void
    4646  {
    4747  }
    4848
    49   function NewRecord($Module, $Operation, $Value = '')
     49  function NewRecord(string $Module, string $Operation, string $Value = ''): void
    5050  {
    51     if (array_key_exists('User', $this->System->ModuleManager->Modules) and
    52       array_key_exists('Id', $this->System->User->User))
    53       $UserId = $this->System->User->User['Id'];
     51    if ($this->System->ModuleManager->ModulePresent('User') and
     52      array_key_exists('Id', ModuleUser::Cast($this->System->GetModule('User'))->User->User))
     53      $UserId = ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'];
    5454      else $UserId = NULL;
    5555    if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IPAddress = $_SERVER['REMOTE_ADDR'];
     
    6060  }
    6161
    62   function ShowRSS()
     62  function ShowRSS(): string
    6363  {
    6464    $this->ClearPage = true;
     
    9898    return $RSS->Generate();
    9999  }
     100
     101  static function Cast(AppModule $AppModule): ModuleLog
     102  {
     103    if ($AppModule instanceof ModuleLog)
     104    {
     105      return $AppModule;
     106    }
     107    throw new Exception('Expected ModuleLog type but got '.gettype($AppModule));
     108  }
    100109}
Note: See TracChangeset for help on using the changeset viewer.