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 moved

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r886 r887  
    1414class Core extends Application
    1515{
    16   /** @var Type */
    17   var $Type;
    18   var $Pages;
    19   var $Bars;
    20   /** @var FormManager */
    21   var $FormManager;
    22   /** @var Config */
    23   var $ConfigManager;
    24   var $PathItems;
    25   var $RootURLFolder;
    26   var $ShowPage;
    27   var $Setup;
    28   var $CommandLine;
    29   var $PageHeaders;
    30   var $BaseView;
     16  public Type $Type;
     17  public array $Bars;
     18  public FormManager $FormManager;
     19  public array $Config;
     20  public Config $ConfigManager;
     21  public array $PathItems;
     22  public string $RootURLFolder;
     23  public bool $ShowPage;
     24  public Setup $Setup;
     25  public array $PageHeaders;
     26  public BaseView $BaseView;
     27  public LocaleManager $LocaleManager;
     28  public array $LinkLocaleExceptions;
    3129
    3230  function __construct()
    3331  {
    3432    parent::__construct();
    35     $this->Modules = array();
    36     $this->Pages = array();
     33    $this->Config = array();
    3734    $this->ModuleManager->FileName = dirname(__FILE__).'/../Config/ModulesConfig.php';
    3835    $this->FormManager = new FormManager($this->Database);
     
    4239    if (substr($this->RootURLFolder, -10, 10) == '/index.php')
    4340      $this->RootURLFolder = substr($this->RootURLFolder, 0, -10);
    44     $this->CommandLine = array();
    4541    $this->PageHeaders = array();
    46   }
    47 
    48   function RegisterPage($Path, $Handler)
    49   {
    50     if (is_array($Path))
    51     {
    52       $Page = &$this->Pages;
    53       $LastKey = array_pop($Path);
    54       foreach ($Path as $PathItem)
    55       {
    56         $Page = &$Page[$PathItem];
    57       }
    58       if (!is_array($Page)) $Page = array('' => $Page);
    59       $Page[$LastKey] = $Handler;
    60     } else $this->Pages[$Path] = $Handler;
    61   }
    62 
    63   function UnregisterPage($Path)
    64   {
    65     unset($this->Pages[$Path]);
    66   }
    67 
    68   function SearchPage($PathItems, $Pages)
     42    $this->LinkLocaleExceptions = array();
     43  }
     44
     45  function SearchPage(array $PathItems, array $Pages): ?string
    6946  {
    7047    if (count($PathItems) > 0) $PathItem = $PathItems[0];
     
    8057  }
    8158
    82   function PageNotFound()
    83   {
    84     return 'Page '.implode('/', $this->PathItems).' not found.';
    85   }
    86 
    87   function ShowPage()
     59  function ShowPage(): void
    8860  {
    8961    $this->BaseView = new BaseView($this);
     
    9466    {
    9567      $Page = new $ClassName($this);
    96     } else {
     68    } else
     69    {
    9770      $Page = new PageMissing($this);
    9871    }
     
    10073  }
    10174
    102   function ModulePresent($Name)
    103   {
    104     return array_key_exists($Name, $this->Modules);
    105   }
    106 
    107   function AddModule($Module)
    108   {
    109     $this->Modules[get_class($Module)] = $Module;
    110   }
    111 
    112   function HumanDate($Time)
     75  function ModulePresent(string $Name): bool
     76  {
     77    return array_key_exists($Name, $this->ModuleManager->Modules);
     78  }
     79
     80  function AddModule($Module): void
     81  {
     82    $this->ModuleManager->Modules[get_class($Module)] = $Module;
     83  }
     84
     85  function HumanDate(int $Time): string
    11386  {
    11487    return date('j.n.Y', $Time);
    11588  }
    11689
    117   function Link($Target)
     90  function Link(string $Target): string
    11891  {
    11992    return $this->RootURLFolder.$Target;
    12093  }
    12194
    122   function ShowAction($Id)
     95  function ShowAction(string $Id): string
    12396  {
    12497    $Output = '';
     
    131104      if ($Action['Icon'] == '') $Action['Icon'] = 'clear.png';
    132105      if (substr($Action['URL'], 0, 4) != 'http') $Action['URL'] = $this->Link($Action['URL']);
    133       if (!defined('NEW_PERMISSION') or $this->User->CheckPermission('System', 'Read', 'Item', $Id))
     106      if (!defined('NEW_PERMISSION') or ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('System', 'Read', 'Item', $Id))
    134107        $Output .= '<img alt="'.$Action['Title'].'" src="'.$this->Link('/images/favicons/'.$Action['Icon']).
    135108        '" width="16" height="16" /> <a href="'.$Action['URL'].'">'.$Action['Title'].'</a>';
     
    138111  }
    139112
    140   function RunCommon()
    141   {
    142     global $Database, $ScriptTimeStart, $ConfigFileName, $Mail, $Type,
    143       $DatabaseRevision, $Config, $GlobalLocaleManager;
     113  function RunCommon(): void
     114  {
     115    global $Database, $ScriptTimeStart, $ConfigFileName, $Config, $GlobalLocaleManager;
    144116
    145117    date_default_timezone_set('Europe/Prague');
     
    199171  }
    200172
    201   function Run()
     173  function Run(): void
    202174  {
    203175    $this->RunCommon();
     
    213185      {
    214186         $NewLangCode = $this->PathItems[0];
    215          if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) 
     187         if (array_key_exists($NewLangCode, $this->LocaleManager->Available))
    216188         {
    217189           array_shift($this->PathItems);
     
    226198  }
    227199
    228   function RunCommandLine()
     200  function RunCommandLine(): void
    229201  {
    230202    global $argv;
     
    236208      {
    237209        $Command = $this->CommandLine[$argv[1]];
    238         $Output = call_user_func($Command['Callback'], $argv);
     210        $Output = call_user_func($Command->Callback, $argv);
    239211      } else $Output = 'Command "'.$argv[1].'" not supported.'."\n";
    240     } else $Output = 'No command was given as parameter'."\n";
     212    } else $Output = 'No command was given as parameter. Use "list" to show available commands.'."\n";
    241213    echo($Output);
    242214  }
    243215
    244   function RegisterCommandLine($Name, $Callback)
    245   {
    246     $this->CommandLine[$Name] = array('Name' => $Name, 'Callback' => $Callback);
    247   }
    248 
    249   function RegisterPageBar($Name)
     216  function RegisterPageBar(string $Name): void
    250217  {
    251218    $this->Bars[$Name] = array();
    252219  }
    253220
    254   function UnregisterPageBar($Name)
     221  function UnregisterPageBar(string $Name): void
    255222  {
    256223    unset($this->Bars[$Name]);
    257224  }
    258225
    259   function RegisterPageBarItem($BarName, $ItemName, $Callback)
     226  function RegisterPageBarItem(string $BarName, string $ItemName, callable $Callback): void
    260227  {
    261228    $this->Bars[$BarName][$ItemName] = $Callback;
    262229  }
    263230
    264   function RegisterPageHeader($Name, $Callback)
     231  function UnregisterPageBarItem(string $BarName, string $ItemName): void
     232  {
     233    unset($this->Bars[$BarName][$ItemName]);
     234  }
     235
     236  function RegisterPageHeader(string $Name, callable $Callback): void
    265237  {
    266238    $this->PageHeaders[$Name] = $Callback;
     239  }
     240
     241  function UnregisterPageHeader(string $Name): void
     242  {
     243    unset($this->PageHeaders[$Name]);
    267244  }
    268245}
     
    270247class PageMissing extends Page
    271248{
    272   var $FullTitle = 'Stránka nenalezena';
    273   var $ShortTitle = 'Stránka nenalezena';
    274 
    275   function __construct($System)
     249  function __construct(System $System)
    276250  {
    277251    parent::__construct($System);
     252    $this->FullTitle = 'Stránka nenalezena';
     253    $this->ShortTitle = 'Stránka nenalezena';
    278254    $this->ParentClass = 'PagePortal';
    279255  }
    280256
    281   function Show()
     257  function Show(): string
    282258  {
    283259    Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
Note: See TracChangeset for help on using the changeset viewer.