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

    r874 r887  
    33class PageWebcam extends Page
    44{
    5   var $FullTitle = 'Webová kamera';
    6   var $ShortTitle = 'Kamera';
    7   var $ParentClass = 'PagePortal';
     5  function __construct(System $System)
     6  {
     7    parent::__construct($System);
     8    $this->FullTitle = 'Webová kamera';
     9    $this->ShortTitle = 'Kamera';
     10    $this->ParentClass = 'PagePortal';
     11  }
    812
    9   function Show()
     13  function Show(): string
    1014  {
    11     if (file_exists($this->System->ModuleManager->Modules['WebCam']->ImageFileName))
     15    if (file_exists(ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName))
    1216    {
    1317      $Output = '<script language="JavaScript">
    14       var ImageURL = "'.$this->System->Config['Web']['RootFolder'].'/webcam/'.$this->System->Modules['Webcam']->ImageFileName.'";
     18      var ImageURL = "'.$this->System->Config['Web']['RootFolder'].'/webcam/'.ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName.'";
    1519
    1620      // Force an immediate image load
     
    3236      </script>';
    3337
    34       $Output .= '<br /><div align="center"><img name="theImage" src="" idth="640" height="480" alt="Webcam image"><br>Poslední aktualizace: '.date('j.n.Y G:i', filemtime($this->System->Modules['Webcam']->ImageFileName)).'<br>Obnovování po '.$this->System->Config['Web']['WebcamRefresh'].' sekundách</div><br />';
     38      $Output .= '<br /><div align="center"><img name="theImage" src="" idth="640" height="480" alt="Webcam image"><br>Poslední aktualizace: '.
     39        date('j.n.Y G:i', filemtime(ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName)).
     40        '<br>Obnovování po '.$this->System->Config['Web']['WebcamRefresh'].' sekundách</div><br />';
    3541    } else $Output = '<br />Obrázek nenalezen.<br /><br />';
    3642
     
    4450class ModuleWebCam extends AppModule
    4551{
    46   var $ImageFileName = 'webcam.jpg';
     52  public string $ImageFileName = 'webcam.jpg';
    4753
    48   function __construct($System)
     54  function __construct(System $System)
    4955  {
    5056    parent::__construct($System);
     
    5864  }
    5965
    60   function DoStart()
     66  function DoStart(): void
    6167  {
    6268    $this->System->Pages['webcam'] = 'PageWebcam';
    6369  }
    6470
    65  function ShowImage()
     71 function ShowImage(): string
    6672  {
    6773    global $Config;
     
    7480    return $Output;
    7581  }
     82
     83  static function Cast(AppModule $AppModule): ModuleWebCam
     84  {
     85    if ($AppModule instanceof ModuleWebCam)
     86    {
     87      return $AppModule;
     88    }
     89    throw new Exception('Expected ModuleWebCam type but got '.gettype($AppModule));
     90  }
    7691}
Note: See TracChangeset for help on using the changeset viewer.